Running and Verifying Memcached
- Start Memcached.
1memcached -t 24 -p 11211 -u root -m 49152 -c 10240
Table 1 describes the startup command parameters.
Table 1 Startup command parameter description Parameter
Description
Default Value
-t
Specifies the number of threads.
4
-p
Specifies the TCP listening port.
11211
-u
Specifies the user who starts the process.
By default, the root user cannot start the process.
-m
Specifies the memory size allocated to Memcached.
The unit is MB.
64 MB
-c
Specifies the maximum number of concurrent connections.
1024
-d
Starts a daemon in the background.
-
To stop Memcached, press Ctrl+C.
- Start another shell window to connect to Memcached.
1telnet 127.0.0.1 11211
- In addition to connecting to the Memcached service using Telnet to obtain data, the source code provides some tool scripts, such as memcached-tool, in the scripts directory of the source code. Table 2 describes the methods for using memcached-tool.
- To exit the Telnet connection, run the quit command.
1quit
Table 2 memcached-tool Command
Description
./memcached-tool localhost display
Displays slabs information.
./memcached-tool 10.0.0.5:11211 display
Displays slabs information.
./memcached-tool 10.0.0.5:11211 stats
Displays Memcached statistics.
./memcached-tool 10.0.0.5:11211 settings
Displays Memcached settings.
./memcached-tool 10.0.0.5:11211 sizes
Displays the size and number of all items.
./memcached-tool 10.0.0.5:11211 dump [limit]
Outputs Keys and Values from the cache.
- After the connection is set up, run the stats command to obtain the statistics of the Memcached server.
1stats

Table 3 lists the common stats commands.
Table 3 stats commands Command
Description
stats
Displays the overall status of Memcached, including the startup time, amount of data stored, cache hit ratio, and number of current connections.
stats items
Outputs the item information of each slab.
stats slabs
Outputs more detailed slab information.
stats sizes
Displays the size and number of all items.
stats cachedump <slabId> <limit>
Outputs data in <slabId>. <limit> indicates the number of data outputs. If the input is 0, all data in the slab is output.
stats detail <on|off|dump>
Sets (on/off) or displays (dump) detailed operation records, such as the get/set operation.
flush_all
Invalidates all items in the memory. This operation does not suspend the server because the memory space is not released but the existing items are marked as invalid.