---
title: "memcache  状态"
author: "wangmored"
date: "2013-01-11T18:10:25Z"
tags: []
categories: ["互联网"]
slug: "memcache"
draft: false
lastmod: "2014-05-09T12:14:44Z"
id: 1768534
url: "https://wangmored.iteye.com/blog/1768534"
---

set <key> <flag> <expires> <byte>
Flag 用于指定是否压缩数据，0不压缩，1压缩
Expires 指定数据保存的时间，一种方法是秒数（不能超过30天），另一种可以使用unix时间戳指定，0为有效期无限
Byte 保存值的字节数


#赋值
set test 0 0 9
zhoujinyi
STORED

#取值
get test
VALUE test 0 9
zhoujinyi
END

#加法
set test1 0 0 1
STORED
incr test1 1                           #加1
get test1
VALUE test1 0 2
END

#减法
decr test1 5                           #减5
get test1
VALUE test1 0 1
END

#删除
delete test1                           #删除key
DELETED
get test1
END

#追加
get test
VALUE test 0 9
zhoujinyi
END
append test 0 0 3                       #最后追加
ABC
STORED
get test
VALUE test 0 12
zhoujinyiABC
END
prepend test 0 0 3                      #最先追加
CBA
STORED
get test
VALUE test 0 15
CBAzhoujinyiABC
END

#清除所有数据
flush_all
ok

#退出
quit





telnet 192.168.6.7 11000
stats



STAT pid 1552

STAT uptime 3792

STAT time 1262517674

STAT version 1.2.6

STAT pointer_size 32

STAT curr_items 1

STAT total_items 2

STAT bytes 593

STAT curr_connections 2

STAT total_connections 28

STAT connection_structures 9

STAT cmd_get 3

STAT cmd_set 2

STAT get_hits 2

STAT get_misses 1

STAT evictions 0

STAT bytes_read 1284

STAT bytes_written 5362

STAT limit_maxbytes 67108864

STAT threads 1

END

这里显示了很多状态信息，下边详细解释每个状态项：

1.  pid: memcached服务进程的进程ID

2.  uptime: memcached服务从启动到当前所经过的时间，单位是秒。

3.  time: memcached服务器所在主机当前系统的时间，单位是秒。

4.  version: memcached组件的版本。这里是我当前使用的1.2.6。

5.  pointer_size：服务器所在主机操作系统的指针大小，一般为32或64.

6.  curr_items：表示当前缓存中存放的所有缓存对象的数量。不包括目前已经从缓存中删除的对象。

7.  total_items：表示从memcached服务启动到当前时间，系统存储过的所有对象的数量，包括目前已经从缓存中删除的对象。

8.  bytes：表示系统存储缓存对象所使用的存储空间，单位为字节。

9.  curr_connections：表示当前系统打开的连接数。

10. total_connections：表示从memcached服务启动到当前时间，系统打开过的连接的总数。

11. connection_structures：表示从memcached服务启动到当前时间，被服务器分配的连接结构的数量，这个解释是协议文档给的，具体什么意思，我目前还没搞明白。

12. cmd_get：累积获取数据的数量，这里是3，因为我测试过3次，第一次因为没有序列化对象，所以获取数据失败，是null，后边有2次是我用不同对象测试了2次。

13. cmd_set：累积保存数据的树立数量，这里是2.虽然我存储了3次，但是第一次因为没有序列化，所以没有保存到缓存，也就没有记录。

14. get_hits：表示获取数据成功的次数。

15. get_misses：表示获取数据失败的次数。

16. evictions：为了给新的数据项目释放空间，从缓存移除的缓存对象的数目。比如超过缓存大小时根据LRU算法移除的对象，以及过期的对象。

17. bytes_read：memcached服务器从网络读取的总的字节数。

18. bytes_written：memcached服务器发送到网络的总的字节数。

19. limit_maxbytes：memcached服务缓存允许使用的最大字节数。这里为67108864字节，也就是是64M.与我们启动memcached服务设置的大小一致。

20. threads：被请求的工作线程的总数量。这个解释是协议文档给的，具体什么意思，我目前还没搞明白。