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' ) {
35 foreach( array_keys( $commandList ) as $cmd ) {
36 $max_cmd_len = max( $max_cmd_len, strlen($cmd) );
38 foreach ( $commandList as $cmd => $desc ) {
39 printf( "%-{$max_cmd_len}s: %s\n", $cmd, $desc );
41 } elseif ( isset( $commandList[$command] ) ) {
42 print "$command: $commandList[$command]\n";
44 print "$command: command does not exist or no help for it\n";
53 $line = Maintenance
::readconsole();
54 if ( $line === false ) exit;
56 $args = explode( ' ', $line );
57 $command = array_shift( $args );
62 // show an help message
63 mccShowHelp( array_shift( $args ) );
68 if ( array_key_exists( 1, $args ) ) {
71 print "Getting {$args[0]}[$sub]\n";
72 $res = $mcc->get( $args[0] );
73 if ( array_key_exists( 1, $args ) ) {
74 $res = $res[$args[1]];
76 if ( $res === false ) {
77 # print 'Error: ' . $mcc->error_string() . "\n";
78 print "MemCached error\n";
79 } elseif ( is_string( $res ) ) {
87 $res = $mcc->get( $args[0] );
88 $sock = $mcc->get_sock( $args[0] );
93 if ( $mcc->_single_sock
!== null ) {
94 print $mcc->_single_sock
. "\n";
97 $res = $mcc->get( $args[0] );
98 $hv = $mcc->_hashfunc( $args[0] );
99 for ( $i = 0; $i < 3; $i++
) {
100 print $mcc->_buckets
[$hv %
$mcc->_bucketcount
] . "\n";
101 $hv +
= $mcc->_hashfunc( $i . $args[0] );
106 $key = array_shift( $args );
107 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
108 $value = str_repeat( '*', $args[1] );
110 $value = implode( ' ', $args );
112 if ( !$mcc->set( $key, $value, 0 ) ) {
113 # print 'Error: ' . $mcc->error_string() . "\n";
114 print "MemCached error\n";
119 $key = implode( ' ', $args );
120 if ( !$mcc->delete( $key ) ) {
121 # print 'Error: ' . $mcc->error_string() . "\n";
122 print "MemCached error\n";
127 if ( function_exists( 'readline_list_history' ) ) {
128 foreach ( readline_list_history() as $num => $line ) {
129 print "$num: $line\n";
132 print "readline_list_history() not available\n";
151 print "Bad command\n";
154 if ( function_exists( 'readline_add_history' ) ) {
155 readline_add_history( $line );