mirror of
https://github.com/cytopia/devilbox.git
synced 2025-01-18 18:56:25 +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 require '../config.php'; ?>
|
||||||
<?php loadClass('Helper')->authPage(); ?>
|
<?php loadClass('Helper')->authPage(); ?>
|
||||||
|
<?php
|
||||||
|
if (isset($_GET['redisdb'])) {
|
||||||
|
|
||||||
|
loadClass('Redis')->flushDB($_GET['redisdb']);
|
||||||
|
loadClass('Helper')->redirect('/db_redis.php');
|
||||||
|
}
|
||||||
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
@ -15,6 +22,27 @@
|
|||||||
<br/>
|
<br/>
|
||||||
<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="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
|
|
||||||
@ -22,29 +50,43 @@
|
|||||||
<p>Redis container is not running.</p>
|
<p>Redis container is not running.</p>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<table class="table table-striped ">
|
<table class="table table-striped ">
|
||||||
<thead class="thead-inverse ">
|
|
||||||
<tr>
|
|
||||||
<th>DB</th>
|
|
||||||
<th>Key</th>
|
|
||||||
<th>Value</th>
|
|
||||||
</th>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach (loadClass('Redis')->getKeys() as $db_name => $keys): ?>
|
<?php $redisKeys = loadClass('Redis')->getKeys(); ?>
|
||||||
<tr class="table-info">
|
<?php if (count($redisKeys)): ?>
|
||||||
<th colspan="3">
|
<?php foreach ($redisKeys as $db_name => $keys): ?>
|
||||||
<?php echo $db_name;?>
|
<tr class="thead-inverse ">
|
||||||
|
<th colspan="5">
|
||||||
|
Database: <?php echo $db_name; ?>
|
||||||
|
Items: <?php echo count($keys); ?>
|
||||||
|
</th>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
<tr class="table-info">
|
||||||
<?php foreach ($keys as $key=> $val): ?>
|
<tr>
|
||||||
<tr>
|
<th>DB</th>
|
||||||
<td></td>
|
<th>Key</th>
|
||||||
<td><?php echo $key;?></td>
|
<th>Expires</th>
|
||||||
<td><code><?php print_r($val);?></code></td>
|
<th>Type</th>
|
||||||
|
<th>Value</th>
|
||||||
|
</th>
|
||||||
</tr>
|
</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>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
@ -67,8 +67,6 @@ class Memcd extends BaseClass implements BaseInterface
|
|||||||
$this->_connect_errno = 3;
|
$this->_connect_errno = 3;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$memcd->set('devilbox-version', $GLOBALS['DEVILBOX_VERSION'].' ('.$GLOBALS['DEVILBOX_DATE'].')');
|
|
||||||
$this->_memcached = $memcd;
|
$this->_memcached = $memcd;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -47,7 +47,6 @@ class Redis extends BaseClass implements BaseInterface
|
|||||||
if (array_key_exists('pass', $data)) {
|
if (array_key_exists('pass', $data)) {
|
||||||
$redis->auth($data['pass']);
|
$redis->auth($data['pass']);
|
||||||
}
|
}
|
||||||
$redis->set('devilbox-version', $GLOBALS['DEVILBOX_VERSION'].' ('.$GLOBALS['DEVILBOX_DATE'].')');
|
|
||||||
$this->_redis = $redis;
|
$this->_redis = $redis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,6 +69,17 @@ class Redis extends BaseClass implements BaseInterface
|
|||||||
* Select functions
|
* 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()
|
public function getInfo()
|
||||||
{
|
{
|
||||||
@ -101,7 +111,35 @@ class Redis extends BaseClass implements BaseInterface
|
|||||||
$this->_redis->select($db);
|
$this->_redis->select($db);
|
||||||
$keys = $this->_redis->keys('*');
|
$keys = $this->_redis->keys('*');
|
||||||
foreach ($keys as $key) {
|
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