From 65e87fec1a381e3eeef484815b77219467fcf15e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 6 Feb 2024 03:52:36 +0800 Subject: [PATCH] up --- plugins/data_query/nosql_memcached.py | 44 ++++++++++++- plugins/data_query/static/html/index.html | 4 +- plugins/data_query/static/js/app.js | 75 ++++++++++++++++++++++- 3 files changed, 118 insertions(+), 5 deletions(-) diff --git a/plugins/data_query/nosql_memcached.py b/plugins/data_query/nosql_memcached.py index 0c10d6b24..1f4b55b9e 100755 --- a/plugins/data_query/nosql_memcached.py +++ b/plugins/data_query/nosql_memcached.py @@ -108,6 +108,10 @@ class nosqlMemcachedCtr(): v_str = v.decode() if not v_str in item_no: item_no.append(v_str) + + if len(item_no) == 0: + item_no = [0] + result['items'] = item_no return mw.returnData(True,'ok', result) @@ -127,6 +131,9 @@ class nosqlMemcachedCtr(): size = args['size'] item_id = args['item_id'] + if item_id == '0': + return mw.returnData(False,'ok') + m_items = mem_instance.stats('items') item_key = 'items:%s:number' % item_id @@ -143,13 +150,19 @@ class nosqlMemcachedCtr(): all_key = mem_instance.stats('cachedump', str(item_id) , str(0)) # print(all_key) all_key_list = [] + cur_time_t = time.time() for k in all_key: t = {} t['k'] = k.decode("utf-8") v = all_key[k].decode("utf-8") v = v.strip('[').strip(']').split(';') t['s'] = v[0] - t['t'] = v[1].strip().split(' ')[0] + cur_time = v[1].strip().split(' ')[0] + + if int(cur_time) != 0 : + t['t'] = int(cur_time) - int(cur_time_t) + else: + t['t'] = 0 all_key_list.append(t) # print(len(all_key_list)) @@ -184,6 +197,27 @@ class nosqlMemcachedCtr(): mem_instance.delete(key) return mw.returnData(True,'删除成功!') + def setKv(self, args): + + sid = args['sid'] + mem_instance = self.getInstanceBySid(sid).conn() + if mem_instance is False: + return mw.returnData(False,'无法链接') + + key = args['key'] + val = args['val'] + endtime = args['endtime'] + mem_instance.set(key, val, int(endtime)) + return mw.returnData(True,'设置成功!') + + def clear(self, args): + sid = args['sid'] + mem_instance = self.getInstanceBySid(sid).conn() + if mem_instance is False: + return mw.returnData(False,'无法链接') + + mem_instance.flush_all() + return mw.returnData(True,'清空成功!') # ---------------------------------- run ---------------------------------- # 获取 memcached 列表 @@ -199,6 +233,14 @@ def del_val(args): t = nosqlMemcachedCtr() return t.delVal(args) +def set_kv(args): + t = nosqlMemcachedCtr() + return t.setKv(args) + +def clear(args): + t = nosqlMemcachedCtr() + return t.clear(args) + # 测试 def test(args): sid = args['sid'] diff --git a/plugins/data_query/static/html/index.html b/plugins/data_query/static/html/index.html index e15ad1cc4..b32bf054f 100644 --- a/plugins/data_query/static/html/index.html +++ b/plugins/data_query/static/html/index.html @@ -69,7 +69,7 @@ - +
@@ -129,7 +129,7 @@
- +
diff --git a/plugins/data_query/static/js/app.js b/plugins/data_query/static/js/app.js index b846b29bc..50512cd02 100755 --- a/plugins/data_query/static/js/app.js +++ b/plugins/data_query/static/js/app.js @@ -173,6 +173,22 @@ function initTabMongodb(){ function initTabMemcached(){ memcachedGetList(); + + $('#memcached_add_key').unbind('click').click(function(){ + memcachedAdd(); + }); + + $('#memcached_clear_all').unbind('click').click(function(){ + var sid = memcachedGetSid(); + memPostCB('clear',{'sid':sid} ,function(rdata){ + console.log(rdata); + showMsg(rdata.data.msg,function(){ + if (rdata.data.status){ + memcachedGetList(); + } + },{icon: rdata.data.status ? 1 : 2}, 2000); + }); + }); } // ------------------------- memcached start ------------------------------- @@ -203,12 +219,11 @@ function memcachedGetList(){ $('#memcached .item_list select').change(function(){ memcachedGetKeyList(1); }); - - memcachedGetKeyList(1); closeInstallLayer(); } else { showInstallLayer(); } + memcachedGetKeyList(1); }); } @@ -256,6 +271,8 @@ function memcachedGetKeyList(p){ var i = $(this).data('index'); copyText(dlist[i]['v']); }); + } else { + $('.memcached_table_content tbody').html(''); } }); } @@ -275,6 +292,60 @@ function memcachedDeleteKey(key){ }); } + +function memcachedAdd(){ + layer.open({ + type: 1, + area: '480px', + title: '添加Key至服务器', + closeBtn: 1, + shift: 0, + shadeClose: false, + btn:['确定','取消'], + content: "
\ +
\ + \ +
\ + \ +
\ +
\ +
\ + \ +
\ + \ +
\ +
\ +
\ + 有效期\ +
\ + \ +
\ +
\ +
\ +
\ +
  • 有效期为0表示永久
  • \ +
\ +
\ +
", + success:function(){ + }, + yes: function(index){ + var data = {}; + data['sid'] = memcachedGetSid(); + data['key'] = $('input[name="key"]').val(); + data['val'] = $('textarea[name="val"]').val(); + data['endtime'] = $('input[name="endtime"]').val(); + + memPostCB('set_kv', data ,function(rdata){ + showMsg(rdata.data.msg,function(){ + layer.close(index); + memcachedGetList(); + },{icon: rdata.data.status ? 1 : 2}, 1000); + }); + } + }); +} + // ------------------------- memcached end --------------------------------- // ------------------------- mongodb start ---------------------------------