From 484714a25771e41b451bd2aaee068e5e0c07a0b5 Mon Sep 17 00:00:00 2001 From: "Helmut K. C. Tessarek" Date: Sun, 17 Nov 2019 15:27:11 -0500 Subject: 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 --- includes/common.inc.php | 4 ++++ includes/config.sample.inc.php | 3 +++ 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, diff --git a/index.php b/index.php index cd96cd3..fc271b6 100644 --- a/index.php +++ b/index.php @@ -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) { ?> -- cgit v1.2.3