3 * memcached diagnostic tool
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 * @ingroup Maintenance
26 require_once( dirname( __FILE__
) . '/commandLine.inc' );
28 $mcc = new MWMemcached( array( 'persistent' => true/*, 'debug' => true*/ ) );
29 $mcc->set_servers( $wgMemCachedServers );
30 # $mcc->set_debug( true );
32 function mccShowHelp( $command ) {
34 'get' => 'grabs something',
35 'getsock' => 'lists sockets',
36 'set' => 'changes something',
37 'delete' => 'deletes something',
38 'history' => 'show command line history',
39 'server' => 'show current memcached server',
40 'dumpmcc' => 'shows the whole thing',
43 'help' => 'help about a command',
46 $command = 'fullhelp';
48 if ( $command === 'fullhelp' ) {
49 $max_cmd_len = max( array_map( 'strlen', array_keys( $commandList ) ) );
50 foreach ( $commandList as $cmd => $desc ) {
51 printf( "%-{$max_cmd_len}s: %s\n", $cmd, $desc );
53 } elseif ( isset( $commandList[$command] ) ) {
54 print "$command: $commandList[$command]\n";
56 print "$command: command does not exist or no help for it\n";
65 $line = Maintenance
::readconsole();
66 if ( $line === false ) exit;
68 $args = explode( ' ', $line );
69 $command = array_shift( $args );
74 // show an help message
75 mccShowHelp( array_shift( $args ) );
80 if ( array_key_exists( 1, $args ) ) {
83 print "Getting {$args[0]}[$sub]\n";
84 $res = $mcc->get( $args[0] );
85 if ( array_key_exists( 1, $args ) ) {
86 $res = $res[$args[1]];
88 if ( $res === false ) {
89 # print 'Error: ' . $mcc->error_string() . "\n";
90 print "MemCached error\n";
91 } elseif ( is_string( $res ) ) {
99 $res = $mcc->get( $args[0] );
100 $sock = $mcc->get_sock( $args[0] );
105 if ( $mcc->_single_sock
!== null ) {
106 print $mcc->_single_sock
. "\n";
109 $res = $mcc->get( $args[0] );
110 $hv = $mcc->_hashfunc( $args[0] );
111 for ( $i = 0; $i < 3; $i++
) {
112 print $mcc->_buckets
[$hv %
$mcc->_bucketcount
] . "\n";
113 $hv +
= $mcc->_hashfunc( $i . $args[0] );
118 $key = array_shift( $args );
119 if ( $args[0] == "#" && is_numeric( $args[1] ) ) {
120 $value = str_repeat( '*', $args[1] );
122 $value = implode( ' ', $args );
124 if ( !$mcc->set( $key, $value, 0 ) ) {
125 # print 'Error: ' . $mcc->error_string() . "\n";
126 print "MemCached error\n";
131 $key = implode( ' ', $args );
132 if ( !$mcc->delete( $key ) ) {
133 # print 'Error: ' . $mcc->error_string() . "\n";
134 print "MemCached error\n";
139 if ( function_exists( 'readline_list_history' ) ) {
140 foreach ( readline_list_history() as $num => $line ) {
141 print "$num: $line\n";
144 print "readline_list_history() not available\n";
163 print "Bad command\n";
166 if ( function_exists( 'readline_add_history' ) ) {
167 readline_add_history( $line );