命令行访问memcached

有很多的web端和GUI可以访问到Memcached服务,比如phpMemCacheAdmin,但是有些时候需要在命令行进行Memcached的访问。 在本教程中使用Telnet来攻取Memcached信息,以及如何读取与删除数据。 连接

telnet localhost 11211

获取服务信息,如pid, uptime, version, 条目数, 连接数

stats

获取slab信息,那么什么是slab Memory is allocated in chunks internally and constantly reused. Since memory is broken into different size slabs, you do waste memory if your items do not fit perfectly into the slab the server chooses to put it in. Memcached会根据你数据的大小来存放不同的slab,可以理解为片或分区,这样不会浪费内存。

stats slabs

获取条目信息

stats items

访问和删除数据

知道slab的概念和信息之后,可以使用如下命令访问slab

stats cachedump [slab ID] [number of items, 0 for all items]

如在ID=36的slab中有3个条目

stats cachedump 36 0
ITEM model1 [223301 b; 1383751902 s]
ITEM modelNodeid1 [223301 b; 1383751902 s]
ITEM id1 [223300 b; 1383751902 s]
END

获取id1

get id1

删除id1

delete id1

退出

quit 或 ctrl + ]

Command Description Example

get Reads a value get mykey
set Set a key unconditionally set mykey 0 60 5
add Add a new key add newkey 0 60 5
replace Overwrite existing key replace key 0 60 5
append Append data to existing key append key 0 60 15
prepend Prepend data to existing key prepend key 0 60 15
incr Increments numerical key value by given number incr mykey 2
decr Decrements numerical key value by given number decr mykey 5
delete Deletes an existing key delete mykey
flush_all Invalidate specific items immediately flush_all
Invalidate all items in n seconds flush_all 900
stats Prints general statistics stats
Prints memory statistics stats slabs
Prints memory statistics stats malloc
Print higher level allocation statistics stats items
stats detail
stats sizes
Resets statistics stats reset
version Prints server version. version
verbosity Increases log level verbosity
quit Terminate telnet session quit

参考: http://www.alphadevx.com/a/90-Accessing-Memcached-from-the-command-line

发表评论

电子邮件地址不会被公开。 必填项已用*标注