Redis 常用命令之-----键值命令
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis 常用命令之-----键值命令相关的知识,希望对你有一定的参考价值。
欢迎大家加入 459479177QQ群进行交流
键值命令
这里就不介绍方法与描述啦,自己看例子
1、keys 查看key
127.0.0.1:6379> keys * 1) "skey2" 2) "skey1" 3) "name" 4) "zkey1" 127.0.0.1:6379> keys s* 1) "skey2" 2) "skey1"
2、del删除key
127.0.0.1:6379> keys * 1) "skey2" 2) "skey1" 3) "name" 4) "zkey1" 127.0.0.1:6379> del name (integer) 1 127.0.0.1:6379> keys * 1) "skey2" 2) "skey1" 3) "zkey1" 127.0.0.1:6379> del skey2 skey1 (integer) 2 127.0.0.1:6379> keys * 1) "zkey1"
3、dump序列号key并返回
127.0.0.1:6379> zadd zkey 3 sunshine 5 sunshineboy (integer) 2 127.0.0.1:6379> ZRANGE zkey 1 2 withscores 1) "sunshineboy" 2) "5" 127.0.0.1:6379> dump zkey "\x0c&&\x00\x00\x00#\x00\x00\x00\x04\x00\x00\bsunshine\n\xf4\x02\x0bsunshineboy\r\xf6\xff\x06\x00\xddX6\xa7I\x85\x00\x91"
4、exists测试key是否存在
127.0.0.1:6379> keys * 1) "zkey" 127.0.0.1:6379> exists zkey (integer) 1 127.0.0.1:6379> exists zkey1 (integer) 0
5、expire设置过期时间
127.0.0.1:6379> keys * 1) "zkey" 127.0.0.1:6379> expire zkey 10 (integer) 1 127.0.0.1:6379> ttl zkey (integer) 5 127.0.0.1:6379> ttl zkey (integer) -2 127.0.0.1:6379> keys * (empty list or set)
6、persist取消设定的过期时间
127.0.0.1:6379> zadd zkey1 1 sunshine (integer) 1 127.0.0.1:6379> keys * 1) "zkey1" 127.0.0.1:6379> EXPIRE zkey1 200 (integer) 1 127.0.0.1:6379> ttl zkey1 (integer) 195 127.0.0.1:6379> ttl zkey1 (integer) 193 127.0.0.1:6379> PERSIST zkey1 (integer) 1 127.0.0.1:6379> ttl zkey1 (integer) -1 127.0.0.1:6379> keys * 1) "zkey1"
7、move把当前数据库的key移动到指定的数据库去
127.0.0.1:6379> select 1 OK 127.0.0.1:6379[1]> keys * (empty list or set) 127.0.0.1:6379[1]> select 0 OK 127.0.0.1:6379> keys * 1) "zkey1" 127.0.0.1:6379> MOVE zkey1 1 (integer) 1 127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> select 1 OK 127.0.0.1:6379[1]> keys * 1) "zkey1"
8、pexpire设置过期时间单位毫秒
127.0.0.1:6379[1]> PEXPIRE zkey1 8000000 (integer) 1 127.0.0.1:6379[1]> PTTL zkey1 (integer) 7992155
9、pttl以毫秒为单位返回
127.0.0.1:6379[1]> PEXPIRE zkey1 8000000 (integer) 1 127.0.0.1:6379[1]> PTTL zkey1 (integer) 7992155
10、ttl以秒为单位返回
127.0.0.1:6379[1]> EXPIRE zkey1 9000 (integer) 1 127.0.0.1:6379[1]> ttl zkey1 (integer) 8995
11、randomkey随机弹出当前库的key
127.0.0.1:6379[1]> keys * 1) "lkey" 2) "lkey1" 3) "zkey1" 127.0.0.1:6379[1]> RANDOMKEY "zkey1" 127.0.0.1:6379[1]> RANDOMKEY "zkey1" 127.0.0.1:6379[1]> RANDOMKEY "lkey"
12、rename修改当前库key的名称,成功返回0
127.0.0.1:6379[1]> keys * 1) "lkey" 2) "lkey1" 3) "zkey1" 127.0.0.1:6379[1]> RENAME zkey1 zzkey1 OK 127.0.0.1:6379[1]> keys * 1) "zzkey1" 2) "lkey" 3) "lkey1"
13、renamenx修改当前库key的名称,仅仅适用于key存在
127.0.0.1:6379[1]> keys * 1) "zzkey1" 2) "lkey" 3) "lkey1" 127.0.0.1:6379[1]> RENAMENX zzkey1 zkey1 (integer) 1 127.0.0.1:6379[1]> keys * 1) "lkey" 2) "zkey1" 3) "lkey1" 127.0.0.1:6379[1]> RENAMENX zzkey1 newzkey1 (error) ERR no such key 127.0.0.1:6379[1]> keys * 1) "lkey" 2) "zkey1" 3) "lkey1"
14、type查看当前key键值的存储类型
127.0.0.1:6379[1]> keys * 1) "lkey" 2) "zkey1" 3) "lkey1" 127.0.0.1:6379[1]> TYPE lkey list 127.0.0.1:6379[1]> TYPE zkey1 zset
键值命令就介绍完毕啦!~
欢迎大家加入 459479177QQ群进行交流
本文出自 “SunshineBoySZF” 博客,请务必保留此出处http://sunshineboyszf.blog.51cto.com/12087328/1856909
以上是关于Redis 常用命令之-----键值命令的主要内容,如果未能解决你的问题,请参考以下文章