Memcached常用命令
1启动和连接
启动Memcached服务:
memcached -d -p11211 -u root -m 64 -c 1024 -P /var/run/memcached/memcached.pid
用Telnet连接上:
telnet192.168.1.100 11211
2基础命令
2.1常用命令列表
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 |
2.2增删改查
// 增加
add name 0 60 5 [name是key的名字(是以key/value存放),0标志,60表示数据存放60s,5表示放入多大数据。如果一个key已经存在,再放入是失败的]
add test1 0 0 10
testing002
NOT_STORED
add test2 0 0 10
testing002
STORED
// 查询
get name [获取 name的值。在第一行得到key的名字,flag的值和返回的value的长度。真正的数据在第二行,最后返回END]
get test1
VALUE test1 0 10
testing003
END
get test4
END
get test1 test2
VALUE test1 0 10
testing003
END
// 更新
set name 0 60 5 [如果 name 这个key存在,就是更新, 如果key不存在,就是添加]
set test1 0 0 10
testing001
STORED
// 删除
delete key值
3管理命令
memcache 的 stats 命令包括:
1. stats
2. stats reset
3. stats malloc
4. stats maps
5. stats sizes
6. stats slabs
7. stats items
8. stats cachedump slab_id limit_num
9. stats detail [on|off|dump]
执行stats items可以查看所有Slab的信息
执行stats cachedump 3 0可以查看Slab的id为3中的所有key-value。
最后一个数字表示取出多少数据,0表示所有数据。
参考资料
如何对memcache的数据(key-value)进行遍历操作
http://kb.cnblogs.com/page/43350/
Memcached: List all keys