From 4cc73d4476e2330fc8119e1a00a9b9a22de73801 Mon Sep 17 00:00:00 2001
From: yifangyou
Date: Thu, 1 Aug 2013 11:44:41 +0800
Subject: [PATCH] add ajax functions
2013-08-01 11:43:03
When redis reach 1000+ keys,phpRedisAdmin will cause brower slow.
When redis reach 6000+ keys,phpRedisAdmin will cause brower crash.
I modify phpRedisAdmin's the key tree,it will load from ajax by level.
It has some problems when one level's keys too many.
---
.DS_Store | Bin 0 -> 6148 bytes
README.markdown | 9 +++
images/waiting.gif | Bin 0 -> 781 bytes
index.php | 56 +++++-------------
js/index.js | 59 +++++++++++--------
keys.php | 141 +++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 202 insertions(+), 63 deletions(-)
create mode 100644 .DS_Store
create mode 100644 images/waiting.gif
mode change 100644 => 100755 index.php
mode change 100644 => 100755 js/index.js
create mode 100755 keys.php
diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..95459c0198bb85cda309c7aefdfcaa089c98066a
GIT binary patch
literal 6148
zcmeHK%}T>S5T0#oO;I5ip~uB@kyKl~cnGC}M`#SQg`UKp8JPVhvol%d%d(RN0M?oLO#l-B3{-)o8V;X`m>0StCGDvoGWm`nB;Guk
zcwy|VM3dtuG9bQP6#}>g7e-M0elOl643gBcURkMJ*{E(BDBFX65c%=E6VD<)xp2nu
z+zI@l=T0xBox15P>9|ulbMB^NoRM}fjzhEuI=UbD>G;a5FBS)fM-AR?XAQn+He0O*
zKentatD%_B#_rz!$yv|6&mJCg#UI11CS^zC5}wc~lyc`xqcDy}=odL9xG8MUUs#?j
z;X_%=@(GCnVt^P}p8Oh4SdYL0$n6#c!k(w8dRQ
z
z6d5S1M^p6w)35LU#Uy$n28e+_#Q>{xoo)w9(!F)1IMHi4>NTnm5tl1`PeDVrVvH57
dxQ;3X{ahG`w#Hl`dQj*`K+-@1G4QPnya6RjfZ_lE
literal 0
HcmV?d00001
diff --git a/README.markdown b/README.markdown
index a46270d..1e6fe3e 100644
--- a/README.markdown
+++ b/README.markdown
@@ -11,6 +11,15 @@ You can send comments, patches, questions
or to erik@dubbelboer.com.
+additional functions
+====================
+2013-08-01 11:43:03
+When redis reach 1000+ keys,phpRedisAdmin will cause brower slow.
+When redis reach 6000+ keys,phpRedisAdmin will cause brower crash.
+I modify phpRedisAdmin's the key tree,it will load from ajax by level.
+It has some problems when one level's keys too many.
+
+
Example
=======
diff --git a/images/waiting.gif b/images/waiting.gif
new file mode 100644
index 0000000000000000000000000000000000000000..c1c60d59673e62c0f7956fb3f31d5a0bc819dee9
GIT binary patch
literal 781
zcmZ?wbhEHblwgoxSj52a|Ns9p|IaWmFuZv2g29-9VI~lRfZ~5{Ki808XU70nBRvCV
zMv%}?7EUf8tpkz=X=h+|;@EZPpTQ~5)q5>opWQv*S);2jVczo<(=>j$Ivx->B6`}D
z@q%fowk2!+C+1fzCJ{Y?F+B3#&o16vZDM)dH*9mM3RYuXVaE14#Z3Picb7eFkvs~1T*XZM8Xo
z%R)3}dZ-&-i?Im|eO)xg)U7o(#$pmyS9<`>c7d5aRY2m1$k8v2-0TyU{#^RVD{J|r
zjj{pZ73&sv&CK^;Vd?XDVsKK&O1$}?u+&_wMM2uvxNc-^zO$j?j0aZ3oq>jj!VDKx
zlsLk25QpI_1SI;8pGY{FqBQ?h+GLNlQR{E4DLehPN|_T^fC$3O4b_x5!gCmxxe7pY
z6^lG`ez7n;XOfy4w6tNhXxG`W-48ZM%)#nrP=FZ2&E}A}QYo+6cYs|>X4NM3S<}|W
zoT>keys($server['filter']);
-
sort($keys);
-
$namespaces = array(); // Array to hold our top namespaces.
-
// Build an array of nested arrays containing all our namespaces and containing keys.
foreach ($keys as $key) {
- // Ignore keys that are to long (Redis supports keys that can be way to long to put in an url).
- if (strlen($key) > $config['maxkeylen']) {
- continue;
- }
-
$key = explode($config['seperator'], $key);
-
- // $d will be a reference to the current namespace.
- $d = &$namespaces;
-
- // We loop though all the namespaces for this key creating the array for each.
- // Each time updating $d to be a reference to the last namespace so we can create the next one in it.
- for ($i = 0; $i < (count($key) - 1); ++$i) {
- if (!isset($d[$key[$i]])) {
- $d[$key[$i]] = array();
- }
-
- $d = &$d[$key[$i]];
+ $k=$key[0];
+ unset($key);
+ if(!isset($namespaces[$k])){
+ $namespaces[$k]=0;
}
-
- // Nodes containing an item named __phpredisadmin__ are also a key, not just a directory.
- // This means that creating an actual key named __phpredisadmin__ will make this bug.
- $d[$key[count($key) - 1]] = array('__phpredisadmin__' => true);
-
- // Unset $d so we don't accidentally overwrite it somewhere else.
- unset($d);
+ $namespaces[$k]++;
}
-
-
-
+unset($keys);
// This is basically the same as the click code in index.js.
// Just build the url for the frame based on our own url.
if (count($_GET) == 0) {
@@ -65,8 +41,8 @@
// Recursive function used to print the namespaces.
function print_namespace($item, $name, $fullkey, $islast) {
- global $config, $server, $redis;
-
+ global $config, $server, $redis,$depth,$maxDepth;
+ $depth=count(explode($config['seperator'], $fullkey));
// Is this also a key and not just a namespace?
if (isset($item['__phpredisadmin__'])) {
// Unset it so we won't loop over it when printing this namespace.
@@ -117,17 +93,17 @@ function print_namespace($item, $name, $fullkey, $islast) {
// Does this namespace also contain subkeys?
if (count($item) > 0) {
?>
-
+
()
-
+
$childitem) {
// $fullkey will be empty on the first call.
- if ($fullkey === '') {
+ if (empty($fullkey)) {
$childfullkey = $childname;
} else {
$childfullkey = $fullkey.$config['seperator'].$childname;
@@ -135,7 +111,7 @@ function print_namespace($item, $name, $fullkey, $islast) {
print_namespace($childitem, $childname, $childfullkey, (--$l == 0));
}
-
+ }
?>
@@ -178,7 +154,7 @@ function print_namespace($item, $name, $fullkey, $islast) {
-
+
diff --git a/js/index.js b/js/index.js
old mode 100644
new mode 100755
index 58f374e..d4ad2cb
--- a/js/index.js
+++ b/js/index.js
@@ -36,26 +36,7 @@ $(function() {
});
- $('li.current').parents('li.folder').removeClass('collapsed');
-
- $('li.folder').click(function(e) {
- var t = $(this);
-
- if ((e.pageY >= t.offset().top) &&
- (e.pageY <= t.offset().top + t.children('div').height())) {
- e.stopPropagation();
- t.toggleClass('collapsed');
- }
- });
-
- $('a').click(function() {
- $('li.current').removeClass('current');
- });
-
- $('li a').click(function() {
- $(this).parent().addClass('current');
- });
-
+
$('#filter').focus(function() {
if ($(this).hasClass('info')) {
@@ -83,8 +64,40 @@ $(function() {
}
});
});
+ setupTree();
+
+});
+
+
+function setupTree(){
+ $('li.current').parents('li.folder').removeClass('collapsed');
+
+ $('li.folder').click(function(e) {
+ var t = $(this);
+ if(t.hasClass('collapsed')){
+ //$(this).html("");
+ $(this).ajaxStart(function(){
+ $(this).children('icon').append("");
+ });
+ $(this).load("keys.php?key="+$(this).attr("title"), function(){
+ setupTree();
+ });
+ }
+ if ((e.pageY >= t.offset().top) &&
+ (e.pageY <= t.offset().top + t.children('div').height())) {
+ //e.stopPropagation();
+ t.toggleClass('collapsed');
+ }
+ });
- $('.deltree').click(function(e) {
+ $('a').click(function() {
+ $('li.current').removeClass('current');
+ });
+
+ $('li a').click(function() {
+ $(this).parent().addClass('current');
+ });
+ $('.deltree').click(function(e) {
e.preventDefault();
if (confirm('Are you sure you want to delete this whole tree and all it\'s keys?')) {
@@ -98,5 +111,5 @@ $(function() {
});
}
});
-});
-
+
+}
diff --git a/keys.php b/keys.php
new file mode 100755
index 0000000..dd6447a
--- /dev/null
+++ b/keys.php
@@ -0,0 +1,141 @@
+keys($keyPath."*");
+
+sort($keys);
+$namespaces = array(); // Array to hold our top namespaces.
+
+// Build an array of nested arrays containing all our namespaces and containing keys.
+foreach ($keys as $key) {
+ // Ignore keys that are to long (Redis supports keys that can be way to long to put in an url).
+ if (strlen($key) > $config['maxkeylen']) {
+ continue;
+ }
+
+ $key = explode($config['seperator'], $key);
+
+ // $d will be a reference to the current namespace.
+ $d = &$namespaces;
+
+ // We loop though all the namespaces for this key creating the array for each.
+ // Each time updating $d to be a reference to the last namespace so we can create the next one in it.
+ for ($i = 0; $i < (count($key) - 1); ++$i) {
+ if (!isset($d[$key[$i]])) {
+ $d[$key[$i]] = array();
+ }
+
+ $d = &$d[$key[$i]];
+ }
+
+ // Nodes containing an item named __phpredisadmin__ are also a key, not just a directory.
+ // This means that creating an actual key named __phpredisadmin__ will make this bug.
+ $d[$key[count($key) - 1]] = array('__phpredisadmin__' => true);
+
+ // Unset $d so we don't accidentally overwrite it somewhere else.
+ unset($d);
+}
+
+
+// Recursive function used to print the namespaces.
+function print_namespace($item, $name, $fullkey, $islast) {
+ global $config, $server, $redis,$depth,$maxDepth,$keyPath;
+ $depth=count(explode($config['seperator'], $fullkey));
+
+ // Is this also a key and not just a namespace?
+ if (isset($item['__phpredisadmin__'])) {
+ // Unset it so we won't loop over it when printing this namespace.
+ unset($item['__phpredisadmin__']);
+
+ $type = $redis->type($fullkey);
+ $class = array();
+ $len = false;
+
+ if (isset($_GET['key']) && ($fullkey == $_GET['key'])) {
+ $class[] = 'current';
+ }
+ if ($islast) {
+ $class[] = 'last';
+ }
+
+ // Get the number of items in the key.
+ if (!isset($config['faster']) || !$config['faster']) {
+ switch ($type) {
+ case 'hash':
+ $len = $redis->hLen($fullkey);
+ break;
+
+ case 'list':
+ $len = $redis->lLen($fullkey);
+ break;
+
+ case 'set':
+ // This is currently the only way to do this, this can be slow since we need to retrieve all keys
+ $len = count($redis->sMembers($fullkey));
+ break;
+
+ case 'zset':
+ // This is currently the only way to do this, this can be slow since we need to retrieve all keys
+ $len = count($redis->zRange($fullkey, 0, -1));
+ break;
+ }
+ }
+
+
+ ?>
+