73730b130f973ff45fbce763c22936c0abc8957f
3 * memcached diagnostic tool
11 require_once( dirname(__FILE__
) . '/commandLine.inc' );
13 $mcc = new MWMemcached( array('persistant' => true/*, 'debug' => true*/) );
14 $mcc->set_servers( $wgMemCachedServers );
15 #$mcc->set_debug( true );
17 function mccShowHelp($command) {
19 'get' => 'grabs something',
20 'getsock' => 'lists sockets',
21 'set' => 'changes something',
22 'delete' => 'deletes something',
23 'history' => 'show command line history',
24 'server' => 'show current memcached server',
25 'dumpmcc' => 'shows the whole thing',
28 'help' => 'help about a command',
31 $command = 'fullhelp';
33 if( $command === 'fullhelp' ) {
34 foreach( $commandList as $cmd => $desc ) {
35 print "$cmd: $desc\n";
37 } elseif( isset( $commandList[$command] ) ) {
38 print "$command: $commandList[$command]\n";
40 print "$command: command does not exist or no help for it\n";
49 $line = readconsole( '> ' );
50 if ($line === false) exit;
52 $args = explode( ' ', $line );
53 $command = array_shift( $args );
58 // show an help message
59 mccShowHelp(array_shift($args));
64 if ( array_key_exists( 1, $args ) ) {
67 print "Getting {$args[0]}[$sub]\n";
68 $res = $mcc->get( $args[0] );
69 if ( array_key_exists( 1, $args ) ) {
70 $res = $res[$args[1]];
72 if ( $res === false ) {
73 #print 'Error: ' . $mcc->error_string() . "\n";
74 print "MemCached error\n";
75 } elseif ( is_string( $res ) ) {
83 $res = $mcc->get( $args[0] );
84 $sock = $mcc->get_sock( $args[0] );
89 $res = $mcc->get( $args[0] );
90 $hv = $mcc->_hashfunc( $args[0] );
91 for ( $i = 0; $i < 3; $i++
) {
92 print $mcc->_buckets
[$hv %
$mcc->_bucketcount
] . "\n";
93 $hv +
= $mcc->_hashfunc( $i . $args[0] );
98 $key = array_shift( $args );
99 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
100 $value = str_repeat( '*', $args[1] );
102 $value = implode( ' ', $args );
104 if ( !$mcc->set( $key, $value, 0 ) ) {
105 #print 'Error: ' . $mcc->error_string() . "\n";
106 print "MemCached error\n";
111 $key = implode( ' ', $args );
112 if ( !$mcc->delete( $key ) ) {
113 #print 'Error: ' . $mcc->error_string() . "\n";
114 print "MemCached error\n";
119 if ( function_exists( 'readline_list_history' ) ) {
120 foreach( readline_list_history() as $num => $line) {
121 print "$num: $line\n";
124 print "readline_list_history() not available\n";
143 print "Bad command\n";
146 if ( function_exists( 'readline_add_history' ) ) {
147 readline_add_history( $line );