|
34 | 34 | die('ERROR: could not encode value');
|
35 | 35 | }
|
36 | 36 |
|
37 |
| - // String |
38 |
| - if ($_POST['type'] == 'string') { |
39 |
| - $redis->set($key, $value); |
40 |
| - } |
41 |
| - |
42 |
| - // Hash |
43 |
| - else if (($_POST['type'] == 'hash') && isset($_POST['hkey'])) { |
44 |
| - if (strlen($_POST['hkey']) > $config['maxkeylen']) { |
45 |
| - die('ERROR: Your hash key is to long (max length is '.$config['maxkeylen'].')'); |
| 37 | + try { |
| 38 | + // String |
| 39 | + if ($_POST['type'] == 'string') { |
| 40 | + $redis->set($key, $value); |
46 | 41 | }
|
47 | 42 |
|
48 |
| - if ($edit && !$redis->hExists($key, input_convert($_POST['hkey']))) { |
49 |
| - $redis->hDel($key, input_convert($_GET['hkey'])); |
| 43 | + // Hash |
| 44 | + else if (($_POST['type'] == 'hash') && isset($_POST['hkey'])) { |
| 45 | + if (strlen($_POST['hkey']) > $config['maxkeylen']) { |
| 46 | + die('ERROR: Your hash key is to long (max length is '.$config['maxkeylen'].')'); |
| 47 | + } |
| 48 | + |
| 49 | + if ($edit && !$redis->hExists($key, input_convert($_POST['hkey']))) { |
| 50 | + $redis->hDel($key, input_convert($_GET['hkey'])); |
| 51 | + } |
| 52 | + |
| 53 | + $redis->hSet($key, input_convert($_POST['hkey']), $value); |
50 | 54 | }
|
51 | 55 |
|
52 |
| - $redis->hSet($key, input_convert($_POST['hkey']), $value); |
53 |
| - } |
| 56 | + // List |
| 57 | + else if (($_POST['type'] == 'list') && isset($_POST['index'])) { |
| 58 | + $size = $redis->lLen($key); |
| 59 | + |
| 60 | + if (($_POST['index'] == '') || |
| 61 | + ($_POST['index'] == $size)) { |
| 62 | + // Push it at the end |
| 63 | + $redis->rPush($key, $value); |
| 64 | + } else if ($_POST['index'] == -1) { |
| 65 | + // Push it at the start |
| 66 | + $redis->lPush($key, $value); |
| 67 | + } else if (($_POST['index'] >= 0) && |
| 68 | + ($_POST['index'] < $size)) { |
| 69 | + // Overwrite an index |
| 70 | + $redis->lSet($key, input_convert($_POST['index']), $value); |
| 71 | + } else { |
| 72 | + die('ERROR: Out of bounds index'); |
| 73 | + } |
| 74 | + } |
54 | 75 |
|
55 |
| - // List |
56 |
| - else if (($_POST['type'] == 'list') && isset($_POST['index'])) { |
57 |
| - $size = $redis->lLen($key); |
58 |
| - |
59 |
| - if (($_POST['index'] == '') || |
60 |
| - ($_POST['index'] == $size)) { |
61 |
| - // Push it at the end |
62 |
| - $redis->rPush($key, $value); |
63 |
| - } else if ($_POST['index'] == -1) { |
64 |
| - // Push it at the start |
65 |
| - $redis->lPush($key, $value); |
66 |
| - } else if (($_POST['index'] >= 0) && |
67 |
| - ($_POST['index'] < $size)) { |
68 |
| - // Overwrite an index |
69 |
| - $redis->lSet($key, input_convert($_POST['index']), $value); |
70 |
| - } else { |
71 |
| - die('ERROR: Out of bounds index'); |
| 76 | + // Set |
| 77 | + else if ($_POST['type'] == 'set') { |
| 78 | + if ($_POST['value'] != $_POST['oldvalue']) { |
| 79 | + // The only way to edit a Set value is to add it and remove the old value. |
| 80 | + $redis->sRem($key, encodeOrDecode('save', $key, input_convert($_POST['oldvalue']))); |
| 81 | + $redis->sAdd($key, $value); |
| 82 | + } |
72 | 83 | }
|
73 |
| - } |
74 | 84 |
|
75 |
| - // Set |
76 |
| - else if ($_POST['type'] == 'set') { |
77 |
| - if ($_POST['value'] != $_POST['oldvalue']) { |
78 |
| - // The only way to edit a Set value is to add it and remove the old value. |
79 |
| - $redis->sRem($key, encodeOrDecode('save', $key, input_convert($_POST['oldvalue']))); |
80 |
| - $redis->sAdd($key, $value); |
| 85 | + // ZSet |
| 86 | + else if (($_POST['type'] == 'zset') && isset($_POST['score']) && is_numeric($_POST['score'])) { |
| 87 | + // The only way to edit a ZSet value is to add it and remove the old value. |
| 88 | + $redis->zRem($key, encodeOrDecode('save', $key, input_convert($_POST['oldvalue']))); |
| 89 | + $redis->zAdd($key, input_convert($_POST['score']), $value); |
81 | 90 | }
|
82 |
| - } |
83 | 91 |
|
84 |
| - // ZSet |
85 |
| - else if (($_POST['type'] == 'zset') && isset($_POST['score']) && is_numeric($_POST['score'])) { |
86 |
| - // The only way to edit a ZSet value is to add it and remove the old value. |
87 |
| - $redis->zRem($key, encodeOrDecode('save', $key, input_convert($_POST['oldvalue']))); |
88 |
| - $redis->zAdd($key, input_convert($_POST['score']), $value); |
89 |
| - } |
90 | 92 |
|
91 | 93 |
|
| 94 | + // Refresh the top so the key tree is updated. |
| 95 | + require 'includes/header.inc.php'; |
92 | 96 |
|
93 |
| - // Refresh the top so the key tree is updated. |
94 |
| - require 'includes/header.inc.php'; |
| 97 | + ?> |
| 98 | + <script> |
| 99 | + top.location.href = top.location.pathname+'?view&s=<?php echo $server['id']?>&d=<?php echo $server['db']?>&key=<?php echo urlencode($_POST['key'])?>'; |
| 100 | + </script> |
| 101 | + <?php |
95 | 102 |
|
96 |
| - ?> |
97 |
| - <script> |
98 |
| - top.location.href = top.location.pathname+'?view&s=<?php echo $server['id']?>&d=<?php echo $server['db']?>&key=<?php echo urlencode($_POST['key'])?>'; |
99 |
| - </script> |
100 |
| - <?php |
| 103 | + require 'includes/footer.inc.php'; |
| 104 | + } catch (\Predis\Response\ServerException $th) { |
| 105 | + require 'includes/header.inc.php'; |
| 106 | + ?> |
| 107 | + <div class="exception"> |
| 108 | + <h3><?php echo $th->getMessage() ?></h3> |
| 109 | + </div> |
| 110 | + <?php |
| 111 | + require 'includes/footer.inc.php'; |
| 112 | + } |
101 | 113 |
|
102 |
| - require 'includes/footer.inc.php'; |
103 | 114 | die;
|
104 | 115 | }
|
105 | 116 |
|
|
0 commit comments