利用shell命令操作Memcached

转自:http://blog.s135.com/post/384/

 首先,需要了解Memcached协议,如果不清楚可参考《Memcached 协议中英文对照》。

1、数据存储(假设key为zhangyan,value为12345)

printf "set zhangyan 0 0 5\r\n12345\r\n" | nc 127.0.0.1 11211

 STORED

2、数据取回(假设key为zhangyan)

printf "get zhangyan\r\n" | nc 127.0.0.1 11211

 VALUE zhangyan 0 5

 12345

 END

3、数值增加1(假设key为zhangyan,并且value为正整数)

printf "incr zhangyan 1\r\n" | nc 127.0.0.1 11211

 12346

4、数值减少3(假设key为zhangyan,并且value为正整数)

printf "decr zhangyan 3\r\n" | nc 127.0.0.1 11211

 12343

5、数据删除(假设key为zhangyan)

printf "delete zhangyan\r\n" | nc 127.0.0.1 11211

 DELETED

6、查看Memcached状态

printf "stats\r\n" | nc 127.0.0.1 11211

 STAT pid 3025

 STATuptime4120500

 STATtime1228021767

 STATversion1.2.6

 STATpointer_size32

 STATrusage_user433.463103

 STATrusage_system1224.515845

 STATcurr_items1132460

 STATtotal_items8980260

 STATbytes1895325386

 STATcurr_connections252

 STATtotal_connections547850

 STATconnection_structures1189

 STATcmd_get13619685

 STATcmd_set8980260

 STATget_hits6851607

 STATget_misses6768078

 STATevictions0

 STATbytes_read160396238246

 STATbytes_written260080686529

 STATlimit_maxbytes2147483648

 STATthreads1

 END

7、模拟top命令,查看Memcached状态:

watch "printf 'stats\r\n' | nc 127.0.0.1 11211"

或者

watch "echo stats | nc 127.0.0.1 11211"

相关推荐