十九、键值和服务器命令
127.0.0.1:6379> keys *            #列出所有键值
1) "key3"
2) "seta"
3) "hash1"
4) "list1"
5) "key2"
6) "zset1"
7) "mset2"
8) "set2"
9) "set1"
10) "key1"
11) "hash2"

12) "set3"

127.0.0.1:6379> keys key*    //模糊匹配

1) "key3"
2) "key2"
3) "key1"

127.0.0.1:6379> EXISTS list1      #查看是否有list1
(integer) 1
127.0.0.1:6379> del key1      #删除key1
(integer) 1
127.0.0.1:6379> EXISTS key1
(integer) 0

127.0.0.1:6379> EXPIRE key3 10     #设置过期时间
(integer) 1
127.0.0.1:6379> get key3
"3"
127.0.0.1:6379> ttl key3    #查看key的过期时间,-1不存在过期  -2不存储键值
(integer) -2
127.0.0.1:6379> EXists key3 
(integer) 0

127.0.0.1:6379> select 0     #切换库,默认16个库
OK
127.0.0.1:6379> select 1
OK

127.0.0.1:6379[1]> set key1 111   #新建一个键值
OK
127.0.0.1:6379[1]> keys *
1) "key1"
127.0.0.1:6379[1]> move set1 2    #移动到库2
(integer) 0
127.0.0.1:6379[1]> select 2     #切换库2
OK
127.0.0.1:6379[2]> keys *    
1) "key1"


127.0.0.1:6379[2]> EXPIRE key1 200    #设置过期时间
(integer) 1
127.0.0.1:6379[2]> ttl key1
(integer) 193
127.0.0.1:6379[2]> PERSIST key1     #取消过期时间
(integer) 1
127.0.0.1:6379[2]> ttl key1
(integer) -1
127.0.0.1:6379[2]> RANDOMKEY    #随机返回一个key
"key1"

127.0.0.1:6379[2]> RENAME key1 szk   #更改一个key的名字
OK
127.0.0.1:6379[2]> keys *
1) "szk"
127.0.0.1:6379[2]> type szk         #查看一个键值的类型

string