3 * memcached diagnostic tool
6 * @addtogroup Maintenance
10 require_once( 'commandLine.inc' );
12 $mcc = new memcached( array('persistant' => true/*, 'debug' => true*/) );
13 $mcc->set_servers( $wgMemCachedServers );
14 #$mcc->set_debug( true );
16 function mccShowHelp($command) {
18 if(! $command ) { $command = 'fullhelp'; }
24 // will show help for all commands
28 print "get: grabs something\n";
29 if($onlyone) { break; }
32 print "getsock: lists sockets\n";
33 if($onlyone) { break; }
36 print "set: changes something\n";
37 if($onlyone) { break; }
40 print "delete: deletes something\n";
41 if($onlyone) { break; }
44 print "history: show command line history\n";
45 if($onlyone) { break; }
48 print "server: show current memcached server\n";
49 if($onlyone) { break; }
52 print "dumpmcc: shows the whole thing\n";
53 if($onlyone) { break; }
57 print "exit or quit: exit mcc\n";
58 if($onlyone) { break; }
61 print "help: help about a command\n";
62 if($onlyone) { break; }
66 print "$command: command does not exist or no help for it\n";
76 $line = readconsole( '> ' );
77 if ($line === false) exit;
79 $args = explode( ' ', $line );
80 $command = array_shift( $args );
85 // show an help message
86 mccShowHelp(array_shift($args));
90 print "Getting {$args[0]}[{$args[1]}]\n";
91 $res = $mcc->get( $args[0] );
92 if ( array_key_exists( 1, $args ) ) {
93 $res = $res[$args[1]];
95 if ( $res === false ) {
96 #print 'Error: ' . $mcc->error_string() . "\n";
97 print "MemCached error\n";
98 } elseif ( is_string( $res ) ) {
106 $res = $mcc->get( $args[0] );
107 $sock = $mcc->get_sock( $args[0] );
112 $res = $mcc->get( $args[0] );
113 $hv = $mcc->_hashfunc( $args[0] );
114 for ( $i = 0; $i < 3; $i++
) {
115 print $mcc->_buckets
[$hv %
$mcc->_bucketcount
] . "\n";
116 $hv +
= $mcc->_hashfunc( $i . $args[0] );
121 $key = array_shift( $args );
122 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
123 $value = str_repeat( '*', $args[1] );
125 $value = implode( ' ', $args );
127 if ( !$mcc->set( $key, $value, 0 ) ) {
128 #print 'Error: ' . $mcc->error_string() . "\n";
129 print "MemCached error\n";
134 $key = implode( ' ', $args );
135 if ( !$mcc->delete( $key ) ) {
136 #print 'Error: ' . $mcc->error_string() . "\n";
137 print "MemCached error\n";
142 if ( function_exists( 'readline_list_history' ) ) {
143 foreach( readline_list_history() as $num => $line) {
144 print "$num: $line\n";
147 print "readline_list_history() not available\n";
166 print "Bad command\n";
169 if ( function_exists( 'readline_add_history' ) ) {
170 readline_add_history( $line );