redis-console.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>redis控制台</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <meta name="viewport"
  7. content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
  8. <!-- 所有的 css & js 资源 -->
  9. <link rel="stylesheet" href="../../static/kj/element-ui/theme-chalk/index.css">
  10. <link rel="stylesheet" href="../../static/sa.css">
  11. <script src="../../static/kj/vue.min.js"></script>
  12. <script src="../../static/kj/element-ui/index.js"></script>
  13. <script src="../../static/kj/jquery.min.js"></script>
  14. <script src="../../static/kj/layer/layer.js"></script>
  15. <script src="../../static/sa.js"></script>
  16. <style type="text/css">
  17. .card-box {
  18. min-width: 230px;
  19. margin-right: 10px;
  20. margin-bottom: 10px;
  21. display: inline-block;
  22. background-color: #f5f5f5;
  23. cursor: pointer;
  24. transition: all 0.3s;
  25. }
  26. .card-box:hover {
  27. box-shadow: 0 0 20px #999;
  28. }
  29. .card-box .prop-name {
  30. padding-left: 14px;
  31. padding-top: 14px;
  32. color: #666;
  33. }
  34. .card-box .prop-value {
  35. /* border: 1px #000 solid; */
  36. padding-left: 14px;
  37. height: 40px;
  38. line-height: 40px;
  39. padding-top: 10px;
  40. padding-bottom: 10px;
  41. font-size: 26px;
  42. color: green;
  43. }
  44. .f5-pre-btn:hover {
  45. cursor: pointer;
  46. text-decoration: underline;
  47. }
  48. .key-div {
  49. color: green;
  50. cursor: pointer;
  51. font-weight: bold;
  52. }
  53. .not-show, .is-show {
  54. padding: 5px 10px;
  55. background-color: #eee;
  56. cursor: pointer;
  57. }
  58. .is-show {
  59. background-color: rgba(0, 0, 0, 0);
  60. }
  61. /* .k-input input{font-weight: bold;} */
  62. </style>
  63. </head>
  64. <body>
  65. <div class="vue-box" style="display: none;" :style="'display: block;'">
  66. <!-- ------------- 总览 ------------- -->
  67. <div class="c-panel">
  68. <div class="c-title">
  69. Redis 控制台
  70. <span class="f5-pre-btn" @click="f5_pre(false)">刷新</span>
  71. </div>
  72. <div style="height: 10px;"></div>
  73. <div>
  74. <div class="card-box" @click="sa.msg('表点我 >_<')">
  75. <p class="prop-name">键值总数</p>
  76. <p class="prop-value">{{preData.keys_count}}</p>
  77. </div>
  78. <div class="card-box" @click="sa.msg('表点我 >_<')">
  79. <p class="prop-name">命中次数</p>
  80. <p class="prop-value">{{preData.keyspace_hits}}</p>
  81. </div>
  82. <div class="card-box" @click="sa.msg('表点我 >_<')">
  83. <p class="prop-name">已用内存</p>
  84. <p class="prop-value">{{preData.used_memory_human}}</p>
  85. </div>
  86. <div class="card-box" @click="sa.msg('表点我 >_<')">
  87. <p class="prop-name">内存峰值</p>
  88. <p class="prop-value">{{preData.used_memory_peak_human}}</p>
  89. </div>
  90. <div class="card-box" @click="sa.msg('表点我 >_<')">
  91. <p class="prop-name">启动时间</p>
  92. <p class="prop-value">{{preData.uptime_in_seconds_str}}</p>
  93. </div>
  94. </div>
  95. </div>
  96. <!-- ------------- 检索参数 ------------- -->
  97. <div class="c-panel c-table">
  98. <div class="c-title">搜索键值</div>
  99. <div class="c-item">
  100. <!-- <label class="c-label">搜索键值:</label> -->
  101. <el-input v-model="p.k" class="k-input" :placeholder="isLike ? '当前为模糊搜索' : '当前为精确搜索'"
  102. @keyup.native.enter="f5()" style="width: 400px;"></el-input>
  103. </div>
  104. <div class="c-item" style="min-width: 0px;">
  105. <el-button type="primary" icon="el-icon-search" @click="f5()">查询</el-button>
  106. <el-button type="success" icon="el-icon-plus" @click="add()">添加</el-button>
  107. <el-button type="danger" icon="el-icon-delete" @click="deleteByKeys()">删除</el-button>
  108. <el-button type="info" icon="el-icon-sort" @click="isLike = !isLike; sa.ok('切换成功')">
  109. {{isLike ? '切换为精确搜索' : '切换为模糊搜索'}}
  110. </el-button>
  111. </div>
  112. <div style="height: 10px;"></div>
  113. <el-table class="data-table" ref="data-table" :data="dataListShow" size="small">
  114. <!-- <el-table-column label="键"></el-table-column> -->
  115. <el-table-column type="selection" width="45px"></el-table-column>
  116. <el-table-column label="键">
  117. <template slot-scope="s">
  118. <div class="key-div" @click="sa.copyText(s.row.key); sa.msg('复制成功')">{{s.row.key}}</div>
  119. </template>
  120. </el-table-column>
  121. <el-table-column label="值">
  122. <template slot-scope="s">
  123. <div class="not-show" @click="get(s.row)" v-if="s.row.is_show == false">点击加载</div>
  124. <div class="is-show" v-if="s.row.is_show == true" @click="sa.copyText(s.row.value); sa.msg('复制成功')">
  125. {{s.row.value}}
  126. </div>
  127. </template>
  128. </el-table-column>
  129. <el-table-column label="TTL (秒)" prop="ttl" width="150px"></el-table-column>
  130. <el-table-column label="操作" width="250px">
  131. <template slot-scope="s">
  132. <el-button type="text" @click="get(s.row)">查询</el-button>
  133. <el-button type="text" @click="updateValue(s.row)">修改值</el-button>
  134. <el-button type="text" @click="updateTTL(s.row)">修改TTL</el-button>
  135. <el-button type="text" @click="del(s.row)">删除</el-button>
  136. </template>
  137. </el-table-column>
  138. </el-table>
  139. <div class="page-box">
  140. <el-pagination background
  141. layout="total, prev, pager, next, sizes, jumper"
  142. :current-page.sync="p.pageNo"
  143. :page-size.sync="p.pageSize"
  144. :total="dataCount"
  145. :page-sizes="[1, 10, 20, 50, 100, 1000]"
  146. @current-change="f5ByPage()"
  147. @size-change="f5ByPage()">
  148. </el-pagination>
  149. </div>
  150. </div>
  151. </div>
  152. <script>
  153. var app = new Vue({
  154. el: '.vue-box',
  155. data: {
  156. sa: sa, // 超级对象
  157. p: { // 查询参数
  158. k: '',
  159. pageNo: 1, // 当前页
  160. pageSize: 10, // 页大小
  161. sortType: 0 // 排序方式
  162. },
  163. isLike: true, // 是否为模糊匹配
  164. dataCount: 0,
  165. preData: {
  166. keys_count: 0, // key 总数
  167. keyspace_hits: 0, // 被命中次数
  168. used_memory_human: 0, // 已经占用内存数量
  169. used_memory_peak_human: 0, // 内存消耗峰值
  170. uptime_in_seconds: 0, // redis 已经启动的秒数
  171. uptime_in_seconds_str: '0', // redis 已经启动的时间
  172. },
  173. dataList: [],
  174. dataListShow: [],
  175. },
  176. methods: {
  177. // 根据分页信息显示出来
  178. f5ByPage: function () {
  179. var dataListShow = [];
  180. var start = (this.p.pageNo - 1) * this.p.pageSize;
  181. var end = this.p.pageNo * this.p.pageSize;
  182. for (var i = start; i < end; i++) {
  183. if (i >= this.dataList.length) {
  184. break;
  185. }
  186. dataListShow.push(this.dataList[i]);
  187. }
  188. this.dataListShow = dataListShow;
  189. sa.f5TableHeight(); // 刷新表格高度
  190. },
  191. // 查询key列表
  192. f5: function () {
  193. let k = this.p.k;
  194. if (this.isLike && k != '') {
  195. k = '*' + k + '*';
  196. }
  197. sa.ajax('/RedisConsole/getKeys', {k: k}, function (res) {
  198. var dataList = [];
  199. for (var i = 0; i < res.data.length; i++) {
  200. dataList.push({
  201. key: res.data[i], // key
  202. value: '', // value
  203. is_show: false, // 是否已经显示详情
  204. ttl: '未加载', // 过期时间
  205. })
  206. }
  207. this.dataList = dataList;
  208. this.f5ByPage();
  209. this.dataCount = this.dataList.length;
  210. }.bind(this), {
  211. success501: function (res) {
  212. sa.msg(res.msg);
  213. this.dataList = [];
  214. this.f5ByPage();
  215. this.dataCount = 0;
  216. }.bind(this)
  217. });
  218. },
  219. // 刷新预览
  220. f5_pre: function (is_f5_keys) {
  221. // 基本预览信息
  222. sa.ajax('/RedisConsole/getPreInfo', this.p, function (res) {
  223. res.data.uptime_in_seconds_str = getDuration(parseInt(res.data.uptime_in_seconds) * 1000);
  224. this.preData = res.data;
  225. // 如果指定不查询keys列表
  226. if (is_f5_keys === false) {
  227. return;
  228. }
  229. // 如果超过了最大值,则提示一下
  230. if (res.data.isGtMax) {
  231. var tipStr = 'key值数量已达' + this.preData.keys_count + ',为了避免卡顿已取消返回结果列表(您可以增加筛选条件缩短记录总数)';
  232. tipStr = '<b style="color: red;">' + tipStr + '</b>';
  233. sa.alert(tipStr);
  234. } else {
  235. this.f5();
  236. }
  237. }.bind(this));
  238. },
  239. // 加载详情
  240. get: function (data) {
  241. sa.ajax('/RedisConsole/getByKey?key=' + data.key, function (res) {
  242. data.value = res.data.value;
  243. data.ttl = res.data.ttl;
  244. data.is_show = true;
  245. sa.f5TableHeight(); // 刷新表格高度
  246. }.bind(this));
  247. },
  248. // 删除
  249. del: function (data) {
  250. sa.confirm('是否删除,此操作不可撤销', function () {
  251. sa.ajax('/RedisConsole/del?key=' + data.key, function (res) {
  252. sa.arrayDelete(app.dataListShow, data);
  253. sa.ok('删除成功');
  254. sa.f5TableHeight(); // 刷新表格高度
  255. })
  256. });
  257. },
  258. // 修改键值
  259. updateValue: function (data) {
  260. layer.prompt({
  261. title: '修改键值',
  262. // shadeClose: true, // 点击遮罩关闭
  263. formType: 2, // 多行输入
  264. maxlength: 9999999999, // 最大输入字符长度
  265. area: ['600px', '400px'], // 弹窗尺寸
  266. }, function (pass, index, elem) {
  267. layer.close(index); //如果设定了yes回调,需进行手工关闭
  268. sa.ajax('/RedisConsole/updateValue', {key: data.key, value: pass}, function (res) {
  269. data.value = pass;
  270. layer.msg('修改成功');
  271. sa.f5TableHeight(); // 刷新表格高度
  272. })
  273. });
  274. },
  275. // 修改ttl
  276. updateTTL: function (data) {
  277. sa.prompt('修改TTL', function (pass, index) {
  278. if (isNaN(pass)) {
  279. return sa.error('请输入一个数值');
  280. }
  281. sa.ajax('/RedisConsole/updateTtl', {key: data.key, ttl: pass}, function (res) {
  282. data.ttl = pass;
  283. sa.ok('修改成功');
  284. })
  285. });
  286. },
  287. // 添加
  288. add: function () {
  289. sa.showIframe('添加键值', 'redis-key-add.html', '800px', '510px');
  290. },
  291. // 根据id列表删除
  292. deleteByKeys: function () {
  293. // 获取选中元素的id列表
  294. let selection = this.$refs['data-table'].selection;
  295. let keys = sa.getArrayField(selection, 'key');
  296. // 判断
  297. if (keys.length < 1) {
  298. return sa.error('请至少选择一行');
  299. }
  300. // 删除
  301. sa.confirm('是否删除选中记录,此操作不可撤销', function () {
  302. sa.ajax('/RedisConsole/deleteByKeys', {key: keys}, function (res) {
  303. sa.arrayDelete(this.dataListShow, selection);
  304. sa.ok2('删除成功');
  305. sa.f5TableHeight(); // 刷新表格高度
  306. }.bind(this))
  307. }.bind(this));
  308. },
  309. // 刷新秒数
  310. auto_f5_run_time: function () {
  311. setInterval(function () {
  312. if (this.preData.uptime_in_seconds <= 0 || this.preData.uptime_in_seconds > 60 * 60 * 24) {
  313. return;
  314. }
  315. this.preData.uptime_in_seconds++;
  316. this.preData.uptime_in_seconds_str = getDuration(parseInt(this.preData.uptime_in_seconds) * 1000);
  317. }.bind(this), 1000);
  318. }
  319. },
  320. created: function () {
  321. this.f5_pre();
  322. this.auto_f5_run_time();
  323. }
  324. })
  325. function getDuration(my_time) {
  326. var days = my_time / 1000 / 60 / 60 / 24;
  327. var daysRound = Math.floor(days);
  328. var hours = my_time / 1000 / 60 / 60 - (24 * daysRound);
  329. var hoursRound = Math.floor(hours);
  330. var minutes = my_time / 1000 / 60 - (24 * 60 * daysRound) - (60 * hoursRound);
  331. var minutesRound = Math.floor(minutes);
  332. var seconds = my_time / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
  333. seconds = parseInt(seconds);
  334. // console.log('转换时间:', daysRound + '天', hoursRound + '时', minutesRound + '分', seconds + '秒');
  335. // var time = hoursRound + ':' + minutesRound + ':' + seconds
  336. // return time;
  337. if (daysRound >= 1) {
  338. return daysRound + '天' + hoursRound + '小时';
  339. } else if (hoursRound >= 1) {
  340. return hoursRound + '小时' + hoursRound + '分';
  341. } else if (minutesRound >= 1) {
  342. return minutesRound + '分' + seconds + '秒';
  343. } else {
  344. return seconds + '秒';
  345. }
  346. }
  347. // console.log(getDuration(200000));;
  348. </script>
  349. </body>
  350. </html>