forked from samm-git/cm_redis_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rediscli.php
70 lines (59 loc) · 1.74 KB
/
rediscli.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
<?php
/* Load Credis client library */
include_once("lib/Credis/Client.php");
/* emulation of the ZF to work standalone */
abstract class Zend_Cache
{
const CLEANING_MODE_ALL = 'all';
const CLEANING_MODE_OLD = 'old';
const CLEANING_MODE_MATCHING_TAG = 'matchingTag';
const CLEANING_MODE_NOT_MATCHING_TAG = 'notMatchingTag';
const CLEANING_MODE_MATCHING_ANY_TAG = 'matchingAnyTag';
function throwException($text) {
die("Exception: ".$text."\n");
}
}
abstract class Zend_Cache_Backend {}
interface Zend_Cache_Backend_ExtendedInterface {}
/* loading Redis cache backend */
include_once("Cm/Cache/Backend/Redis.php");
function showHelp(){
echo "Usage: rediscli.php\n".
"\t-s <server> - server address\n".
"\t-p <port> - server port\n".
"\t-v show status messages\n".
"\t-d <database list> - list of the databases, comma separated\n".
"Example: rediscli.php -s 127.0.0.1 -p 6379 -d 0,1\n\n";
exit(0);
}
/* parsing command line options */
$opts = "s:p:vd:";
$options = getopt($opts);
if(!isset($options["s"]) || !isset($options["p"]) || !isset($options["d"])) {
showHelp();
}
$databases=preg_split('/,/',$options["d"]);
foreach($databases as $db) {
$db = (int) $db;
if(isset($options["v"]))
echo "Cleaing database $db:";
try {
$cache = new Cm_Cache_Backend_Redis(array('server' => $options["s"], 'port' => $options["p"], 'database' => $db));
} catch (CredisException $e) {
echo "\nError: ".$e->getMessage()."\n";
exit(1);
}
if($cache === false ){
echo "\nERROR: Unable to clean database $db\n";
}
try {
$cache->clean(Zend_Cache::CLEANING_MODE_OLD);
} catch (CredisException $e) {
echo "\nError: ".$e->getMessage()."\n";
exit(1);
}
if(isset($options["v"]))
echo " [done]\n";
unset($cache);
}
?>