memcached键值对操作

(0)quit 退出memcache
(1)set
set key flags exptime bytes 【noreply】
value
flags 可以包括键值对的整型参数,客户机使用它存储关于键值对的额外信息
exptime 缓存时间,单位是秒,0表示永远
bytes 缓存中存储的字节数
noreply 告知服务不需要返回数据
返回结果:stored、error

set userId 0 0 5
12345
STORED

(2)add(用于添加不存在的键,如果存在,在不改变键值)
用法和set相同
(3)replace(替换已经存在的键值,如果不存在,替换失败)
语法和set相同
(4)append  向后追加(用于对已存在的键追加值)
语法和set相同
(5)prepend 向前追加(用于已存在的键)
(6)cas (check and set) 用于执行一个检查并设置的操作,用于已存在 键
cas key flags exptime bytes  unique_cas_token【noreply】
value

set c 0 900 9  
memcached
STORED
gets c
VALUE c 0 9 6 //6位token值
memcached
END
cas c 0 900 5 6
abcde
STORED
get c
VALUE c 0 5
abcde
END
(7)get  用于查看,可跟多个键
set userId 0 0 5
STORED
get userId
VALUE userId 0 5
END


(8)gets  可以得到cas需要的token值
gets userId
VALUE userId 0 5 4
12345
END

(9)delete key
(10)incr key 5
(11)decr key 5
(12)stats 显示当前memcache的统计数据
(13)flush_all  清空所有键值对
发布了76 篇原创文章 · 获赞 60 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_43557605/article/details/104182424