用nc命令操作memcached
1)存储数据:printf “set key 0 10 6\r\nresult\r\n” |nc 192.168.2.34 11211
2)获取数据:printf “get key\r\n” |nc 192.168.2.34 11211
3)删除数据:printf “delete key\r\n” |nc 192.168.2.34 11211
4)查看状态:printf “stats\r\n” |nc 192.168.2.34 11211
5)模拟top命令查看状态:watch “echo stats” |nc 192.168.2.34 11211
6)清空缓存:printf “flush_all\r\n” |nc 192.168.2.34 11211 (小心操作,清空了缓存就没了)
memcached的基本命令(安装、卸载、启动、配置相关):
-p 监听的端口-l 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop |shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB ,最大好像2G
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25
-n 最小分配空间,key+value+flags默认是48
-h 显示帮助
memcached的基本命令(当memcached 启动后用于对memcached管理的数据和本身运行状态相关的命令):
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 |