Show Redis keys grouped by DB

This commit is contained in:
cytopia 2018-08-12 10:26:51 +02:00
parent ed52e7e3d8
commit 8e14009d3d
No known key found for this signature in database
GPG Key ID: 6D56EDB8695128A2
2 changed files with 33 additions and 7 deletions

View File

@ -24,16 +24,26 @@
<table class="table table-striped ">
<thead class="thead-inverse ">
<tr>
<th>DB</th>
<th>Key</th>
<th>Value</th>
</th>
</thead>
<tbody>
<?php foreach (loadClass('Redis')->getKeys() as $key => $value): ?>
<tr>
<td><?php echo $key;?></td>
<td><?php print_r($value);?></td>
<?php foreach (loadClass('Redis')->getKeys() as $db_name => $keys): ?>
<tr class="table-info">
<th colspan="3">
<?php echo $db_name;?>
</th>
</tr>
<?php foreach ($keys as $key=> $val): ?>
<tr>
<td></td>
<td><?php echo $key;?></td>
<td><code><?php print_r($val);?></code></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>

View File

@ -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;