xiaobaoqiu@xiaobaoqiu:~$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
add myid 1 0 4
1234
STORED
get myid
VALUE myid 1 4
1234
END
# memcached default config file
# 2003 - Jay Bonci <jaybonci@debian.org>
# This configuration file is read by the start-memcached script provided as
# part of the Debian GNU/Linux distribution.
# Run memcached as a daemon. This command is implied, and is not needed for the
# daemon to run. See the README.Debian that comes with this package for more
# information.
# 以守护进程的形似运行
-d
# Log memcached's output to /var/log/memcached
# 日志文件存放位置
logfile /var/log/memcached.log
# Be verbose
# -v
# Be even more verbose (print client commands as well)
# -vv
# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
# Note that the daemon will grow to this size, but does not start out holding this much
# memory
# 分配给mencached的内存数目,单位是MB
-m 256
# Default connection port is 11211
# Memcached的监听端口
-p 11211
# Run the daemon as root. The start-memcached will default to running as root if no
# -u command is present in this config file
# 允许memcached的用户
-u memcache
# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.
# 监听的服务器IP地址
-l 127.0.0.1
# Limit the number of simultaneous incoming connections. The daemon default is 1024
# -c 1024
# Lock down all paged memory. Consult with the README and homepage before you do this
# -k
# Return error when memory is exhausted (rather than removing items)
# -M
# Maximize core file limit
# -r
xiaobaoqiu@xiaobaoqiu:~$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set name 0 0 11
baoqiu.xiao
STORED
get name
VALUE name 0 11
baoqiu.xiao
END
set name 0 0 9
memcached
STORED
get name
VALUE name 0 9
memcached
END
(2).add:只有数据不存在时添加值的add命令
已经存在的key是不能再add
12345678910
xiaobaoqiu@xiaobaoqiu:~$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
add sex 0 0 1
f
STORED
add sex 0 0 1
m
NOT_STORED
(3).replace:只有数据存在时替换的replace命令
只有存在才能replace:
123456789101112131415161718192021
xiaobaoqiu@xiaobaoqiu:~$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
replace host 0 0 9
localhost
NOT_STORED
add host 0 0 9
127.0.0.1
STORED
get host
VALUE host 0 9
127.0.0.1
END
replace host 0 0 9
localhost
STORED
get host
VALUE host 0 9
localhost
END
4.2删除命令
(1).delete:删除已经存在的数据
1234567891011
xiaobaoqiu@xiaobaoqiu:~$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
delete unknow
NOT_FOUND
add unknow 0 0 6
unknow
STORED
delete unknow
DELETED
4.3自增自减命令
incr和decr命令,注意只能在数字类型上进行自增自减操作
123456789101112131415161718
xiaobaoqiu@xiaobaoqiu:~$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set age 2 0 2
25
STORED
incr age 1
26
incr age 3
29
decr age 2
27
set name 1 0 11
baoqiu.xiao
STORED
incr name 1
CLIENT_ERROR cannot increment or decrement non-numeric value
4.4读取命令
(1).get:获取一条或者多条数据
12345678910111213141516
xiaobaoqiu@xiaobaoqiu:~$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
add name 1 0 11
baoqiu.xiao
STORED
add age 2 0 2
25
STORED
get name age
VALUE name 1 11
baoqiu.xiao
VALUE age 2 2
25
END
(2).gets:获取一条或者多条数据
gets命令比get返回的值多一个数字(类似于版本号)用来判断数据是否发生过改变.
123456
gets name age
VALUE name 1 11 12
baoqiu.xiao
VALUE age 2 2 13
25
END
xiaobaoqiu@xiaobaoqiu:~$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
gets name
VALUE name 1 11 19
baoqiu.xiao
END
cas name 1 0 9 20
memcached
EXISTS
cas name 1 0 9 19
memcached
STORED
xiaobaoqiu@xiaobaoqiu:~$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats
STAT pid 1241 //memcached服务进程的进程ID
STAT uptime 24026 //memcached服务从启动到当前所经过的时间,单位是秒
STAT time 1411579124 //memcached服务器所在主机当前系统的时间,单位是秒
STAT version 1.4.14 //memcached组件的版本
STAT libevent 2.0.21-stable //libevent版本
STAT pointer_size 64 //服务器所在主机操作系统的指针大小,一般为32或64
STAT rusage_user 0.404722 //进程累计使用用户时间
STAT rusage_system 0.313086 //进程累计使用系统时间
STAT curr_connections 5 //当前系统打开的连接数
STAT total_connections 21 //从memcached服务启动开始,系统打开过的连接总数
STAT connection_structures 6 //从memcached服务启动到现在,被服务器分配的连接结构数量
STAT reserved_fds 20 //
STAT cmd_get 15 //累积get命令次数
STAT cmd_set 22 //累积set命令次数
STAT cmd_flush 0 //累积flush命令次数
STAT cmd_touch 0 //
STAT get_hits 9 //命中次数,即get成功的次数
STAT get_misses 6 //miss次数,即get失败的次数
STAT delete_misses 2 //delete miss次数
STAT delete_hits 5 //delete 命中次数
STAT incr_misses 0 //incr miss次数
STAT incr_hits 2 //incr 命中次数
STAT decr_misses 0 //decr miss次数
STAT decr_hits 1 //decr命中次数
STAT cas_misses 0 //cas命令miss的次数
STAT cas_hits 1 //cas命令命中的次数
STAT cas_badval 1 //使用cas擦拭次数
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 968 //memcached服务器从网络读取的总的字节数
STAT bytes_written 706 //memcached服务器发送到网络的总的字节数
STAT limit_maxbytes 268435456 //memcached允许使用的最大字节,256M,见memcached.conf
STAT accepting_conns 1 //目前使用的连接数
STAT listen_disabled_num 0
STAT threads 4 //工作线程的总数量
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT bytes 373 //系统存储缓存对象所使用的存储空间,单位为字节
STAT curr_items 5 //当前缓存中存放的所有缓存对象的数量,不包括已删除的
STAT total_items 22 //自启动起所有缓存对象的数量,包括已删除的
STAT evictions 0 //从缓存移除的缓存对象数目,包括过期和空间不足时LRU移除
STAT reclaimed 0
END