3 * memcached diagnostic tool
7 * @subpackage Maintenance
11 require_once( 'commandLine.inc' );
12 require_once( 'memcached-client.php' );
14 $mcc = new memcached( array('persistant' => true/*, 'debug' => true*/) );
15 $mcc->set_servers( $wgMemCachedServers );
16 #$mcc->set_debug( true );
18 function mccShowHelp($command) {
20 if(! $command ) { $command = 'fullhelp'; }
26 // will show help for all commands
30 print "get: grabs something\n";
31 if($onlyone) { break; }
34 print "getsock: lists sockets\n";
35 if($onlyone) { break; }
38 print "set: changes something\n";
39 if($onlyone) { break; }
42 print "delete: deletes something\n";
43 if($onlyone) { break; }
46 print "history: show command line history\n";
47 if($onlyone) { break; }
50 print "server: show current memcached server\n";
51 if($onlyone) { break; }
54 print "dumpmcc: shows the whole thing\n";
55 if($onlyone) { break; }
59 print "exit or quit: exit mcc\n";
60 if($onlyone) { break; }
63 print "help: help about a command\n";
64 if($onlyone) { break; }
68 print "$command: command does not exist or no help for it\n";
78 $line = readconsole( '> ' );
79 if ($line === false) exit;
81 $args = explode( ' ', $line );
82 $command = array_shift( $args );
87 // show an help message
88 mccShowHelp(array_shift($args));
92 print "Getting {$args[0]}[{$args[1]}]\n";
93 $res = $mcc->get( $args[0] );
94 if ( array_key_exists( 1, $args ) ) {
95 $res = $res[$args[1]];
97 if ( $res === false ) {
98 #print 'Error: ' . $mcc->error_string() . "\n";
99 print "MemCached error\n";
100 } elseif ( is_string( $res ) ) {
108 $res = $mcc->get( $args[0] );
109 $sock = $mcc->get_sock( $args[0] );
114 $res = $mcc->get( $args[0] );
115 $hv = $mcc->_hashfunc( $args[0] );
116 for ( $i = 0; $i < 3; $i++
) {
117 print $mcc->_buckets
[$hv %
$mcc->_bucketcount
] . "\n";
118 $hv +
= $mcc->_hashfunc( $i . $args[0] );
123 $key = array_shift( $args );
124 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
125 $value = str_repeat( '*', $args[1] );
127 $value = implode( ' ', $args );
129 if ( !$mcc->set( $key, $value, 0 ) ) {
130 #print 'Error: ' . $mcc->error_string() . "\n";
131 print "MemCached error\n";
136 $key = implode( ' ', $args );
137 if ( !$mcc->delete( $key ) ) {
138 #print 'Error: ' . $mcc->error_string() . "\n";
139 print "MemCached error\n";
144 if ( function_exists( 'readline_list_history' ) ) {
145 foreach( readline_list_history() as $num => $line) {
146 print "$num: $line\n";
149 print "readline_list_history() not available\n";
168 print "Bad command\n";
171 if ( function_exists( 'readline_add_history' ) ) {
172 readline_add_history( $line );