How to login and manage memcached through command-line
Memcached is an in-memory key-value store system to speed up the websites.
This article explains some basic commands to manage memcached.
Connect to memcached.
#telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Check the server info of memcached.
stats
STAT pid 22622
STAT uptime 69300
STAT time 1296733424
STAT version 1.2.5
STAT pointer_size 32
STAT rusage_user 0.117982
STAT rusage_system 0.145977
STAT curr_items 3
STAT total_items 10
STAT bytes 1174
STAT curr_connections 2
STAT total_connections 13
STAT connection_structures 3
STAT cmd_get 10
STAT cmd_set 10
STAT get_hits 9
STAT get_misses 1
STAT evictions 0
STAT bytes_read 4593
STAT bytes_written 7388
STAT limit_maxbytes 268435456
STAT threads 1
END
List the slabs in the memcached instance.
stats slabs
STAT 1:chunk_size 88
STAT 1:chunks_per_page 11915
STAT 1:total_pages 1
STAT 1:total_chunks 11915
STAT 1:used_chunks 11915
STAT 1:free_chunks 0
STAT 1:free_chunks_end 11914
STAT 6:chunk_size 296
STAT 6:chunks_per_page 3542
STAT 6:total_pages 1
STAT 6:total_chunks 3542
STAT 6:used_chunks 3541
STAT 6:free_chunks 1
STAT 6:free_chunks_end 3541
STAT 7:chunk_size 376
STAT 7:chunks_per_page 2788
STAT 7:total_pages 1
STAT 7:total_chunks 2788
STAT 7:used_chunks 2788
STAT 7:free_chunks 0
STAT 7:free_chunks_end 2787
STAT 8:chunk_size 472
STAT 8:chunks_per_page 2221
STAT 8:total_pages 1
STAT 8:total_chunks 2221
STAT 8:used_chunks 2220
STAT 8:free_chunks 1
STAT 8:free_chunks_end 2218
STAT active_slabs 4
STAT total_malloced 4193552
END
Get more info of slabs.
stats items
STAT items:1:number 1
STAT items:1:age 35
STAT items:1:evicted 0
STAT items:1:outofmemory 0
STAT items:7:number 1
STAT items:7:age 69596
STAT items:7:evicted 0
STAT items:7:outofmemory 0
STAT items:8:number 2
STAT items:8:age 69627
STAT items:8:evicted 0
STAT items:8:outofmemory 0
END
Accessing data info from slab.
Syntax: stats cachedump [slab ID] [number of items, 0 for all items]
stats cachedump 1 0
ITEM testkey [9 b; 1296857316 s]
END
Get the exact data.
get testkey
VALUE testkey 0 9
test data
END
Delete the data.
delete testkey
DELETED
Quit from memcached terminal.
quit
Connection closed by foreign host.
That's all…