From ce40bb516477347003f9f9d94ad6bfad454dc6b2 Mon Sep 17 00:00:00 2001 From: aborn Date: Fri, 7 Mar 2014 14:31:46 +0800 Subject: [PATCH 1/2] add redisadmin.php --- redisadmin.php | 204 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 redisadmin.php diff --git a/redisadmin.php b/redisadmin.php new file mode 100644 index 0000000..98418ac --- /dev/null +++ b/redisadmin.php @@ -0,0 +1,204 @@ +keys($server['filter']); +} catch (Exception $e) { + die('ERROR: Can\'t connect to Redis'); +} + +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($server['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); +} + + + +// 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) { + $iframe = 'overview.php'; +} else { + $iframe = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1); + + if (strpos($iframe, '&') !== false) { + $iframe = substr_replace($iframe, '.php?', strpos($iframe, '&'), 1); + } else { + $iframe .= '.php'; + } +} + + + + + + +// Recursive function used to print the namespaces. +function print_namespace($item, $name, $fullkey, $islast) { + global $config, $server, $redis; + + // 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; + } + } + + + ?> + > + () + + 0) { + ?> +
  • +
     () + [X] +
      + $childitem) { + // $fullkey will be empty on the first call. + if ($fullkey === '') { + $childfullkey = $childname; + } else { + $childfullkey = $fullkey.$server['seperator'].$childname; + } + + print_namespace($childitem, $childname, $childfullkey, (--$l == 0)); + } + + ?> +
    +
  • + + + From 8409ee1dccea7d8d6076b8a7b9d6e978aa1fd591 Mon Sep 17 00:00:00 2001 From: aborn Date: Fri, 7 Mar 2014 14:35:27 +0800 Subject: [PATCH 2/2] add config.inc.php in include --- .gitignore | 2 +- includes/config.inc.php | 66 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 includes/config.inc.php diff --git a/.gitignore b/.gitignore index daf3eea..df9e117 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -config.inc.php +# config.inc.php *.phar vendor diff --git a/includes/config.inc.php b/includes/config.inc.php new file mode 100644 index 0000000..818479c --- /dev/null +++ b/includes/config.inc.php @@ -0,0 +1,66 @@ + array( + array( + 'name' => 'local db 0', // Optional name. + 'host' => '127.0.0.1', + 'port' => 6379, + 'filter' => '*', + + // Optional Redis authentication. + //'auth' => 'redispasswordhere' // Warning: The password is sent in plain-text to the Redis server. + ), + + /*array( + 'host' => 'localhost', + 'port' => 6380 + ),*/ + + array( + 'name' => 'local db 1', + 'host' => 'localhost', + 'port' => 6379, + 'db' => 1, // Optional database number, see http://redis.io/commands/select + 'filter' => '*', // Show only parts of database for speed or security reasons + 'seperator' => '/', // Use a different seperator on this database + 'flush' => false // Set to true to enable the flushdb button for this instance. + ), + + array( + 'name' => '105 db 0', + 'host' => '10.0.0.105', + 'port' => 6379, + 'db' => 0, + 'flush' => true) + + ), + 'seperator' => ':', + + + // Uncomment to show less information and make phpRedisAdmin fire less commands to the Redis server. Recommended for a really busy Redis server. + //'faster' => true, + + + // Uncomment to enable HTTP authentication + /*'login' => array( + // Username => Password + // Multiple combinations can be used + 'admin' => array( + 'password' => 'adminpassword', + ), + 'guest' => array( + 'password' => '', + 'servers' => array(1) // Optional list of servers this user can access. + ) + ),*/ + + + // You can ignore settings below this point. + + 'maxkeylen' => 100, + 'count_elements_page' => 100 +); + +?>