转自:http://blog.java1234.com/blog/articles/321.html
Redis Keys的通用操作
keys * 显示所有key
127.0.0.1:6379> keys *
1) "sort1"
2) "l2"
3) "set2"
4) "r1"
5) "h1"
6) "n2"
7) "l3"
8) "r2"
9) "s1"
10) "set3"
11) "set1"
12) "r3"
13) "n"
14) "n3"
15) "nn"
16) "l1"
查找所有以s开头的key
用s* *代表任意字符
127.0.0.1:6379> keys s*
1) "sort1"
2) "set2"
3) "s1"
4) "set3"
5) "set1"
查找所有s开头 后面紧跟任意一个字符的key
127.0.0.1:6379> keys s?
1) "s1"
del删除key
127.0.0.1:6379> del n2 n3 nn
(integer) 3
exists判断key是否存在 1表示存在 0表示不存在
127.0.0.1:6379> exists n2
(integer) 0
127.0.0.1:6379> exists l1
(integer) 1
get获取元素
127.0.0.1:6379> get n
"1"
rename对key重命名
127.0.0.1:6379> rename n n2
OK
127.0.0.1:6379> get n
(nil)
127.0.0.1:6379> get n2
"1"
expire 设置n2 有效时间
127.0.0.1:6379> expire n2 120
(integer) 1
ttl查看剩余时间
127.0.0.1:6379> ttl n2
(integer) 116
type显示类型
127.0.0.1:6379> type n2
string
127.0.0.1:6379> type l1
list
127.0.0.1:6379> type s1
string
127.0.0.1:6379> type sort1
zset