Skip to content

Commit f419e7f

Browse files
1 parent 5c91646 commit f419e7f

File tree

12 files changed

+125
-70
lines changed

12 files changed

+125
-70
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "erik-dubbelboer/php-redis-admin",
33
"description": "Simple web interface to manage Redis databases.",
4-
"version": "1.1.2",
4+
"version": "1.2.0",
55
"license": "CC-BY-ND",
66
"homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin",
77
"authors": [
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"predis/predis": "0.8.*"
16+
"predis/predis": "1.0.1"
1717
},
1818
"minimum-stability": "stable",
1919
"target-dir": "ErikDubbelboer/phpRedisAdmin"

composer.lock

Lines changed: 20 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

delete.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
}
4747

4848

49-
die('?view&s='.$server['id'].'&key='.urlencode($_GET['key']));
49+
die('?view&s='.$server['id'].'&d='.$server['db'].'&key='.urlencode($_GET['key']));
5050
}
5151

5252

@@ -57,7 +57,7 @@
5757
$redis->del($key);
5858
}
5959

60-
die('?view&s='.$server['id']);
60+
die('?view&s='.$server['id'].'&d='.$server['db']);
6161
}
6262

6363
?>

edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686

8787
?>
8888
<script>
89-
top.location.href = top.location.pathname+'?view&s=<?php echo $server['id']?>&key=<?php echo urlencode($_POST['key'])?>';
89+
top.location.href = top.location.pathname+'?view&s=<?php echo $server['id']?>&d=<?php echo $server['db']?>&key=<?php echo urlencode($_POST['key'])?>';
9090
</script>
9191
<?php
9292

import.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
?>
7575
<script>
76-
top.location.href = top.location.pathname+'?overview&s=<?php echo $server['id']?>';
76+
top.location.href = top.location.pathname+'?overview&s=<?php echo $server['id']?>&d=<?php echo $server['db']?>';
7777
</script>
7878
<?php
7979

includes/common.inc.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
}
4141

4242

43-
44-
4543
if (isset($login['servers'])) {
4644
$i = current($login['servers']);
4745
} else {
@@ -53,8 +51,8 @@
5351
$i = $_GET['s'];
5452
}
5553

56-
$server = $config['servers'][$i];
57-
$server['id'] = $i;
54+
$server = $config['servers'][$i];
55+
$server['id'] = $i;
5856
$server['charset'] = isset($server['charset']) && $server['charset'] ? $server['charset'] : false;
5957

6058

@@ -75,9 +73,14 @@
7573

7674

7775
if (!isset($server['db'])) {
78-
$server['db'] = 0;
76+
if (isset($_GET['d']) && is_numeric($_GET['d'])) {
77+
$server['db'] = $_GET['d'];
78+
} else {
79+
$server['db'] = 0;
80+
}
7981
}
8082

83+
8184
if (!isset($server['filter'])) {
8285
$server['filter'] = '*';
8386
}
@@ -94,6 +97,14 @@
9497
$server['seperator'] = $config['seperator'];
9598
}
9699

100+
if (!isset($server['keys'])) {
101+
$server['keys'] = $config['keys'];
102+
}
103+
104+
if (!isset($server['scansize'])) {
105+
$server['scansize'] = $config['scansize'];
106+
}
107+
97108
// Setup a connection to Redis.
98109
$redis = !$server['port'] ? new Predis\Client($server['host']) : new Predis\Client('tcp://'.$server['host'].':'.$server['port']);
99110
try {

includes/config.sample.inc.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
'port' => 6379,
2525
'db' => 1, // Optional database number, see http://redis.io/commands/select
2626
'filter' => 'something:*', // Show only parts of database for speed or security reasons.
27-
'seperator' => '/', // Use a different seperator on this database.
27+
'seperator' => '/', // Use a different seperator on this database (default uses config default).
2828
'flush' => false, // Set to true to enable the flushdb button for this instance.
2929
'charset' => 'cp1251', // Keys and values are stored in redis using this encoding (default utf-8).
30+
'keys' => false, // Use the old KEYS command instead of SCAN to fetch all keys for this server (default uses config default).
31+
'scansize' => 1000 // How many entries to fetch using each SCAN command for this server (default uses config default).
3032
),*/
3133
),
3234

@@ -55,7 +57,14 @@
5557
// You can ignore settings below this point.
5658

5759
'maxkeylen' => 100,
58-
'count_elements_page' => 100
60+
'count_elements_page' => 100,
61+
62+
63+
// Use the old KEYS command instead of SCAN to fetch all keys.
64+
'keys' => false,
65+
66+
// How many entries to fetch using each SCAN command.
67+
'scansize' => 1000
5968
);
6069

6170
?>

index.php

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,23 @@
44

55
if($redis) {
66

7-
$keys = $redis->keys($server['filter']);
7+
if (!empty($server['keys'])) {
8+
$keys = $redis->keys($server['filter']);
9+
} else {
10+
$next = 0;
11+
$keys = array();
12+
13+
while (true) {
14+
$r = $redis->scan($next, 'MATCH', $server['filter'], 'COUNT', $server['scansize']);
15+
16+
$next = $r[0];
17+
$keys = array_merge($keys, $r[1]);
18+
19+
if ($next == 0) {
20+
break;
21+
}
22+
}
23+
}
824

925
sort($keys);
1026

@@ -83,7 +99,7 @@ function print_namespace($item, $name, $fullkey, $islast) {
8399

84100
?>
85101
<li<?php echo empty($class) ? '' : ' class="'.implode(' ', $class).'"'?>>
86-
<a href="http://github.com/?view&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>&amp;key=<?php echo urlencode($fullkey)?>"><?php echo format_html($name)?><?php if ($len !== false) { ?><span class="info">(<?php echo $len?>)</span><?php } ?></a>
102+
<a href="http://github.com/?view&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>&amp;d=<?php echo $server['db']?>&amp;key=<?php echo urlencode($fullkey)?>"><?php echo format_html($name)?><?php if ($len !== false) { ?><span class="info">(<?php echo $len?>)</span><?php } ?></a>
87103
</li>
88104
<?php
89105
}
@@ -93,7 +109,7 @@ function print_namespace($item, $name, $fullkey, $islast) {
93109
?>
94110
<li class="folder<?php echo ($fullkey === '') ? '' : ' collapsed'?><?php echo $islast ? ' last' : ''?>">
95111
<div class="icon"><?php echo format_html($name)?>&nbsp;<span class="info">(<?php echo count($item)?>)</span>
96-
<?php if ($fullkey !== '') { ?><a href="http://github.com/delete.php?s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>&amp;tree=<?php echo urlencode($fullkey)?>:" class="deltree"><img src="http://github.com/images/delete.png" width="10" height="10" title="Delete tree" alt="[X]"></a><?php } ?>
112+
<?php if ($fullkey !== '') { ?><a href="http://github.com/delete.php?s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>&amp;d=<?php echo $server['db']?>&amp;tree=<?php echo urlencode($fullkey)?>:" class="deltree"><img src="http://github.com/images/delete.png" width="10" height="10" title="Delete tree" alt="[X]"></a><?php } ?>
97113
</div><ul>
98114
<?php
99115

@@ -144,32 +160,43 @@ function print_namespace($item, $name, $fullkey, $islast) {
144160
?>
145161
<div id="sidebar">
146162

147-
<h1 class="logo"><a href="http://github.com/?overview&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>">phpRedisAdmin</a></h1>
163+
<h1 class="logo"><a href="http://github.com/?overview&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>&amp;d=<?php echo $server['db']?>">phpRedisAdmin</a></h1>
148164

149165
<p>
150166
<select id="server">
151167
<?php foreach ($config['servers'] as $i => $srv) { ?>
152168
<option value="<?php echo $i?>" <?php echo ($server['id'] == $i) ? 'selected="selected"' : ''?>><?php echo isset($srv['name']) ? format_html($srv['name']) : $srv['host'].':'.$srv['port']?></option>
153169
<?php } ?>
154170
</select>
155-
</p>
156171

157-
<?php if($redis): ?>
172+
<?php if($redis) { ?>
173+
174+
<?php
175+
$databases = $redis->config('GET', 'databases');
176+
$databases = $databases['databases'];
177+
if ($databases > 1) { ?>
178+
<select id="database">
179+
<?php for ($d = 0; $d < $databases; ++$d) { ?>
180+
<option value="<?php echo $d?>" <?php echo ($server['db'] == $d) ? 'selected="selected"' : ''?>>database <?php echo $d?></option>
181+
<?php } ?>
182+
</select>
183+
<?php } ?>
184+
</p>
158185

159186
<p>
160187
<?php if (isset($login)) { ?>
161188
<a href="logout.php"><img src="images/logout.png" width="16" height="16" title="Logout" alt="[L]"></a>
162189
<?php } ?>
163-
<a href="http://github.com/?info&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>"><img src="http://github.com/images/info.png" width="16" height="16" title="Info" alt="[I]"></a>
164-
<a href="http://github.com/?export&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>"><img src="http://github.com/images/export.png" width="16" height="16" title="Export" alt="[E]"></a>
165-
<a href="http://github.com/?import&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>"><img src="http://github.com/images/import.png" width="16" height="16" title="Import" alt="[I]"></a>
190+
<a href="http://github.com/?info&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>&amp;d=<?php echo $server['db']?>"><img src="http://github.com/images/info.png" width="16" height="16" title="Info" alt="[I]"></a>
191+
<a href="http://github.com/?export&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>&amp;d=<?php echo $server['db']?>"><img src="http://github.com/images/export.png" width="16" height="16" title="Export" alt="[E]"></a>
192+
<a href="http://github.com/?import&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>&amp;d=<?php echo $server['db']?>"><img src="http://github.com/images/import.png" width="16" height="16" title="Import" alt="[I]"></a>
166193
<?php if (isset($server['flush']) && $server['flush']) { ?>
167-
<a href="http://github.com/?flush&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>" id="flush"><img src="http://github.com/images/flush.png" width="16" height="16" title="Flush" alt="[F]"></a>
194+
<a href="http://github.com/?flush&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>&amp;d=<?php echo $server['db']?>" id="flush"><img src="http://github.com/images/flush.png" width="16" height="16" title="Flush" alt="[F]"></a>
168195
<?php } ?>
169196
</p>
170197

171198
<p>
172-
<a href="http://github.com/?edit&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>" class="add">Add another key</a>
199+
<a href="http://github.com/?edit&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>&amp;d=<?php echo $server['db']?>" class="add">Add another key</a>
173200
</p>
174201

175202
<p>
@@ -187,9 +214,10 @@ function print_namespace($item, $name, $fullkey, $islast) {
187214
</ul>
188215
</div><!-- #keys -->
189216

190-
<?php else: ?>
217+
<?php } else { ?>
218+
</p>
191219
<div style="color:red">Can't connect to this server</div>
192-
<?php endif; ?>
220+
<?php } ?>
193221

194222
<div id="frame">
195223
<iframe src="<?php echo format_html($iframe)?>" id="iframe" frameborder="0" scrolling="0"></iframe>

info.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
<?php if (method_exists($redis, 'resetStat')) { ?>
3333
<p>
34-
<a href="http://github.com/?reset&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>" class="reset">Reset usage statistics</a>
34+
<a href="http://github.com/?reset&amp;s=%3Cspan%20class="pl-ent"><?php echo $server['id']?>&amp;d=<?php echo $server['db']?>" class="reset">Reset usage statistics</a>
3535
</p>
3636
<?php } ?>
3737

js/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ $(function() {
4949
});
5050

5151

52+
$('#database').change(function(e) {
53+
if (location.href.indexOf('?') == -1) {
54+
location.href = location.href+'?d='+e.target.value;
55+
} else if (location.href.indexOf('&d=') == -1) {
56+
location.href = location.href+'&d='+e.target.value;
57+
} else {
58+
location.href = location.href.replace(/d=[0-9]*/, 'd='+e.target.value);
59+
}
60+
});
61+
62+
5263
$('li.current').parents('li.folder').removeClass('collapsed');
5364

5465
$('li.folder').click(function(e) {
@@ -71,7 +82,7 @@ $(function() {
7182

7283
$('#btn_server_filter').click(function() {
7384
var filter = $('#server_filter').val();
74-
location.href = top.location.pathname + '?overview&s=' + $('#server').val() + '&filter=' + filter;
85+
location.href = top.location.pathname + '?overview&s=' + $('#server').val() + '&d=' + ($('#database').val() || '') + '&filter=' + filter;
7586
});
7687

7788
$('#server_filter').keydown(function(e){

0 commit comments

Comments
 (0)