mirror of
https://github.com/cytopia/devilbox.git
synced 2025-01-18 10:46:23 +00:00
Allow to delete keys in Redis via UI
This commit is contained in:
parent
e916c5100d
commit
8e038d403c
@ -1,5 +1,12 @@
|
||||
<?php require '../config.php'; ?>
|
||||
<?php loadClass('Helper')->authPage(); ?>
|
||||
<?php
|
||||
if (isset($_GET['redisdb'])) {
|
||||
|
||||
loadClass('Redis')->flushDB($_GET['redisdb']);
|
||||
loadClass('Helper')->redirect('/db_redis.php');
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@ -15,6 +22,27 @@
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<?php $databases = array_keys(loadClass('Redis')->getKeys()); ?>
|
||||
<?php if (count($databases)): ?>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<form class="form-inline">
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="redisdb">Redis DB</label>
|
||||
<select class="form-control" name="redisdb">
|
||||
<option value="" selected disabled>Select Redis DB</option>
|
||||
<?php foreach ($databases as $db): ?>
|
||||
<option value="<?php echo $db;?>"><?php echo $db;?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Flush database</button>
|
||||
</form>
|
||||
<br/>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
||||
@ -22,29 +50,43 @@
|
||||
<p>Redis container is not running.</p>
|
||||
<?php else: ?>
|
||||
<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 $db_name => $keys): ?>
|
||||
<tr class="table-info">
|
||||
<th colspan="3">
|
||||
<?php echo $db_name;?>
|
||||
<?php $redisKeys = loadClass('Redis')->getKeys(); ?>
|
||||
<?php if (count($redisKeys)): ?>
|
||||
<?php foreach ($redisKeys as $db_name => $keys): ?>
|
||||
<tr class="thead-inverse ">
|
||||
<th colspan="5">
|
||||
Database: <?php echo $db_name; ?>
|
||||
Items: <?php echo count($keys); ?>
|
||||
</th>
|
||||
</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 class="table-info">
|
||||
<tr>
|
||||
<th>DB</th>
|
||||
<th>Key</th>
|
||||
<th>Expires</th>
|
||||
<th>Type</th>
|
||||
<th>Value</th>
|
||||
</th>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php foreach ($keys as $key): ?>
|
||||
<tr>
|
||||
<td><?php echo $db_name;?></td>
|
||||
<td class="break-word" style="width:30%;"><?php echo $key['name'];?></td>
|
||||
<td><?php echo $key['ttl'];?>s</td>
|
||||
<td><?php echo $key['type'];?></td>
|
||||
<td class="break-word">
|
||||
<code>
|
||||
<?php echo htmlentities($key['val']);?>
|
||||
</code>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<p>No keys set.</p>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
|
@ -67,8 +67,6 @@ class Memcd extends BaseClass implements BaseInterface
|
||||
$this->_connect_errno = 3;
|
||||
return;
|
||||
}
|
||||
|
||||
$memcd->set('devilbox-version', $GLOBALS['DEVILBOX_VERSION'].' ('.$GLOBALS['DEVILBOX_DATE'].')');
|
||||
$this->_memcached = $memcd;
|
||||
} else {
|
||||
|
||||
|
@ -47,7 +47,6 @@ class Redis extends BaseClass implements BaseInterface
|
||||
if (array_key_exists('pass', $data)) {
|
||||
$redis->auth($data['pass']);
|
||||
}
|
||||
$redis->set('devilbox-version', $GLOBALS['DEVILBOX_VERSION'].' ('.$GLOBALS['DEVILBOX_DATE'].')');
|
||||
$this->_redis = $redis;
|
||||
}
|
||||
}
|
||||
@ -70,6 +69,17 @@ class Redis extends BaseClass implements BaseInterface
|
||||
* Select functions
|
||||
*
|
||||
*********************************************************************************/
|
||||
public function flushDB($db)
|
||||
{
|
||||
if ($this->_redis) {
|
||||
if ( !$this->_redis->select($db) ) {
|
||||
return FALSE;
|
||||
}
|
||||
return $this->_redis->flushDb();
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
public function getInfo()
|
||||
{
|
||||
@ -101,7 +111,35 @@ class Redis extends BaseClass implements BaseInterface
|
||||
$this->_redis->select($db);
|
||||
$keys = $this->_redis->keys('*');
|
||||
foreach ($keys as $key) {
|
||||
$store[$db][$key] = $this->_redis->get($key);
|
||||
|
||||
switch($this->_redis->type($key)) {
|
||||
case \Redis::REDIS_STRING:
|
||||
$dtype = 'string';
|
||||
break;
|
||||
case \Redis::REDIS_SET:
|
||||
$dtype = 'set';
|
||||
break;
|
||||
case \Redis::REDIS_LIST:
|
||||
$dtype = 'list';
|
||||
break;
|
||||
case \Redis::REDIS_ZSET:
|
||||
$dtype = 'zset';
|
||||
break;
|
||||
case \Redis::REDIS_HASH:
|
||||
$dtype = 'hash';
|
||||
break;
|
||||
case \Redis::REDIS_NOT_FOUND:
|
||||
$dtype = 'other';
|
||||
break;
|
||||
default:
|
||||
$dtype = 'unknown';
|
||||
}
|
||||
$store[$db][] = array(
|
||||
'name' => $key,
|
||||
'val' => $this->_redis->get($key),
|
||||
'type' => $dtype,
|
||||
'ttl' => $this->_redis->ttl($key)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user