diff options
author | Helmut K. C. Tessarek <tessarek@evermeet.cx> | 2019-11-17 23:27:11 +0300 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2019-11-17 23:27:11 +0300 |
commit | 484714a25771e41b451bd2aaee068e5e0c07a0b5 (patch) | |
tree | f4f0de2b3fc57a287df639ac21713ee4017a464d | |
parent | 5e870a22a8dda82cc148656a6462305576b807d6 (diff) |
show number of keys in database drop-down list (#150)
also added an option to hide empty database
the option can be set for all databases or on a database level
the default is that empty database are shown
closes #149
-rw-r--r-- | includes/common.inc.php | 4 | ||||
-rw-r--r-- | includes/config.sample.inc.php | 3 | ||||
-rw-r--r-- | index.php | 26 |
3 files changed, 31 insertions, 2 deletions
diff --git a/includes/common.inc.php b/includes/common.inc.php index 367c539..c50a2f3 100644 --- a/includes/common.inc.php +++ b/includes/common.inc.php @@ -111,6 +111,10 @@ if (!isset($server['serialization'])) { } } +if (!isset($config['hideEmptyDBs'])) { + $config['hideEmptyDBs'] = false; +} + // Setup a connection to Redis. if(isset($server['scheme']) && $server['scheme'] === 'unix' && $server['path']) { $redis = new Predis\Client(array('scheme' => 'unix', 'path' => $server['path'])); diff --git a/includes/config.sample.inc.php b/includes/config.sample.inc.php index 10e043d..e24aa52 100644 --- a/includes/config.sample.inc.php +++ b/includes/config.sample.inc.php @@ -10,6 +10,7 @@ $config = array( 'filter' => '*', 'scheme' => 'tcp', // Optional. Connection scheme. 'tcp' - for TCP connection, 'unix' - for connection by unix domain socket 'path' => '', // Optional. Path to unix domain socket. Uses only if 'scheme' => 'unix'. Example: '/var/run/redis/redis.sock' + 'hide' => false, // Optional. Override global setting. Hide empty databases in the database list. // Optional Redis authentication. //'auth' => 'redispasswordhere' // Warning: The password is sent in plain-text to the Redis server. @@ -38,6 +39,8 @@ $config = array( 'seperator' => ':', + // Hide empty databases in the database list (global, valid for all servers unless set at server level) + 'hideEmptyDBs' => false, // Uncomment to show less information and make phpRedisAdmin fire less commands to the Redis server. Recommended for a really busy Redis server. //'faster' => true, @@ -137,9 +137,30 @@ if($redis) { } } + function getDbInfo($d, $info, $padding = '') { + global $config, $server; + $prefix = "database "; + $db = "db$d"; + + $dbHasData = array_key_exists("db$d", $info['Keyspace']); + + if (!$dbHasData && ((isset($server['hide']) && $server['hide']) || (!isset($server['hide']) && $config['hideEmptyDBs']))) { + return false; // we don't show empty dbs, so return false to tell the caller to continue the loop + } + + $dbinfo = sprintf("$prefix%'.-${padding}d", $d); + if ($dbHasData) { + $dbinfo = sprintf("%s (%d)", $dbinfo, $info['Keyspace'][$db]['keys']); + } + $dbinfo = str_replace('.', ' ', $dbinfo); // 2 spaces per character are needed to get the alignment right + + return $dbinfo; + } + } // if redis + // 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) { @@ -183,10 +204,11 @@ if (isset($server['databases'])) { $databases = $redis->config('GET', 'databases'); $databases = $databases['databases']; } +$info = $redis->info(); $len = strlen((string)($databases-1)); if ($databases > 1) { ?> <select id="database"> - <?php for ($d = 0; $d < $databases; ++$d) { ?> - <option value="<?php echo $d?>" <?php echo ($server['db'] == $d) ? 'selected="selected"' : ''?>>database <?php echo $d?></option> + <?php for ($d = 0; $d < $databases; ++$d) { if (($dbinfo=getDbInfo($d, $info, $len)) === false) continue; ?> + <option value="<?php echo $d?>" <?php echo ($server['db'] == $d) ? 'selected="selected"' : ''?>><?php echo "$dbinfo"; ?></option> <?php } ?> </select> <?php } ?> |