From 8e14009d3d85627caf2762a1a1fa14554acb6ba8 Mon Sep 17 00:00:00 2001 From: cytopia Date: Sun, 12 Aug 2018 10:26:51 +0200 Subject: [PATCH] Show Redis keys grouped by DB --- .devilbox/www/htdocs/db_redis.php | 18 +++++++++++---- .devilbox/www/include/lib/container/Redis.php | 22 ++++++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/.devilbox/www/htdocs/db_redis.php b/.devilbox/www/htdocs/db_redis.php index 18ffab4e..5c07cf92 100644 --- a/.devilbox/www/htdocs/db_redis.php +++ b/.devilbox/www/htdocs/db_redis.php @@ -24,16 +24,26 @@ + - getKeys() as $key => $value): ?> - - - + getKeys() as $db_name => $keys): ?> + + + $val): ?> + + + + + + +
DB Key Value
+ +
diff --git a/.devilbox/www/include/lib/container/Redis.php b/.devilbox/www/include/lib/container/Redis.php index 078bd322..e2f142b5 100644 --- a/.devilbox/www/include/lib/container/Redis.php +++ b/.devilbox/www/include/lib/container/Redis.php @@ -80,13 +80,29 @@ class Redis extends BaseClass implements BaseInterface } } + public function getDatabases() + { + $databases = array(); + + foreach ($this->getInfo() as $key => $val) { + if (preg_match('/db[0-9]+/', $key)) { + $databases[] = str_replace('db', '', $key); + } + } + return ($databases); + } + public function getKeys() { $store = array(); if ($this->_redis) { - $keys = $this->_redis->keys('*'); - foreach ($keys as $key) { - $store[$key] = $this->_redis->get($key); + $databases = $this->getDatabases(); + foreach ($databases as $db) { + $this->_redis->select($db); + $keys = $this->_redis->keys('*'); + foreach ($keys as $key) { + $store[$db][$key] = $this->_redis->get($key); + } } } return $store;