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 = Maintenance
::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 if ( $mcc->_single_sock
!== null ) {
90 print $mcc->_single_sock
. "\n";
93 $res = $mcc->get( $args[0] );
94 $hv = $mcc->_hashfunc( $args[0] );
95 for ( $i = 0; $i < 3; $i++
) {
96 print $mcc->_buckets
[$hv %
$mcc->_bucketcount
] . "\n";
97 $hv +
= $mcc->_hashfunc( $i . $args[0] );
102 $key = array_shift( $args );
103 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
104 $value = str_repeat( '*', $args[1] );
106 $value = implode( ' ', $args );
108 if ( !$mcc->set( $key, $value, 0 ) ) {
109 # print 'Error: ' . $mcc->error_string() . "\n";
110 print "MemCached error\n";
115 $key = implode( ' ', $args );
116 if ( !$mcc->delete( $key ) ) {
117 # print 'Error: ' . $mcc->error_string() . "\n";
118 print "MemCached error\n";
123 if ( function_exists( 'readline_list_history' ) ) {
124 foreach ( readline_list_history() as $num => $line ) {
125 print "$num: $line\n";
128 print "readline_list_history() not available\n";
147 print "Bad command\n";
150 if ( function_exists( 'readline_add_history' ) ) {
151 readline_add_history( $line );