forked from erikdubbelboer/phpRedisAdmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.php
75 lines (56 loc) · 2.05 KB
/
delete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
if (!isset($_POST['post'])) {
die('Javascript needs to be enabled for you to delete keys.');
}
require_once 'includes/common.inc.php';
global $redis;
global $server;
if (isset($_GET['key'])) {
// String
if (!isset($_GET['type']) || ($_GET['type'] == 'string')) {
// Delete the whole key.
$redis->del($_GET['key']);
}
// Hash
else if (($_GET['type'] == 'hash') && isset($_GET['hkey'])) {
// Delete only the field in the hash.
$redis->hDel($_GET['key'], $_GET['hkey']);
}
// List
else if (($_GET['type'] == 'list') && isset($_GET['index'])) {
// Lists don't have simple delete operations.
// You can only remove something based on a value so we set the value at the index to some random value we hope doesn't occur elsewhere in the list.
$value = str_rand(69);
// This code assumes $value is not present in the list. To make sure of this we would need to check the whole list and place a Watch on it to make sure the list isn't modified in between.
$redis->lSet($_GET['key'], $_GET['index'], $value);
$redis->lRem($_GET['key'], 1, $value);
}
// Set
else if (($_GET['type'] == 'set') && isset($_GET['value'])) {
// Removing members from a set can only be done by supplying the member.
$redis->sRem($_GET['key'], $_GET['value']);
}
// ZSet
else if (($_GET['type'] == 'zset') && isset($_GET['value'])) {
// Removing members from a zset can only be done by supplying the value.
$redis->zRem($_GET['key'], $_GET['value']);
}
die('?view&s='.$server['id'].'&d='.$server['db'].'&key='.urlencode($_GET['key']));
}
if (isset($_GET['tree'])) {
$keys = $redis->keys($_GET['tree'].'*');
foreach ($keys as $key) {
$redis->del($key);
}
die('?view&s='.$server['id'].'&d='.$server['db']);
}
if (isset($_GET['batch_del'])) {
if (empty($_POST['selected_keys'])) {
die('No keys to delete');
}
$keys = json_decode($_POST['selected_keys']);
foreach ($keys as $key) {
$redis->del($key);
}
die('?view&s=' . $server['id'] . '&d=' . $server['db'] . '&key=' . urlencode($keys[0]));
}