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 $max_cmd_len = max( array_map( 'strlen', array_keys( $commandList ) ) );
35 foreach ( $commandList as $cmd => $desc ) {
36 printf( "%-{$max_cmd_len}s: %s\n", $cmd, $desc );
38 } elseif ( isset( $commandList[$command] ) ) {
39 print "$command: $commandList[$command]\n";
41 print "$command: command does not exist or no help for it\n";
50 $line = Maintenance
::readconsole();
51 if ( $line === false ) exit;
53 $args = explode( ' ', $line );
54 $command = array_shift( $args );
59 // show an help message
60 mccShowHelp( array_shift( $args ) );
65 if ( array_key_exists( 1, $args ) ) {
68 print "Getting {$args[0]}[$sub]\n";
69 $res = $mcc->get( $args[0] );
70 if ( array_key_exists( 1, $args ) ) {
71 $res = $res[$args[1]];
73 if ( $res === false ) {
74 # print 'Error: ' . $mcc->error_string() . "\n";
75 print "MemCached error\n";
76 } elseif ( is_string( $res ) ) {
84 $res = $mcc->get( $args[0] );
85 $sock = $mcc->get_sock( $args[0] );
90 if ( $mcc->_single_sock
!== null ) {
91 print $mcc->_single_sock
. "\n";
94 $res = $mcc->get( $args[0] );
95 $hv = $mcc->_hashfunc( $args[0] );
96 for ( $i = 0; $i < 3; $i++
) {
97 print $mcc->_buckets
[$hv %
$mcc->_bucketcount
] . "\n";
98 $hv +
= $mcc->_hashfunc( $i . $args[0] );
103 $key = array_shift( $args );
104 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
105 $value = str_repeat( '*', $args[1] );
107 $value = implode( ' ', $args );
109 if ( !$mcc->set( $key, $value, 0 ) ) {
110 # print 'Error: ' . $mcc->error_string() . "\n";
111 print "MemCached error\n";
116 $key = implode( ' ', $args );
117 if ( !$mcc->delete( $key ) ) {
118 # print 'Error: ' . $mcc->error_string() . "\n";
119 print "MemCached error\n";
124 if ( function_exists( 'readline_list_history' ) ) {
125 foreach ( readline_list_history() as $num => $line ) {
126 print "$num: $line\n";
129 print "readline_list_history() not available\n";
148 print "Bad command\n";
151 if ( function_exists( 'readline_add_history' ) ) {
152 readline_add_history( $line );