- keys *
查看当前库所有的key
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k2 v2
OK
127.0.0.1:6379> keys *
1) "k2"
2) "k1"
- exists key
判断某个key是否存在
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k2 v2
OK
127.0.0.1:6379> exists k1
(integer) 1
127.0.0.1:6379> exists k3
(integer) 0
- type key
查看你的key是什么类型
127.0.0.1:6379> type k1
string
- del key
删除指定的key数据
127.0.0.1:6379> keys *
1) "k2"
2) "k1"
127.0.0.1:6379> del k1
(integer) 1
127.0.0.1:6379> keys *
1) "k2"
- unlink key
非阻塞删除,仅仅将keys从keyspace元数据中删除,真正的删除会在后续异步中操作
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k2 v2
OK
127.0.0.1:6379> keys *
1) "k1"
2) "k2"
127.0.0.1:6379> unlink k1
(integer) 1
127.0.0.1:6379> keys *
1) "k2"
- ttl key
查看还有多少秒过期,-1 表示永不过期,-2表示已过期
127.0.0.1:6379> ttl k1
(integer) -2
127.0.0.1:6379> ttl k2
(integer) -1
- expire key 秒钟
为给定的key设置过期时间
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> expire k1 5
(integer) 1
127.0.0.1:6379> ttl k1
(integer) 2
127.0.0.1:6379> ttl k1
(integer) 1
127.0.0.1:6379> ttl k1
(integer) -2
- move key dbindex[0-15]
将当前数据库的key移动到给定的数据库db当中
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> keys *
1) "k1"
2) "k2"
127.0.0.1:6379> move k1 3
(integer) 1
127.0.0.1:6379> keys *
1) "k2"
127.0.0.1:6379> select 3
OK
127.0.0.1:6379[3]> keys *
1) "k1"
- select dbindex
切换数据库[0-15],默认为0
127.0.0.1:6379> select 3
OK
127.0.0.1:6379[3]>
- dbsize
查看当前数据库key的数量
127.0.0.1:6379[3]> dbsize
(integer) 1
127.0.0.1:6379[3]> set k2 v2
OK
127.0.0.1:6379[3]> dbsize
(integer) 2
- flushdb
清空当前库
127.0.0.1:6379[3]> flushdb
OK
127.0.0.1:6379[3]> keys *
(empty array)
127.0.0.1:6379[3]> select 0
OK
127.0.0.1:6379> keys *
1) "k2"
- flushall
通杀全部库
127.0.0.1:6379> select 3
OK
127.0.0.1:6379[3]> set k2 v2
OK
127.0.0.1:6379[3]> flushall
OK
127.0.0.1:6379[3]> keys *
(empty array)
127.0.0.1:6379[3]> select 0
OK
127.0.0.1:6379> keys *
(empty array)
标签:127.0,OK,k2,0.1,redis,6379,k1
From: https://www.cnblogs.com/xiaodunan/p/18633825