centos7_01_192.168.120.90:0>mset name v1 "OK" centos7_01_192.168.120.90:0>keys * 1) "name" #使用exists centos7_01_192.168.120.90:0>exists name "1" centos7_01_192.168.120.90:0>exists age "0" #使用expire和ttl centos7_01_192.168.120.90:0>expire name 20 "1" centos7_01_192.168.120.90:0>TTL name "15" centos7_01_192.168.120.90:0>TTL name "14" centos7_01_192.168.120.90:0>TTL name "9" centos7_01_192.168.120.90:0>TTL name "4" centos7_01_192.168.120.90:0>TTL name "2" centos7_01_192.168.120.90:0>TTL name "1" centos7_01_192.168.120.90:0>TTL name "0" centos7_01_192.168.120.90:0>TTL name "-2" centos7_01_192.168.120.90:0>TTL name "-2" centos7_01_192.168.120.90:0>TTL name "-2" centos7_01_192.168.120.90:0>TTL name "-2" centos7_01_192.168.120.90:0>TTL name "-2" # -2表示已经被删了 centos7_01_192.168.120.90:0>keys *
centos7_01_192.168.120.90:0> #没有用expire设置有效期,那么-1表示的是永久有效 centos7_01_192.168.120.90:0>set name Kevin "OK" centos7_01_192.168.120.90:0>ttl name "-1" centos7_01_192.168.120.90:0>
centos7_01_192.168.120.90:0>INCR age "19" centos7_01_192.168.120.90:0>get age "19" centos7_01_192.168.120.90:0>INCR age "20" centos7_01_192.168.120.90:0>get age "20" #INCRBY 设置每次增长多少 #设置为负数就是自减了 centos7_01_192.168.120.90:0>INCRBY age 2 "22" centos7_01_192.168.120.90:0>INCRBY age 2 "24" centos7_01_192.168.120.90:0>INCRBY age 2 "26" centos7_01_192.168.120.90:0>get age "26" centos7_01_192.168.120.90:0>INCRBY age -3 "23" centos7_01_192.168.120.90:0>INCRBY age -3 "20" centos7_01_192.168.120.90:0>get age "20" #setnx centos7_01_192.168.120.90:0>setnx name lli "0" centos7_01_192.168.120.90:0>get name "Jack" centos7_01_192.168.120.90:0>setnx name1 kevin "1" centos7_01_192.168.120.90:0>get name "Jack" centos7_01_192.168.120.90:0>get name1 "kevin" #set和nx是组合的,可以分开可以合起来 centos7_01_192.168.120.90:0>set name lucy nx null centos7_01_192.168.120.90:0>get name "Jack" #setex set和expire的组合 添加并设置有效期 centos7_01_192.168.120.90:0>setex name 10 jack "OK" centos7_01_192.168.120.90:0>ttl name "6" centos7_01_192.168.120.90:0>ttl name "3" centos7_01_192.168.120.90:0>ttl name "2" centos7_01_192.168.120.90:0>ttl name "1" centos7_01_192.168.120.90:0>ttl name "0" centos7_01_192.168.120.90:0>ttl name "-2" centos7_01_192.168.120.90:0>get name null #set和ex分开的 centos7_01_192.168.120.90:0>set name Jack ex 10 "OK" centos7_01_192.168.120.90:0>get name "Jack" centos7_01_192.168.120.90:0>ttl name "4" centos7_01_192.168.120.90:0>ttl name "3" centos7_01_192.168.120.90:0>ttl name "-2" centos7_01_192.168.120.90:0>get name null