127.0.0.1:6379> incr num (integer) 1 127.0.0.1:6379> get num "1" 127.0.0.1:6379> incr num (integer) 2 127.0.0.1:6379> get num "2" 127.0.0.1:6379>
如果不存在会设置初始值为0,然后+1
数字递减
1 2 3 4 5 6 7 8 9 10 11 12 13
127.0.0.1:6379> decr num (integer) 1 127.0.0.1:6379> get num "1" 127.0.0.1:6379> decr num (integer) 0 127.0.0.1:6379> get num "0" 127.0.0.1:6379> 127.0.0.1:6379> decr num (integer) -1 127.0.0.1:6379> get num "-1"
数字增加指定的值
1 2 3 4 5
127.0.0.1:6379> incrby num 5 (integer) 4 127.0.0.1:6379> incrby num 5 (integer) 9 127.0.0.1:6379>
数字减去指定的值
1 2 3 4 5 6 7
127.0.0.1:6379> decrby num 3 (integer) 6 127.0.0.1:6379> decrby num 3 (integer) 3 127.0.0.1:6379> decrby num 3 (integer) 0 127.0.0.1:6379>
拼接字符串
1 2 3 4
127.0.0.1:6379> append name laoli (integer) 13 127.0.0.1:6379> get name "zhangsanlaoli"
重命名KEY
1 2 3 4 5 6 7 8 9 10
127.0.0.1:6379> set a1 a1 OK 127.0.0.1:6379> get a1 "a1" 127.0.0.1:6379> rename a1 aa1 OK 127.0.0.1:6379> get a1 (nil) 127.0.0.1:6379> get aa1 "a1"
设置过期时间 单位秒
1 2 3 4 5 6 7 8
127.0.0.1:6379> get abc "abc" 127.0.0.1:6379> expire abc 10 (integer) 1 127.0.0.1:6379> get abc "abc" 127.0.0.1:6379> get abc (nil)
查看超时时间
1 2 3 4 5 6 7 8 9 10 11
127.0.0.1:6379> set abc abc OK 127.0.0.1:6379> get abc "abc" 127.0.0.1:6379> ttl abc (integer) -1 127.0.0.1:6379> expire abc 100 (integer) 1 127.0.0.1:6379> ttl abc (integer) 96 127.0.0.1:6379>
获取key存储的数据类型
1 2 3 4 5 6
127.0.0.1:6379> type abc string 127.0.0.1:6379> type mylist list 127.0.0.1:6379> type myset set