3 * memcached diagnostic tool
11 require_once( 'commandLine.inc' );
13 $mcc = new memcached( array('persistant' => true/*, 'debug' => true*/) );
14 $mcc->set_servers( $wgMemCachedServers );
15 #$mcc->set_debug( true );
17 function mccShowHelp($command) {
19 if(! $command ) { $command = 'fullhelp'; }
25 // will show help for all commands
29 print "get: grabs something\n";
30 if($onlyone) { break; }
33 print "getsock: lists sockets\n";
34 if($onlyone) { break; }
37 print "set: changes something\n";
38 if($onlyone) { break; }
41 print "delete: deletes something\n";
42 if($onlyone) { break; }
45 print "history: show command line history\n";
46 if($onlyone) { break; }
49 print "server: show current memcached server\n";
50 if($onlyone) { break; }
53 print "dumpmcc: shows the whole thing\n";
54 if($onlyone) { break; }
58 print "exit or quit: exit mcc\n";
59 if($onlyone) { break; }
62 print "help: help about a command\n";
63 if($onlyone) { break; }
67 print "$command: command does not exist or no help for it\n";
77 $line = readconsole( '> ' );
78 if ($line === false) exit;
80 $args = explode( ' ', $line );
81 $command = array_shift( $args );
86 // show an help message
87 mccShowHelp(array_shift($args));
91 print "Getting {$args[0]}[{$args[1]}]\n";
92 $res = $mcc->get( $args[0] );
93 if ( array_key_exists( 1, $args ) ) {
94 $res = $res[$args[1]];
96 if ( $res === false ) {
97 #print 'Error: ' . $mcc->error_string() . "\n";
98 print "MemCached error\n";
99 } elseif ( is_string( $res ) ) {
107 $res = $mcc->get( $args[0] );
108 $sock = $mcc->get_sock( $args[0] );
113 $res = $mcc->get( $args[0] );
114 $hv = $mcc->_hashfunc( $args[0] );
115 for ( $i = 0; $i < 3; $i++
) {
116 print $mcc->_buckets
[$hv %
$mcc->_bucketcount
] . "\n";
117 $hv +
= $mcc->_hashfunc( $i . $args[0] );
122 $key = array_shift( $args );
123 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
124 $value = str_repeat( '*', $args[1] );
126 $value = implode( ' ', $args );
128 if ( !$mcc->set( $key, $value, 0 ) ) {
129 #print 'Error: ' . $mcc->error_string() . "\n";
130 print "MemCached error\n";
135 $key = implode( ' ', $args );
136 if ( !$mcc->delete( $key ) ) {
137 #print 'Error: ' . $mcc->error_string() . "\n";
138 print "MemCached error\n";
143 if ( function_exists( 'readline_list_history' ) ) {
144 foreach( readline_list_history() as $num => $line) {
145 print "$num: $line\n";
148 print "readline_list_history() not available\n";
167 print "Bad command\n";
170 if ( function_exists( 'readline_add_history' ) ) {
171 readline_add_history( $line );