From f78a8204a54380d3e4f525e767e353ef85972d1c Mon Sep 17 00:00:00 2001 From: daivem <13358533@qq.com> Date: Mon, 5 Sep 2016 11:08:38 +0800 Subject: [PATCH 01/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1ed96a..d77786e 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ TODO: v0.4.0 (2016-09-05) -采用scan命令读取key列表(redis >= 2.8),页面建树改用ztree (https://github.com/zTree/zTree_v3),单个节点超过10万时不建议展开(好吧,有可能展不开) +采用scan命令读取key列表(redis >= 2.8),页面建树改用ztree ( https://github.com/zTree/zTree_v3 ),单个节点超过10万时不建议展开(好吧,有可能展不开) 增加直接查看指定key的功能 From 243073ea49459f18c5f90cc95f84f4a2b92dcef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=B9=BF=E6=96=87?= Date: Mon, 26 Sep 2016 05:49:05 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E4=BF=AE=E6=AD=A3scan=E5=9C=A8=E9=9B=86?= =?UTF-8?q?=E7=BE=A4=E6=A8=A1=E5=BC=8F=E4=B8=8B=E4=B8=8D=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 +++++++++ application/models/redis_model.php | 24 ++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d77786e..1bb9f26 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,15 @@ TODO: ----------------------------------------------- + +更新日志: + +v0.4.1 (2016-09-19) + +修正scan在集群模式下不可用的问题(由于官方文档缺失,暂时将集群模式读取key列表改回原来的keys命令,如有错误,请斧正) + +—————————————————— + 更新日志: v0.4.0 (2016-09-05) diff --git a/application/models/redis_model.php b/application/models/redis_model.php index aa9d747..6e729fd 100644 --- a/application/models/redis_model.php +++ b/application/models/redis_model.php @@ -8,6 +8,10 @@ class Redis_Model extends CI_Model { private $_port; private $_db; private $_auth; + + private $_config; + + private $_is_cluster; public function __construct() { @@ -28,17 +32,21 @@ public function init($redis_config) ){ show_error('Redis Config Error'); } - + + $this -> _is_cluster = FALSE; + if ( isset($redis_config['host']) ) { return $this -> _init_redis($redis_config); } elseif ( ( isset($redis_config['cluster_list']) ) && ( is_array($redis_config['cluster_list']) ) ){ $this -> _init_cluster($redis_config); + $this -> _is_cluster = TRUE; } else{ show_error('Redis Config Error'); } + $this -> _config = $redis_config; } private function _init_cluster($redis_config) @@ -153,7 +161,9 @@ public function get_keys_count() */ public function get_all_keys($prefix = '', $need_sort = TRUE) { - if ( method_exists($this -> _redis, 'scan') ) { + if ( ( method_exists($this -> _redis, 'scan') ) + && ( ! $this -> _is_cluster ) + ){ return $this -> get_all_keys_by_scan($prefix, $need_sort); } @@ -188,9 +198,15 @@ public function get_all_keys_by_scan($prefix = '', $need_sort = TRUE) public function scan_keys($prefix, $iterator, $need_sort = TRUE) { $keys = array(); - $scan_prefix = empty($prefix) ? NULL : $prefix . '*'; $this -> _redis -> setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); - $keys = $this -> _redis -> scan($iterator, $scan_prefix, TREE_KEY_PAGE_SIZE); + if ( ! $this -> _is_cluster ) { + $scan_prefix = empty($prefix) ? NULL : $prefix . '*'; + $keys = $this -> _redis -> scan($iterator, $scan_prefix, TREE_KEY_PAGE_SIZE); + } else { + $scan_prefix = empty($prefix) ? '*' : $prefix . '*'; + $keys = $this -> _redis -> keys($scan_prefix); + $iterator = 0; + } if ( $need_sort ) { sort($keys); From 4bca806c0d7c9fb51111dae2253cad8211c33aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=B9=BF=E6=96=87?= Date: Thu, 20 Oct 2016 10:25:13 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E4=B8=AD=E7=9A=84BUG=EF=BC=8C=E4=BF=AE=E6=AD=A3=E5=A4=9A?= =?UTF-8?q?=E5=A4=84JS=E7=BC=BA=E5=A4=B1=E5=AF=BC=E8=87=B4=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/config/config_global.php | 6 + application/config/config_redis.php | 7 + application/config/config_redis_github.php | 26 ++ application/controllers/clear_idle_key.php | 99 +++++++ application/controllers/export.php | 20 +- application/controllers/index.php | 6 + application/core/MY_Controller.php | 5 + application/helpers/common_helper.php | 3 +- application/models/redis_model.php | 4 +- application/views/clear_idle_key.php | 145 ++++++++++ application/views/index.php | 3 +- static/js/common.js | 321 ++++++++++++++++++++- 12 files changed, 632 insertions(+), 13 deletions(-) create mode 100644 application/config/config_redis_github.php create mode 100644 application/controllers/clear_idle_key.php create mode 100644 application/views/clear_idle_key.php diff --git a/application/config/config_global.php b/application/config/config_global.php index ef1f6cb..86976de 100644 --- a/application/config/config_global.php +++ b/application/config/config_global.php @@ -47,3 +47,9 @@ */ $config['tree_key_page_size'] = 10000; +/* + * 检索空闲key时每次读取的个数 + * 如为本机或本地局域网 建议甚至为1000-2000 + * 如为远程redis服务器,建议设置100-500 + */ +$config['idle_key_page_size'] = 1000; diff --git a/application/config/config_redis.php b/application/config/config_redis.php index 81eff35..af18a11 100644 --- a/application/config/config_redis.php +++ b/application/config/config_redis.php @@ -7,6 +7,13 @@ 'port' => 6379, 'auth' => FALSE, //如无密码,可不设置此键,或将值设置为FALSE or NULL ), + array( + 'name' => '智检生产', + 'host' => '127.0.0.1', + 'port' => 6401, + 'auth' => FALSE, //如无密码,可不设置此键,或将值设置为FALSE or NULL + ), + /* * 集群服务器 */ diff --git a/application/config/config_redis_github.php b/application/config/config_redis_github.php new file mode 100644 index 0000000..81eff35 --- /dev/null +++ b/application/config/config_redis_github.php @@ -0,0 +1,26 @@ + 'localhost server', + 'host' => '127.0.0.1', + 'port' => 6379, + 'auth' => FALSE, //如无密码,可不设置此键,或将值设置为FALSE or NULL + ), + /* + * 集群服务器 + */ + /* + array( + 'name' => 'cluster server', + 'cluster_list' => array( + '127.0.0.1:7000', + '127.0.0.1:7001', + '127.0.0.1:7002', + '127.0.0.1:7010', + '127.0.0.1:7011', + '127.0.0.1:7012', + ), + ), + */ +); diff --git a/application/controllers/clear_idle_key.php b/application/controllers/clear_idle_key.php new file mode 100644 index 0000000..3f769a9 --- /dev/null +++ b/application/controllers/clear_idle_key.php @@ -0,0 +1,99 @@ + _idle_key = get_custom_config('config_global', 'idle_key'); + } + + public function index() + { + $db_size = $this -> redis_model -> get_db_size(); + + $page_data = $this -> get_default_page_data(); + $page_data['db_size'] = $db_size; + $page_data['title'] = '检索/删除 空闲key'; + + $this -> load -> view('clear_idle_key', $page_data); + } + + public function view_idle_key_list() + { + $iterator = get_arg('iterator', -1, 'intval'); + $idle_time = get_arg('idle_time', 0, 'intval'); + $key_prefix = get_arg('key_prefix', '', 'trim'); + if ( $idle_time < 5 ) { + show_message(1, sprintf('设置的时间[%d]过短,空闲时间不建议小于5秒', $idle_time)); + + } + $iterator = ($iterator === -1) ? NULL : $iterator; + $sub_key = ''; + if ( $key_prefix != '' ) { + $sub_key = $key_prefix . '*'; + } + $result = $this -> redis_model -> scan_keys($sub_key, $iterator, TRUE, IDLE_KEY_PAGE_SIZE); + $redis_keys = $result['keys']; + $new_iterator = $result['iterator']; + $ret_arr = array(); + if ( ! empty($redis_keys) ) { + $redis = $this -> redis_model -> get_redis_instance(); + foreach($redis_keys as $key) { + $t = $redis -> object('idletime', $key); + if ( $t >= $idle_time ) { + $ret_arr[] = array( + 'k' => htmlspecialchars($key), + 't' => $t, + ); + } + } + } + show_message(0, '', array( + 'iterator' => $new_iterator, + 'idle_keys' => $ret_arr, + )); + } + + public function clear_keys() + { + $iterator = get_arg('iterator', -1, 'intval'); + $idle_time = get_arg('idle_time', 0, 'intval'); + $key_prefix = get_arg('key_prefix', '', 'trim'); + if ( $idle_time < 5 ) { + show_message(1, sprintf('设置的时间[%d]过短,空闲时间不建议小于5秒', $idle_time)); + + } + $iterator = ($iterator === -1) ? NULL : $iterator; + $sub_key = ''; + if ( $key_prefix != '' ) { + $sub_key = $key_prefix . '*'; + } + $result = $this -> redis_model -> scan_keys($sub_key, $iterator, TRUE, IDLE_KEY_PAGE_SIZE); + $redis_keys = $result['keys']; + $new_iterator = $result['iterator']; + $ret_arr = array(); + $affected = 0; + if ( ! empty($redis_keys) ) { + $redis = $this -> redis_model -> get_redis_instance(); + foreach($redis_keys as $key) { + $t = $redis -> object('idletime', $key); + if ( $t >= $idle_time ) { + $redis -> delete($key); + $affected += 1; + } + } + } + show_message(0, '', array( + 'iterator' => $new_iterator, + 'affected' => $affected, + )); + } +} diff --git a/application/controllers/export.php b/application/controllers/export.php index 5bfebc0..67aafb6 100644 --- a/application/controllers/export.php +++ b/application/controllers/export.php @@ -118,38 +118,44 @@ private function _export_redis($key) // Hash else if ($type == 'hash') { $values = $redis -> hGetAll($key); - + $result = array(); foreach ($values as $k => $v) { - return 'HSET "' . addslashes($key) . '" "' . addslashes($k) . '" "' . addslashes($v) . '"'; + $result[] = 'HSET "' . addslashes($key) . '" "' . addslashes($k) . '" "' . addslashes($v) . '"'; } + return implode(PHP_EOL, $result); } // List else if ($type == 'list') { $size = $redis -> lSize($key); - - for ($i = 0; $i < $size; ++$i) { - return 'RPUSH "' . addslashes($key) . '" "' . addslashes($redis -> lGet($key . $i)) . '"'; + $result = array(); + for ($i = 0; $i < $size; $i++) { + $result[] = 'RPUSH "' . addslashes($key) . '" "' . addslashes($redis -> lGet($key, $i)) . '"'; } + return implode(PHP_EOL, $result); } // Set else if ($type == 'set') { $values = $redis -> sMembers($key); + $result = array(); foreach ($values as $v) { - return 'SADD "' . addslashes($key) . '" "' . addslashes($v) . '"'; + $result[] = 'SADD "' . addslashes($key) . '" "' . addslashes($v) . '"'; } + return implode(PHP_EOL, $result); } // ZSet else if ($type == 'zset') { $values = $redis -> zRange($key, 0, -1); + $result = array(); foreach ($values as $v) { $s = $redis -> zScore($key, $v); - return 'ZADD "' . addslashes($key) . '" ' . $s . ' "' . addslashes($v) . '"'; + $result[] = 'ZADD "' . addslashes($key) . '" ' . $s . ' "' . addslashes($v) . '"'; } + return implode(PHP_EOL, $result); } } diff --git a/application/controllers/index.php b/application/controllers/index.php index a9641b3..7c34741 100644 --- a/application/controllers/index.php +++ b/application/controllers/index.php @@ -100,5 +100,11 @@ public function idle() $this -> index(); } + public function clear_idle_key() + { + $this -> _current_method = 'clear_idle_key'; + $this -> index(); + } + } diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 423a7ec..dfe50c7 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -85,6 +85,11 @@ public function __construct(){ * 异步加载建树时,一次读取的key的数量 */ define('TREE_KEY_PAGE_SIZE', get_custom_config('config_global', 'tree_key_page_size')); + + /* + * 异步查找空闲Key时,一次读取的key的数量 + */ + define('IDLE_KEY_PAGE_SIZE', get_custom_config('config_global', 'idle_key_page_size')); define('PROJECT_NAME', get_custom_config('config_global', 'project_name')); define('VERSION', get_custom_config('config_global', 'version')); diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php index 1b39682..8dd480f 100644 --- a/application/helpers/common_helper.php +++ b/application/helpers/common_helper.php @@ -103,7 +103,8 @@ function get_custom_config($config_file, $config_item) if (! function_exists('format_html') ) { function format_html($str) { - return htmlentities($str, ENT_COMPAT, 'UTF-8'); + return htmlspecialchars($str, ENT_SUBSTITUTE + ENT_QUOTES); + } } diff --git a/application/models/redis_model.php b/application/models/redis_model.php index 6e729fd..9f382ba 100644 --- a/application/models/redis_model.php +++ b/application/models/redis_model.php @@ -195,13 +195,13 @@ public function get_all_keys_by_scan($prefix = '', $need_sort = TRUE) return $keys; } - public function scan_keys($prefix, $iterator, $need_sort = TRUE) + public function scan_keys($prefix, $iterator, $need_sort = TRUE, $page_size = TREE_KEY_PAGE_SIZE) { $keys = array(); $this -> _redis -> setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); if ( ! $this -> _is_cluster ) { $scan_prefix = empty($prefix) ? NULL : $prefix . '*'; - $keys = $this -> _redis -> scan($iterator, $scan_prefix, TREE_KEY_PAGE_SIZE); + $keys = $this -> _redis -> scan($iterator, $scan_prefix, $page_size); } else { $scan_prefix = empty($prefix) ? '*' : $prefix . '*'; $keys = $this -> _redis -> keys($scan_prefix); diff --git a/application/views/clear_idle_key.php b/application/views/clear_idle_key.php new file mode 100644 index 0000000..c6f55a8 --- /dev/null +++ b/application/views/clear_idle_key.php @@ -0,0 +1,145 @@ + +

+ +

+
+
+ 当前db的Key总数为: + = 100000 ) { ?> + 数据较多,生成报表会较久 + +
+
+
+
+ 空闲时间(秒): + + 1天[86400] 3天[259200] 7天[604800] 30天[2592000] +
+
+ Key前缀过滤: + +
+
+ + + +
+
+

+
+ + + + + + + + + + + + + + diff --git a/application/views/index.php b/application/views/index.php index 2c28e82..e3d34b0 100644 --- a/application/views/index.php +++ b/application/views/index.php @@ -30,7 +30,8 @@ 导出所有数据 导入数据 服务器一览表 - 空闲key列表 + + 检索/删除 空闲key 退出登录     diff --git a/static/js/common.js b/static/js/common.js index 3907c05..f6872e9 100644 --- a/static/js/common.js +++ b/static/js/common.js @@ -1,3 +1,4 @@ + $(function($){ $('#server').change(function(e) { _change_server(); @@ -25,6 +26,12 @@ $(function($){ location.href = url; } + $('#type').change(function(e) { + $('#hkeyp' ).css('display', e.target.value == 'hash' ? 'block' : 'none'); + $('#indexp').css('display', e.target.value == 'list' ? 'block' : 'none'); + $('#scorep').css('display', e.target.value == 'zset' ? 'block' : 'none'); + }).change(); + if (history.replaceState) { var params = getRequest(); params['m'] = params['c']; @@ -38,6 +45,22 @@ $(function($){ window.parent.history.replaceState({}, '', href); } + + + $('.delkey, .delval').click(function(e) { + e.preventDefault(); + + if (confirm($(this).hasClass('delkey') ? '确认要删除这个KEY及其所有的值吗?' : '确认要删除这个值吗?')) { + $.ajax({ + type: "POST", + url: this.href, + data: 'post=1', + success: function(url) { + location.href = url; + } + }); + } + }); }) var getRequest = function() { @@ -85,7 +108,6 @@ var addDiyDom = function(treeId, treeNode) { } } - var redisAdmin = function(options){ /* options = { @@ -162,7 +184,7 @@ redisAdmin.prototype.loadData = function(prefix) { url: that.options.baseUrl + "?c=key&key="+ prefix + '&' + that.options.extraParams, data: {"iterator": iterator}, dataType: 'json', - timeout: 10000, + timeout: 30000, success: function(json) { if ( typeof json == 'object' ) { if (json.result == 0) { @@ -223,3 +245,298 @@ redisAdmin.prototype.loadData = function(prefix) { var iterator = -1; _doLoadData(prefix, iterator); } + + + +var redisAdminIdle = function(options){ + /* + options = { + //前缀 + prefix : string + //基础URL + baseUrl : string, + //附加参数 + extraParams : string, + //表格的ID + tableDom : string, + //显示tips的Id + tipsDom : string, + //读取完数据后的callback + loadCompleteCallback: func + //清理完数据后的callback + clearCompleteCallback: func + } + */ + this.options = { + displayPerTime: 500, + prefix: '', + baseUrl: '', + extraParams: '', + tableDom: '', + tipsDom: '', + loadCompleteCallback: null, + clearCompleteCallback: null + } + + this.options = $.extend(this.options, options) + if ( this.options.baseUrl == '' ) { + alert('options error, baseUrl empty') + return ; + } + if ( this.options.tableBodyDom == '' ) { + alert('options error, tableBodyDom empty') + return ; + } + + this.keyMap = {} + this.keyCnt = 0; + if (this.options.tipsDom != '') { + this.tipDomObj = $("#" + this.options.tipsDom) + } + this.tableObj = $("#" + this.options.tableDom); + if (this.tableObj.length <= 0) { + alert('没有找到表格标签'); + return ; + } + this.tableBodyOby = $("#" + this.options.tableDom + '_body'); + if (this.tableBodyOby.length <= 0) { + alert('没有找到表格TBody标签'); + return ; + } +} + +redisAdminIdle.prototype.displayData = function(orderBy, displayCnt) { + function _createTableBody(key, idle_time) { + alt = ! alt; + cls = alt ? ' class="alt"' : ''; + return '\ + \ +
' + key + '
\ +
' + idle_time + '
\ + '; + } + + this.tableBodyOby.empty(); + var alt = false; + displayCnt = displayCnt == null ? -1 : displayCnt; + + if ( orderBy == 'key' ) { + var keys = []; + var key; + for (key in this.keyMap) { + keys.push(key) + } + + var currentCnt = 0; + var i; + var cnt = 0; + var _html = []; + keys = keys.sort() + for (i in keys) { + cnt += 1; + key = keys[i]; + _html.push(_createTableBody(key, this.keyMap[key])) + if (cnt >= this.options.displayPerTime) { + this.tableBodyOby.append(_html.join("")); + cnt = 0; + _html = []; + } + currentCnt += 1; + if ( (displayCnt != -1) && (currentCnt >= displayCnt) ) { + break; + } + } + if (cnt > 0) { + this.tableBodyOby.append(_html.join("")); + cnt = 0; + _html = []; + } + } else { + var currentCnt = 0; + var cnt = 0; + var _html = []; + var key; + for (key in this.keyMap) { + cnt += 1; + _html.push(_createTableBody(key, this.keyMap[key])) + if (cnt >= this.options.displayPerTime) { + this.tableBodyOby.append(_html.join("")); + cnt = 0; + _html = []; + } + currentCnt += 1; + if ( (displayCnt != -1) && (currentCnt >= displayCnt) ) { + break; + } + } + if (cnt > 0) { + this.tableBodyOby.append(_html.join("")); + cnt = 0; + _html = []; + } + } + this.tableObj.show(); +} + +redisAdminIdle.prototype.showTips = function(tipContent) { + if (this.tipDomObj.length > 0) { + this.tipDomObj.html(tipContent) + } +} + +redisAdminIdle.prototype.loadDataComplete = function() { + if (typeof this.options.loadCompleteCallback == 'function' ) { + this.options.loadCompleteCallback(this); + } else { + this.displayData(); + } +} + + +redisAdminIdle.prototype.loadData = function(idle_time){ + var that = this; + that.keyCnt = 0; + var requestTimes = 0; + var _doLoadData = function(prefix, iterator, idle_time) { + $.ajax({ + type: "GET", + url: that.options.baseUrl + "?c=clear_idle_key&m=view_idle_key_list&" + that.options.extraParams, + data: { + iterator: iterator, + idle_time: idle_time, + key_prefix: prefix + }, + dataType: 'json', + timeout: 30000, + success: function(json) { + if ( typeof json == 'object' ) { + if (json.result == 0) { + if (_global.forceStop) { + that.showTips('用户中止操作'); + //去锁 + _global.isLock = false; + return ; + } + + var data = json.data; + var tempObj, name; + that.keyCnt += data['idle_keys'].length; + for (var i in data['idle_keys'] ) { + tempObj = data['idle_keys'][i] + that.keyMap[tempObj['k']] = tempObj['t']; + } + + requestTimes += 1; + that.showTips('已经完成' + requestTimes + '次请求,找到吻合条件数据:' + that.keyCnt); + + if (( typeof data.iterator != 'undefined') + && ( data.iterator > 0 ) + ){ + _doLoadData(prefix, data.iterator, idle_time); + } else { + that.loadDataComplete(); + //去锁 + _global.isLock = false; + return ; + } + } else { + _global.isLock = false; + alert('连接服务器时发生错误:' + json.msg); + return ; + } + } else { + _global.isLock = false; + alert('连接服务器出错。'); + } + + }, + error: function(){ + alert('连接服务器超时'); + _global.isLock = false; + } + }); + } + + if ( _global.isLock ) { + return ; + } + _global.isLock = true; + + var iterator = -1; + _doLoadData(this.options.prefix, iterator, idle_time); +} + +redisAdminIdle.prototype.clearDataComplete = function(){ + if (typeof this.options.clearCompleteCallback == 'function' ) { + this.options.clearCompleteCallback(this); + } else { + alert('清理完毕'); + } +} + + +redisAdminIdle.prototype.clearData = function(idle_time){ + var that = this; + that.keyCnt = 0; + var _doclearData = function(prefix, iterator, idle_time) { + $.ajax({ + type: "GET", + url: that.options.baseUrl + "?c=clear_idle_key&m=clear_keys&" + that.options.extraParams, + data: { + iterator: iterator, + idle_time: idle_time, + key_prefix: prefix + }, + dataType: 'json', + timeout: 10000, + success: function(json) { + if ( typeof json == 'object' ) { + if (json.result == 0) { + if (_global.forceStop) { + that.showTips('用户中止操作'); + //去锁 + _global.isLock = false; + return ; + } + + var data = json.data; + that.keyCnt += data['affected']; + + that.showTips('已清理Key数量:' + that.keyCnt); + + if (( typeof data.iterator != 'undefined') + && ( data.iterator > 0 ) + ){ + _doclearData(prefix, data.iterator, idle_time); + } else { + that.clearDataComplete(); + //去锁 + _global.isLock = false; + return ; + } + } else { + _global.isLock = false; + alert('连接服务器时发生错误:' + json.msg); + return ; + } + } else { + _global.isLock = false; + alert('连接服务器出错。'); + } + + }, + error: function(){ + alert('连接服务器超时'); + _global.isLock = false; + } + }); + } + + if ( _global.isLock ) { + return ; + } + _global.isLock = true; + + var iterator = -1; + _doclearData(this.options.prefix, iterator, idle_time); +} \ No newline at end of file From 75f09fb3362b103b2fd06933138a56f219de65c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=B9=BF=E6=96=87?= Date: Thu, 20 Oct 2016 10:25:39 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js/common_bk.js | 325 ----------------------------------------- 1 file changed, 325 deletions(-) delete mode 100644 static/js/common_bk.js diff --git a/static/js/common_bk.js b/static/js/common_bk.js deleted file mode 100644 index 63a82cb..0000000 --- a/static/js/common_bk.js +++ /dev/null @@ -1,325 +0,0 @@ -$(function($){ - $('#server').change(function(e) { - _change_server(); - }); - - $('#redis_db').change(function(e) { - _change_server(); - }); - - var _change_server = function() { - var server = $('#server').val(); - var db = $('#redis_db').val(); - var request = getRequest(); - request['server_id'] = server; - request['db'] = db; - - var url = 'http://' + location.host + location.pathname + '?'; - for(var i in request) { - - url += i + ( (typeof request[i] == 'undefined' || request[i] == 'undefined') ? '' : '=' + request[i] ); - url += '&'; - } - - url = url.substr(0, url.length - 1); - location.href = url; - } - - if (history.replaceState) { - var params = getRequest(); - params['m'] = params['c']; - params['c'] = 'index'; - var href = location.protocol + '\/\/' + location.host + location.pathname; - var separator = '?'; - for(var key in params) { - href += separator + key + '=' + params[key]; - separator = '&'; - } - - window.parent.history.replaceState({}, '', href); - } -}) - -var getRequest = function() { - var url = location.search; //获取url中"?"符后的字串 - var theRequest = new Object(); - if (url.indexOf("?") != -1) { - var str = url.substr(1); - strs = str.split("&"); - for(var i = 0; i < strs.length; i ++) { - theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]); - } - } - return theRequest; -} - - -var delTree = function(obj){ - if (confirm('确定要删除整个树及其所有的键吗?')) { - $.ajax({ - type: "POST", - url: obj.href, - data: {}, - timeout: 120000, - success: function(url) { - top.location.href = url; - } - }); - } - return false; -} - -var addDiyDom = function(treeId, treeNode) { - if ( (typeof treeNode['isDir'] != 'undefined') - && ( treeNode['isDir'] ) - ){ - var aObj = $("#" + treeNode.tId + '_a'); - var urlExport = _global.baseUrl + '?c=export&m=index&key=' + treeNode.id + ':*&' + _global.urlParams; - var urlDelete = _global.baseUrl + '?c=delete&m=index&tree=' + treeNode.id + ':&' + _global.urlParams; - var editStr = ""; - editStr += ""; - aObj.append(editStr); - } -} - - -var redisAdmin = function(options){ - /* - options = { - //目标dom节点 - targetDom : string - //基础URL - baseUrl : string, - //附加参数 - extraParams : string, - //分割符 - seperator: ':' - } - */ - this.treeNodeSetting = { - pIdKey: 'pId', - idKey: 'id', - childKey: 'children', - countKey: 'count' - } - - this.formatedData = []; - this.formatedDataForBuildTree = [] - this.options = options; - - this.keyList = []; - - this.existsNodeKey = {} -} - -redisAdmin.prototype.transformTozTreeFormat = function(pageSize) { - this.formatedData = []; - var i,l, - key = this.treeNodeSetting.idKey, - parentKey = this.treeNodeSetting.pIdKey, - childKey = this.treeNodeSetting.children; - if (!key || key=="" || !sNodes) return []; - - var tmpMap = []; - for (i=0, l=sNodes.length; i= pageSize ) { - break - } - } - } - - } - var r = []; - var node; - var tmpLen; - var parentKey = this.treeNodeSetting.pIdKey; - var childKey = this.treeNodeSetting.childKey; - var countKey = this.treeNodeSetting.countKey; - for (i = 0, l = this.formatedData.length; i < l; i++ ) { - var dstObj = {} - copyNode(r, this.formatedData[i], dstObj, 10) - } -} - -redisAdmin.prototype.buildTree = function() { - - - return ; - var $obj = $("#" + this.options.targetDom); - $obj.html(''); - - var setting = { - data: { - simpleData: { - enable: true - } - }, - view: { - addDiyDom: addDiyDom - } - }; - - _global.ztreeObj = $.fn.zTree.init($obj, setting, this.keyList); - _global.inited = true; -} - -redisAdmin.prototype.loadData = function(prefix) { - var that = this; - - var _buildParentNood = function(arr) { - var id = arr.join(that.options.seperator); - if ( typeof that.existsNodeKey[id] != 'undefined' ) { - return - } - that.existsNodeKey[id] = 1; - var name = arr.pop(); - var obj = { - id: id, - pId: arr.length > 0 ? arr.join(that.options.seperator) : -1, - isDir: true, - name: name - } - that.keyList.push(obj) - if ( arr.length > 0 ) { - _buildParentNood(arr); - } - } - - var _doLoadData = function(prefix, iterator) { - $.ajax({ - type: "GET", - url: that.options.baseUrl + "?c=key&key="+ prefix + '&' + that.options.extraParams, - data: {"iterator": iterator}, - dataType: 'json', - timeout: 10000, - success: function(json) { - if ( typeof json == 'object' ) { - if (json.result == 0) { - var data = json.data; - var tempArr, name; - for (var i in data['keys'] ) { - tempArr = data['keys'][i].split(that.options.seperator) - name = tempArr.pop(); - var obj = { - id: data['keys'][i], - pId: tempArr.length > 0 ? tempArr.join(that.options.seperator) : -1, - name: name, - isDir: false, - target: "iframe", - url: that.options.baseUrl + "?c=view&m=index&key="+ data['keys'][i] + '&' + that.options.extraParams - } - - that.keyList.push(obj); - if ( tempArr.length > 0 ) { - _buildParentNood(tempArr); - } - } - - $("#current_loaded").html(that.keyList.length) - - if (( typeof data.iterator != 'undefined') - && ( data.iterator > 0 ) - ){ - _doLoadData(prefix, data.iterator); - } else { - that.buildTree() - //去锁 - _global.isLock = false; - } - } else { - _global.isLock = false; - alert('连接服务器时发生错误:' + json.msg); - } - } else { - _global.isLock = false; - alert('连接服务器出错。'); - } - - }, - error: function(){ - alert('连接服务器超时'); - _global.isLock = false; - } - }); - } - - if ( _global.isLock ) { - return ; - } - _global.isLock = true; - this.keyList = [{id: -1, pId: 0, name: "Keys"}]; - - var iterator = -1; - _doLoadData(prefix, iterator); -} From 6ed81f1072afb6e15527bfefcc1344f0bbc36e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=B9=BF=E6=96=87?= Date: Thu, 20 Oct 2016 10:30:51 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E6=B8=85=E7=90=86=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/config/config_redis.php | 7 ------ application/config/config_redis_github.php | 26 ---------------------- 2 files changed, 33 deletions(-) delete mode 100644 application/config/config_redis_github.php diff --git a/application/config/config_redis.php b/application/config/config_redis.php index af18a11..81eff35 100644 --- a/application/config/config_redis.php +++ b/application/config/config_redis.php @@ -7,13 +7,6 @@ 'port' => 6379, 'auth' => FALSE, //如无密码,可不设置此键,或将值设置为FALSE or NULL ), - array( - 'name' => '智检生产', - 'host' => '127.0.0.1', - 'port' => 6401, - 'auth' => FALSE, //如无密码,可不设置此键,或将值设置为FALSE or NULL - ), - /* * 集群服务器 */ diff --git a/application/config/config_redis_github.php b/application/config/config_redis_github.php deleted file mode 100644 index 81eff35..0000000 --- a/application/config/config_redis_github.php +++ /dev/null @@ -1,26 +0,0 @@ - 'localhost server', - 'host' => '127.0.0.1', - 'port' => 6379, - 'auth' => FALSE, //如无密码,可不设置此键,或将值设置为FALSE or NULL - ), - /* - * 集群服务器 - */ - /* - array( - 'name' => 'cluster server', - 'cluster_list' => array( - '127.0.0.1:7000', - '127.0.0.1:7001', - '127.0.0.1:7002', - '127.0.0.1:7010', - '127.0.0.1:7011', - '127.0.0.1:7012', - ), - ), - */ -); From eff667e3811c051238468f22b6d90bf464f2965e Mon Sep 17 00:00:00 2001 From: daivem <13358533@qq.com> Date: Thu, 20 Oct 2016 10:35:45 +0800 Subject: [PATCH 06/14] Update README Update README --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1bb9f26..2f33813 100644 --- a/README.md +++ b/README.md @@ -46,14 +46,23 @@ TODO: 更新日志: +v0.4.2 (2016-10-20) + +增加删除空闲Key的功能,配置详见config_global.php + +修正导出中的BUG + +修正因JS缺失而产生的BUG + +—————————————————— + + v0.4.1 (2016-09-19) 修正scan在集群模式下不可用的问题(由于官方文档缺失,暂时将集群模式读取key列表改回原来的keys命令,如有错误,请斧正) —————————————————— -更新日志: - v0.4.0 (2016-09-05) 采用scan命令读取key列表(redis >= 2.8),页面建树改用ztree ( https://github.com/zTree/zTree_v3 ),单个节点超过10万时不建议展开(好吧,有可能展不开) From c18d67dbcda859339aafe5c59b0e157ff40362c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=B9=BF=E6=96=87?= Date: Thu, 20 Oct 2016 10:55:12 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=80=E4=B8=AAphp5.?= =?UTF-8?q?4=E5=8F=8A=E4=BB=A5=E4=B8=8B=E7=9A=84=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/config/config_global.php | 2 +- application/helpers/common_helper.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/application/config/config_global.php b/application/config/config_global.php index 86976de..b90e1cc 100644 --- a/application/config/config_global.php +++ b/application/config/config_global.php @@ -1,7 +1,7 @@ Date: Wed, 24 Apr 2024 14:13:41 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E5=9C=A8redis=E7=9A=84key=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E9=9D=9Eutf8=E5=AD=97=E7=AC=A6=E6=97=B6=EF=BC=8Cjson?= =?UTF-8?q?=5Fencode=E5=87=BD=E6=95=B0=E4=BC=9A=E5=87=BA=E9=94=99=EF=BC=8C?= =?UTF-8?q?=20=E8=BF=94=E5=9B=9Enull,=E9=80=A0=E6=88=90=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=9A=84key=E4=B8=8D=E5=8F=AF=E8=A7=81,=20=E4=B8=8B=E9=9D=A2?= =?UTF-8?q?=E7=9A=84php=E7=94=9F=E6=88=90=E7=9A=84key,=E5=9C=A8RedisMyAdmi?= =?UTF-8?q?n=E4=B8=AD=E4=B8=8D=E8=83=BD=E6=98=BE=E7=A4=BA=E3=80=82?= =?UTF-8?q?=E6=9C=AC=E6=AC=A1=E4=BF=AE=E6=94=B9=E8=A7=A3=E5=86=B3=E8=BF=99?= =?UTF-8?q?=E4=B8=AA=E9=97=AE=E9=A2=98=EF=BC=8C=E5=9C=A8=E6=98=BE=E7=A4=BA?= =?UTF-8?q?key=E7=9A=84=E5=9C=B0=E6=96=B9=EF=BC=8C=20=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E7=9A=84=E7=BC=96=E7=A0=81=EF=BC=8C=20?= =?UTF-8?q?=E5=9C=A8=E5=AE=9E=E9=99=85=E6=93=8D=E4=BD=9Credis=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=20=E4=BD=BF=E7=94=A8=E7=9C=9F=E5=AE=9E=E7=9A=84key.?= =?UTF-8?q?=20<=3Fphp=20$redis=20=3D=20new=20Redis();=20$redis->connect('1?= =?UTF-8?q?27.0.0.1',6379);=20$redis->setex("abc\xFFdef",=203600*24,=20'te?= =?UTF-8?q?st');?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #25 --- application/controllers/delete.php | 9 ++++++++- application/controllers/rename.php | 20 ++++++++++++++++---- application/controllers/ttl.php | 20 ++++++++++++++++---- application/controllers/view.php | 28 +++++++++++++++++----------- application/models/redis_model.php | 6 +++++- 5 files changed, 62 insertions(+), 21 deletions(-) diff --git a/application/controllers/delete.php b/application/controllers/delete.php index 44e362e..57e0333 100644 --- a/application/controllers/delete.php +++ b/application/controllers/delete.php @@ -16,6 +16,13 @@ public function __construct() public function index() { $key = get_arg('key'); + + if(strpos($key,"\\")){ + $key_raw = urldecode(strtr($key, array('\x'=>'%'))); + } else { + $key_raw = $key; + } + $type = strtolower( get_arg('type') ); $allow_type = array('' ,'string', 'hash', 'list', 'set', 'zset'); @@ -24,7 +31,7 @@ public function index() && ( $key !== '' ) && ( in_array($type, $allow_type) ) ){ - $this -> _delete_key($type, $key); + $this -> _delete_key($type, $key_raw); $url = manager_site_url('view', 'index', 'key=' . urlencode($key)); die($url); diff --git a/application/controllers/rename.php b/application/controllers/rename.php index f41f253..4585748 100644 --- a/application/controllers/rename.php +++ b/application/controllers/rename.php @@ -25,14 +25,20 @@ public function index() show_error('没有找到参数Key'); } + if(strpos($key,"\\")){ + $key_raw = urldecode(strtr($key, array('\x'=>'%'))); + } else { + $key_raw = $key; + } + $redis = $this -> redis_model -> get_redis_instance(); - $key_exists = $redis -> exists($key); + $key_exists = $redis -> exists($key_raw); if ( ! $key_exists ) { show_error('Key[' . $key . ']不存在'); } $page_data = $this -> get_default_page_data(); - $page_data['key'] = $key; + $page_data['key'] = $key_raw; $page_data['title'] = '重命名Key[' . $key . ']'; $this -> load -> view('rename', $page_data); @@ -49,17 +55,23 @@ private function _do_index() show_error('没有找到新键名参数key'); } + if(strpos($old_key,"\\")){ + $old_key_raw = urldecode(strtr($old_key, array('\x'=>'%'))); + } else { + $old_key_raw = $old_key; + } + if ( strlen($key) > MAX_KEY_LEN ) { show_error('Key长度[' . strlen($key) . ']超过限制,当前限制为[' . MAX_KEY_LEN . ']'); } $redis = $this -> redis_model -> get_redis_instance(); - $key_exists = $redis -> exists($old_key); + $key_exists = $redis -> exists($old_key_raw); if ( ! $key_exists ) { show_error('Key[' . $old_key . ']不存在'); } - $redis -> rename($old_key, $key); + $redis -> rename($old_key_raw, $key); $url = manager_site_url('view', 'index', 'key=' . urlencode($key)); Header('Location:' . $url); diff --git a/application/controllers/ttl.php b/application/controllers/ttl.php index 48957fd..83dcadb 100644 --- a/application/controllers/ttl.php +++ b/application/controllers/ttl.php @@ -26,8 +26,14 @@ public function index() show_error('没有找到参数Key'); } + if(strpos($key,"\\")){ + $key_raw = urldecode(strtr($key, array('\x'=>'%'))); + } else { + $key_raw = $key; + } + $redis = $this -> redis_model -> get_redis_instance(); - $key_exists = $redis -> exists($key); + $key_exists = $redis -> exists($key_raw); if ( ! $key_exists ) { show_error('Key[' . $key . ']不存在'); } @@ -48,9 +54,15 @@ private function _do_index() { $key = get_post_arg('key'); + if(strpos($key,"\\")){ + $key_raw = urldecode(strtr($key, array('\x'=>'%'))); + } else { + $key_raw = $key; + } + $redis = $this -> redis_model -> get_redis_instance(); - $key_exists = $redis -> exists($key); + $key_exists = $redis -> exists($key_raw); if ( ! $key_exists ) { show_error('Key[' . $key . ']不存在'); @@ -58,9 +70,9 @@ private function _do_index() $ttl = get_post_arg('ttl'); if ( $ttl == '-1' ) { - $redis -> persist($key); + $redis -> persist($key_raw); } else { - $redis -> expire($key, $ttl); + $redis -> expire($key_raw, $ttl); } $url = manager_site_url('view', 'index', 'key=' . urlencode($key)); diff --git a/application/controllers/view.php b/application/controllers/view.php index baed2a1..30278af 100644 --- a/application/controllers/view.php +++ b/application/controllers/view.php @@ -20,13 +20,19 @@ public function index() if ($key === NULL) { show_error('没有找到参数Key'); } - + + if(strpos($key,"\\")){ + $key_raw = urldecode(strtr($key, array('\x'=>'%'))); + } else { + $key_raw = $key; + } + $redis = $this -> redis_model -> get_redis_instance(); $page_data = $this -> get_default_page_data(); - $key_type = $this -> redis_model -> get_key_type($key); - $key_exists = $redis -> exists($key); + $key_type = $this -> redis_model -> get_key_type($key_raw); + $key_exists = $redis -> exists($key_raw); $page_data['exists'] = $key_exists; $page_data['key'] = $key; @@ -37,36 +43,36 @@ public function index() $redis_types = $this -> redis_model -> get_redis_types(); $type = $redis_types[$key_type]; - $ttl = $redis -> ttl($key); - $encoding = $redis -> object('encoding', $key); + $ttl = $redis -> ttl($key_raw); + $encoding = $redis -> object('encoding', $key_raw); switch ($type) { case 'string': - $values = $redis -> get($key); + $values = $redis -> get($key_raw); $size = strlen($values); $template = 'view_string'; break; case 'hash': - $values = $redis -> hGetAll($key); + $values = $redis -> hGetAll($key_raw); $size = count($values); $template = 'view_hash'; break; case 'list': - $size = $redis -> lSize($key); - $values = $redis -> lRange($key, 0, -1); + $size = $redis -> lSize($key_raw); + $values = $redis -> lRange($key_raw, 0, -1); $template = 'view_list'; break; case 'set': - $values = $redis -> sMembers($key); + $values = $redis -> sMembers($key_raw); $size = count($values); $template = 'view_set'; break; case 'zset': - $values = $redis -> zRange($key, 0, -1, 1); + $values = $redis -> zRange($key_raw, 0, -1, 1); $size = count($values); $template = 'view_zset'; break; diff --git a/application/models/redis_model.php b/application/models/redis_model.php index 9f382ba..133c983 100644 --- a/application/models/redis_model.php +++ b/application/models/redis_model.php @@ -207,7 +207,11 @@ public function scan_keys($prefix, $iterator, $need_sort = TRUE, $page_size = TR $keys = $this -> _redis -> keys($scan_prefix); $iterator = 0; } - + foreach($keys as $key => $value) { + if(!mb_check_encoding($value, 'UTF-8') || strpos($value, "%") !== false) { + $keys[$key]=strtr(urlencode($value), array('%3A'=>':', '%3a'=>':', ' %'=>'\x', ' '=>'\x20')); + } + } if ( $need_sort ) { sort($keys); } From 01f866b7f2e27724d4565b827552a6a42a7ba2d2 Mon Sep 17 00:00:00 2001 From: liu shiwei Date: Wed, 24 Apr 2024 14:31:00 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E8=AE=A9json=5Fencode=20=E8=BE=93?= =?UTF-8?q?=E5=87=BAutf8=E7=9A=84=E5=8E=9F=E5=A7=8B=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=EF=BC=8C=20=E8=80=8C=E9=9D=9E=E8=BE=93=E5=87=BA\uxxxx?= =?UTF-8?q?=E8=BF=99=E6=A0=B7=E7=9A=84=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/helpers/common_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php index 729aba5..eca905f 100644 --- a/application/helpers/common_helper.php +++ b/application/helpers/common_helper.php @@ -20,9 +20,9 @@ function show_message($result, $msg = '', $data = array()) header( 'Content-type: text/javascript; charset=UTF-8' ); if (isset( $_REQUEST['callback'] ) ) { - $response = htmlspecialchars( $_REQUEST['callback'] ).'('.json_encode( $ret_arr ).');'; + $response = htmlspecialchars( $_REQUEST['callback'] ).'('.json_encode( $ret_arr, JSON_UNESCAPED_UNICODE ).');'; } else { - $response = json_encode( $ret_arr ); + $response = json_encode( $ret_arr, JSON_UNESCAPED_UNICODE); } echo $response; exit; From 29066bbcce8de051a65cbe28fea743f703b144c2 Mon Sep 17 00:00:00 2001 From: spf Date: Wed, 2 Nov 2016 17:04:00 +0800 Subject: [PATCH 10/14] =?UTF-8?q?fix=EF=BC=9A=E9=80=82=E9=85=8Dphpredis3.0?= =?UTF-8?q?=E4=BB=A5=E5=90=8E=E7=9A=84=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/clear_idle_key.php | 2 +- application/controllers/delete.php | 6 +++--- application/controllers/edit.php | 4 ++-- application/controllers/export.php | 4 ++-- application/controllers/view.php | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/application/controllers/clear_idle_key.php b/application/controllers/clear_idle_key.php index 3f769a9..aec472f 100644 --- a/application/controllers/clear_idle_key.php +++ b/application/controllers/clear_idle_key.php @@ -86,7 +86,7 @@ public function clear_keys() foreach($redis_keys as $key) { $t = $redis -> object('idletime', $key); if ( $t >= $idle_time ) { - $redis -> delete($key); + $redis -> del($key); $affected += 1; } } diff --git a/application/controllers/delete.php b/application/controllers/delete.php index 57e0333..4fde138 100644 --- a/application/controllers/delete.php +++ b/application/controllers/delete.php @@ -52,7 +52,7 @@ private function _delete_tree($tree) $tree .= '*'; $keys = $redis -> keys($tree); foreach($keys as $key) { - $redis -> delete($key); + $redis -> del($key); } } @@ -62,7 +62,7 @@ private function _delete_key($type, $key) switch($type) { default: //如果传空,即是整key删除 case 'string': - $redis -> delete($key); + $redis -> del($key); break; @@ -98,7 +98,7 @@ private function _delete_key($type, $key) case 'zset': $value = get_arg('value'); if ( $value !== NULL ){ - $redis -> zDelete($key, $value); + $redis -> zRem($key, $value); } break; } diff --git a/application/controllers/edit.php b/application/controllers/edit.php index e11cdee..1e51733 100644 --- a/application/controllers/edit.php +++ b/application/controllers/edit.php @@ -133,7 +133,7 @@ private function _do_index() } elseif ( $type == 'list' ) { //list - $size = $redis -> lSize($key); + $size = $redis -> lLen($key); $index = get_post_arg('index', NULL, 'trim'); ($index === NULL) && ($index = ''); @@ -174,7 +174,7 @@ private function _do_index() if ( ( $value != $old_value ) || ( $score != $old_score ) ){ - $redis -> zDelete($key, $old_value); + $redis -> zRem($key, $old_value); $redis -> zAdd($key, $score, $value); } diff --git a/application/controllers/export.php b/application/controllers/export.php index 67aafb6..136ef2c 100644 --- a/application/controllers/export.php +++ b/application/controllers/export.php @@ -127,7 +127,7 @@ private function _export_redis($key) // List else if ($type == 'list') { - $size = $redis -> lSize($key); + $size = $redis -> lLen($key); $result = array(); for ($i = 0; $i < $size; $i++) { $result[] = 'RPUSH "' . addslashes($key) . '" "' . addslashes($redis -> lGet($key, $i)) . '"'; @@ -192,7 +192,7 @@ private function _export_json($key) // List else if ($type == 'list') { - $size = $redis -> lSize($key); + $size = $redis -> lLen($key); $value = array(); for ($i = 0; $i < $size; ++$i) { diff --git a/application/controllers/view.php b/application/controllers/view.php index 30278af..6c14168 100644 --- a/application/controllers/view.php +++ b/application/controllers/view.php @@ -60,7 +60,7 @@ public function index() break; case 'list': - $size = $redis -> lSize($key_raw); + $size = $redis -> lLen($key_raw); $values = $redis -> lRange($key_raw, 0, -1); $template = 'view_list'; break; From 60926607d80ada99b17c8b208b91d53727ecb60e Mon Sep 17 00:00:00 2001 From: "binyan.li" Date: Fri, 16 Dec 2016 16:59:18 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=AA=E8=AF=BB?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E9=80=82=E7=94=A8=E4=BA=8E=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/config/config.php | 25 +++++++++++++++++++++++ application/config/config_auth.php | 2 +- application/config/config_global.php | 4 ++++ application/core/MY_Controller.php | 30 ++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/application/config/config.php b/application/config/config.php index 32f34e9..24ab5e9 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -360,3 +360,28 @@ /* End of file config.php */ /* Location: ./application/config/config.php */ + + +//================== Readonly switch add by binyan.li +define('READONLY_SWITCH', TRUE); +//define('READONLY_SWITCH', FALSE); +$config['readonly'] = READONLY_SWITCH; +$config['deny_operater']= array( + 'none', +//== 下方为放行方法 +// 'delete', //删除键 +// 'rename', //修改键名 +// 'edit', //查看/修改键值 +// 'ttl', //存活时间查看/修改 +// 'save', //保存 +// 'import', //导入键值 +// 'clear_idle_key', +// 'export', //导出键值 +// 'idle', +// 'overview', //统计信息 +// 'info', //统计信息 +// 'view', //查看各类型数据(string/hash/set/zset/list) +// 'index', //首页 +// 'key', //列出键值 +); +//================== diff --git a/application/config/config_auth.php b/application/config/config_auth.php index ed05b54..edaac3b 100644 --- a/application/config/config_auth.php +++ b/application/config/config_auth.php @@ -21,7 +21,7 @@ /* * 验证码语言 en=英文 cn=中文 */ -$config['seccode_lang'] = 'en'; +$config['seccode_lang'] = 'cn'; /* * 验证码字数 默认为4, diff --git a/application/config/config_global.php b/application/config/config_global.php index b90e1cc..643be02 100644 --- a/application/config/config_global.php +++ b/application/config/config_global.php @@ -3,6 +3,10 @@ $config['project_name'] = 'RedisMyAdmin'; $config['version'] = '0.4.2'; +if( defined('READONLY_SWITCH') && READONLY_SWITCH==TRUE ){ + $config['project_name'].= '-只读开启'; +} + /** * PHP执行时间 * set_time_limit(xxx); diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index dfe50c7..b46c9d1 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -45,6 +45,36 @@ public function __construct(){ $this -> _auth_check(); } } + + //=================增加只读判断 add by binyan.li + if( config_item('readonly') ){ + $stopLabel= FALSE; + $deny_operater= config_item('deny_operater'); + if( is_array($deny_operater) && count($deny_operater)>0 ){ + if( in_array(get_arg('c'), $deny_operater) ){ + $stopLabel= TRUE; + //die("当前开启了只读功能,不允许进行此操作。"); + } + } else { + $stopLabel= TRUE; + //die("未定义禁止操作列表。"); + } + + if($stopLabel==TRUE){ + $key = get_arg('key'); + $tree = get_arg('tree'); + if ( ( $key !== NULL ) && ( $key !== '' ) ){ + $url = manager_site_url('view', 'index', 'key=' . urlencode($key)); + die($url); + + } elseif ( ( $tree !== NULL ) && ( $this -> is_post() ) ){ + $url = manager_site_url('index', 'overview'); + die($url); + } + die('抱歉,该操作不被允许!'); + } + } + //=================== /* * 服务器列表 From 5b4807d2e7c2c8e3de9dd446c654dd75b720e3a6 Mon Sep 17 00:00:00 2001 From: liu shiwei Date: Wed, 24 Apr 2024 16:24:19 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E6=97=B6=EF=BC=8C=20=E5=A6=82=E6=9E=9C=E6=9C=89auth?= =?UTF-8?q?=E8=A6=81=E5=81=9Aauth=E8=AE=A4=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/overview.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/controllers/overview.php b/application/controllers/overview.php index 909718e..2612671 100644 --- a/application/controllers/overview.php +++ b/application/controllers/overview.php @@ -57,6 +57,7 @@ private function _overview_all() $can_connect = FALSE; try { $can_connect = $redis -> connect($server['host'], $server['port'], 0.5); + if($server['auth']) $redis -> auth($server['auth']); } catch (Exception $e) { $can_connect = TRUE; } From 67734515f171f132a93c961af2cc5943065aa939 Mon Sep 17 00:00:00 2001 From: liu shiwei Date: Wed, 24 Apr 2024 16:30:38 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=9A=84=E6=AF=8F=E4=B8=AA=E5=BA=93?= =?UTF-8?q?=E7=9A=84key=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/views/index.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/application/views/index.php b/application/views/index.php index e3d34b0..0179c31 100644 --- a/application/views/index.php +++ b/application/views/index.php @@ -1,10 +1,17 @@ - +