Permalink
Browse files

Now usable without php module.

- Changed phpredis to predis.
  • Loading branch information...
1 parent 9fcb29d commit 306b73dfb8e13d2a9f1c2da1c7f7bc8ddf7777ea @erikdubbelboer committed Aug 19, 2012
Showing with 27 additions and 75 deletions.
  1. +3 −0 .gitmodules
  2. +1 −3 README.markdown
  3. +2 −27 common.inc.php
  4. +4 −4 delete.php
  5. +3 −3 edit.php
  6. +6 −18 export.php
  7. +3 −9 index.php
  8. +1 −1 info.php
  9. +1 −7 overview.php
  10. +1 −0 predis
  11. +2 −3 view.php
View
@@ -0,0 +1,3 @@
+[submodule "predis"]
+ path = predis
+ url = git://github.com/nrk/predis.git
View
@@ -9,14 +9,12 @@ You can send comments, patches, questions [here on github](https://github.com/Er
Example
=======
-You can find an example database at [http://dubbelboer.com/phpRedisAdmin/](http://dubbelboer.com/phpRedisAdmin/?view&key=example:hash)
+You can find an example database at [http://dubbelboer.com/phpRedisAdmin/](http://dubbelboer.com/phpRedisAdmin/)
Installing/Configuring
======================
-You will need [phpredis](https://github.com/nicolasff/phpredis). See phpredis for install instructions.
-
You will need to edit config.inc.php with your redis information. You might also want to uncomment and change the login information in config.inc.php.
View
@@ -1,11 +1,5 @@
<?php
-if (!class_exists('Redis')) {
- die('ERROR: phpredis is required. You can find phpredis at <a href="https://github.com/nicolasff/phpredis">https://github.com/nicolasff/phpredis</a>');
-}
-
-
-
// Undo magic quotes (both in keys and values)
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
@@ -34,6 +28,7 @@
require_once 'config.inc.php';
require_once 'functions.inc.php';
require_once 'page.inc.php';
+require_once 'predis/autoload.php';
if (isset($config['login'])) {
@@ -43,19 +38,6 @@
-// phpredis types to string conversion array.
-$redistypes = array(
- Redis::REDIS_STRING => 'string',
- Redis::REDIS_SET => 'set',
- Redis::REDIS_LIST => 'list',
- Redis::REDIS_ZSET => 'zset',
- Redis::REDIS_HASH => 'hash',
-);
-
-
-
-
-
if (isset($login['servers'])) {
$i = current($login['servers']);
} else {
@@ -90,14 +72,7 @@
// Setup a connection to Redis.
-$redis = new Redis();
-
-try {
- $redis->connect($server['host'], $server['port']);
-} catch (Exception $e) {
- die('ERROR: Could not connect to Redis ('.$server['host'].':'.$server['port'].')');
-}
-
+$redis = new Predis\Client('tcp://'.$server['host'].':'.$server['port']);
if (isset($server['auth'])) {
if (!$redis->auth($server['auth'])) {
View
@@ -13,7 +13,7 @@
// String
if (!isset($_GET['type']) || ($_GET['type'] == 'string')) {
// Delete the whole key.
- $redis->delete($_GET['key']);
+ $redis->del($_GET['key']);
}
// Hash
@@ -30,7 +30,7 @@
// 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'], $value, 1);
+ $redis->lRem($_GET['key'], 1, $value);
}
// Set
@@ -42,7 +42,7 @@
// ZSet
else if (($_GET['type'] == 'zset') && isset($_GET['value'])) {
// Removing members from a zset can only be done by supplying the value.
- $redis->zDelete($_GET['key'], $_GET['value']);
+ $redis->zRem($_GET['key'], $_GET['value']);
}
@@ -54,7 +54,7 @@
$keys = $redis->keys($_GET['tree'].'*');
foreach ($keys as $key) {
- $redis->delete($key);
+ $redis->del($key);
}
die('?&s='.$server['id']);
View
@@ -47,7 +47,7 @@
// List
else if (($_POST['type'] == 'list') && isset($_POST['index'])) {
- $size = $redis->lSize($_POST['key']);
+ $size = $redis->lLen($_POST['key']);
if (($_POST['index'] == '') ||
($_POST['index'] == $size) ||
@@ -76,7 +76,7 @@
else if (($_POST['type'] == 'zset') && isset($_POST['score'])) {
if ($_POST['value'] != $_POST['oldvalue']) {
// The only way to edit a ZSet value is to add it and remove the old value.
- $redis->zDelete($_POST['key'], $_POST['oldvalue']);
+ $redis->zRem($_POST['key'], $_POST['oldvalue']);
$redis->zAdd($_POST['key'], $_POST['score'], $_POST['value']);
}
}
@@ -115,7 +115,7 @@
// List
else if (($_GET['type'] == 'list') && isset($_GET['index'])) {
- $value = $redis->lGet($_GET['key'], $_GET['index']);
+ $value = $redis->lIndex($_GET['key'], $_GET['index']);
}
// Set, ZSet
View
@@ -7,16 +7,10 @@
// Export to redis-cli commands
function export_redis($key) {
- global $redistypes, $redis;
+ global $redis;
$type = $redis->type($key);
- if (!isset($redistypes[$type])) {
- return;
- }
-
- $type = $redistypes[$type];
-
// String
if ($type == 'string') {
@@ -34,10 +28,10 @@ function export_redis($key) {
// List
else if ($type == 'list') {
- $size = $redis->lSize($key);
+ $size = $redis->lLen($key);
for ($i = 0; $i < $size; ++$i) {
- echo 'RPUSH "',addslashes($key),'" "',addslashes($redis->lGet($key, $i)),'"',PHP_EOL;
+ echo 'RPUSH "',addslashes($key),'" "',addslashes($redis->lIndex($key, $i)),'"',PHP_EOL;
}
}
@@ -66,16 +60,10 @@ function export_redis($key) {
// Return the JSON for this key
function export_json($key) {
- global $redistypes, $redis;
+ global $redis;
$type = $redis->type($key);
- if (!isset($redistypes[$type])) {
- return 'undefined';
- }
-
- $type = $redistypes[$type];
-
// String
if ($type == 'string') {
@@ -89,11 +77,11 @@ function export_json($key) {
// List
else if ($type == 'list') {
- $size = $redis->lSize($key);
+ $size = $redis->lLen($key);
$value = array();
for ($i = 0; $i < $size; ++$i) {
- $value[] = $redis->lGet($key, $i);
+ $value[] = $redis->lIndex($key, $i);
}
}
View
@@ -65,20 +65,14 @@
// Recursive function used to print the namespaces.
function print_namespace($item, $name, $fullkey, $islast) {
- global $config, $redistypes, $server, $redis;
+ global $config, $server, $redis;
// Is this also a key and not just a namespace?
if (isset($item['__phpredisadmin__'])) {
// Unset it so we won't loop over it when printing this namespace.
unset($item['__phpredisadmin__']);
- $type = $redis->type($fullkey);
-
- if (!isset($redistypes[$type])) {
- return;
- }
-
- $type = $redistypes[$type];
+ $type = $redis->type($fullkey);
$class = array();
$len = false;
@@ -97,7 +91,7 @@ function print_namespace($item, $name, $fullkey, $islast) {
break;
case 'list':
- $len = $redis->lSize($fullkey);
+ $len = $redis->lLen($fullkey);
break;
case 'set':
View
@@ -45,7 +45,7 @@
}
?>
- <tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo format_html($key)?></div></td><td><div><?php echo nl2br(format_html($value))?></div></td></tr>
+ <tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo format_html($key)?></div></td><td><div><?php echo nl2br(format_html(is_array($value) ? print_r($value, true) : $value))?></div></td></tr>
<?php
$alt = !$alt;
View
@@ -13,13 +13,7 @@
}
// Setup a connection to this Redis server.
- $redis->close();
-
- try {
- $redis->connect($server['host'], $server['port']);
- } catch (Exception $e) {
- die('ERROR: Could not connect to Redis ('.$server['host'].':'.$server['port'].')');
- }
+ $redis = new Predis\Client('tcp://'.$server['host'].':'.$server['port']);
if (isset($server['auth'])) {
1 predis
Submodule predis added at 6e9db6
View
@@ -49,7 +49,6 @@
$alt = false;
-$type = $redistypes[$type];
$ttl = $redis->ttl($_GET['key']);
$encoding = $redis->object('encoding', $_GET['key']);
@@ -66,7 +65,7 @@
break;
case 'list':
- $size = $redis->lSize($_GET['key']);
+ $size = $redis->lLen($_GET['key']);
break;
case 'set':
@@ -139,7 +138,7 @@
<tr><th><div>Index</div></th><th><div>Value</div></th><th><div>&nbsp;</div></th><th><div>&nbsp;</div></th></tr>
<?php for ($i = 0; $i < $size; ++$i) {
- $value = $redis->lGet($_GET['key'], $i);
+ $value = $redis->lIndex($_GET['key'], $i);
?>
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo $i?></div></td><td><div><?php echo nl2br(format_html($value))?></div></td><td><div>
<a href="edit.php?s=<?php echo $server['id']?>&amp;type=list&amp;key=<?php echo urlencode($_GET['key'])?>&amp;index=<?php echo $i?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>

0 comments on commit 306b73d

Please sign in to comment.