redis-console.html 12 KB

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