Telnet操作memcached

telnet登录

#telnet <ip> 11211

[root@c1 ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

set

set在memcached中添加一个key->value,如果这个key之前已经存在,那么就会替换,否则就是添加

语法set <key> 0(是否需要压缩)  60(过期时间s)  6(字符的长度)

#设置username的值为heboan, 不压缩,过期时间为60s,字符长度为6
set username 0 60 6
heboan
STORED

get

从memecached中根据key来获取值

语法: get <key>

get username
VALUE username 0 6
heboan
END

add

add在memcached中添加一个key->value,如果memcached中已经存在了这个key,那么就添加失败,否则添加成功

语法和set一样

set username 0 60 6
heboan
STORED
add username 0 60 6
heboan
NOT_STORED      #username已经存在,添加失败
add love 0 60 8
12345678
STORED      #love之前不存在,添加成功

delete

语法: delete <key>

set username 0 60 6
heboan
STORED
delete username  #删除username
DELETED  
get username   #删除后,username不存在了
END

flush_all

删除memcached 中所有的数据

set book 0 120 6
python
STORED

set username 0 120 6
heboan
STORED

flush_all
OK

get book
END
get username
END

incr

整数自增

语法: incr <key> num(相加的值)

set age 0 120 2
18
STORED
incr age 2
20
incr age 1
21

decr

整数相减

set age 0 120 2
18
STORED
decr age 2
16
decr age 6
10

stats

查看memcached的状态

STAT pid 2373
STAT uptime 3214
STAT time 1533343756
STAT version 1.4.15
STAT libevent 2.0.21-stable
STAT pointer_size 64
STAT rusage_user 0.037207
STAT rusage_system 0.186036
STAT curr_connections 10
STAT total_connections 16
STAT connection_structures 11
STAT reserved_fds 20
STAT cmd_get 7
STAT cmd_set 11
STAT cmd_flush 1
STAT cmd_touch 0
STAT get_hits 1
STAT get_misses 6
STAT delete_misses 0
STAT delete_hits 1
STAT incr_misses 0
STAT incr_hits 2
STAT decr_misses 0
STAT decr_hits 2
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 981
STAT bytes_written 855
STAT limit_maxbytes 67108864
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 bytes 70
STAT curr_items 1
STAT total_items 14
STAT expired_unfetched 2
STAT evicted_unfetched 0
STAT evictions 0
STAT reclaimed 4
stats

 

posted @ 2018-08-03 23:04  sellsa  阅读(245)  评论(0编辑  收藏  举报