redis键

  • 永远的帮助命令,help @类型
  • help @string
  • help @list
  • help @hash
  • help @hyperloglog
  1. 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"

  1. 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
  1. type key
    查看你的key是什么类型
127.0.0.1:6379> type k1
string
  1. 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"
  1. 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"
  1. ttl key
    查看还有多少秒过期,-1 表示永不过期,-2表示已过期
127.0.0.1:6379> ttl k1
(integer) -2
127.0.0.1:6379> ttl k2
(integer) -1
  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
  1. 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"
  1. select dbindex
    切换数据库[0-15],默认为0
127.0.0.1:6379> select 3
OK
127.0.0.1:6379[3]>
  1. 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
  1. 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"
  1. 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)

posted @ 2024-12-26 17:46  小肚腩吖  阅读(1)  评论(0编辑  收藏  举报