|NO.Z.00013|——————————|BigDataEnd|——|Hadoop&Redis.V13|——|Redis.v13|常用命令|

一、Redis常用命令
### --- Redis官方地址

~~~     官方命令大全网址:http://www.redis.cn/commands.html
~~~     keys:返回满足给定pattern 的所有key
~~~     语法:keys pattern
~~~     # 示例:

127.0.0.1:6379>  keys list*
1) "list:2"
2) "list:1"
### --- del
~~~     语法:DEL key

~~~     # 示例:
127.0.0.1:6379> del test
(integer) 1
### --- exists:确认一个key 是否存在
~~~     语法:exists key

~~~     # 示例:从结果来看,数据库中不存在HongWan 这个key ,但是age 这个key 是存在的
127.0.0.1:6379>  exists HongWan
(integer) 1
127.0.0.1:6379> exists age
(integer) 0
### --- expire:
~~~     Redis在实际使用过程中更多的用作缓存,
~~~     然而缓存的数据一般都是需要设置生存时间的,即:到期后数据销毁。

~~~     # 语法:
~~~     EXPIRE key seconds 设置key的生存时间(单位:秒)key在多少秒后会自动删除
~~~     TTL key 查看key生于的生存时间
~~~     PERSIST key 清除生存时间
~~~     PEXPIRE key milliseconds 生存时间设置单位为:毫秒
~~~     # 示例:
redis 127.0.0.1:6379> set test 1        // 设置test的值为1
OK
redis 127.0.0.1:6379> get test          // 获取test的值
"1"
redis 127.0.0.1:6379> EXPIRE test 5     // 设置test的生存时间为5秒
(integer) 1
redis 127.0.0.1:6379> TTL test          //  查看test的生于生成时间还有1秒删除
(integer) 1
redis 127.0.0.1:6379> TTL test
(integer) -2
redis 127.0.0.1:6379> get test          //  获取test的值,已经删除
(nil)
### --- rename:重命名key
~~~     语法:rename oldkey newkey

~~~     # 示例: age 成功的被我们改名为age_new 了
redis 127.0.0.1:6379> keys *
1) "name"
127.0.0.1:6379> rename name name_new
OK
redis 127.0.0.1:6379> keys *
"name_new"
### --- type:显示指定key的数据类型
~~~     语法:type key

~~~     # 示例:这个方法可以非常简单的判断出值的类型
redis 127.0.0.1:6379> type addr
string
redis 127.0.0.1:6379> type myzset2
zset
redis 127.0.0.1:6379> type mylist
list

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

posted on   yanqi_vip  阅读(20)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示