redis数据类型

[root@localhost bin]# /usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379
登录数据库

redis提供五种数据类型。

127.0.0.1:6379> set name lishi  #添加一个name=lishi的键值对应
OK
127.0.0.1:6379> get name  #获取name键的值
"lishi"
127.0.0.1:6379> set name linux  #重新赋值。
OK
127.0.0.1:6379> 

设置key对应的值为string类型的value, 如果key已经存在,则返回0,nx是not exist的意思。
127.0.0.1:6379> setnx name lishi
(integer) 0
setex设置key对应的值为string类型的value,并制定此值对应的有效期。
添加一个age=18的键值对,并且指定有效期为10秒

127.0.0.1:6379> setex age 10 18
OK
127.0.0.1:6379> get age
"18"
127.0.0.1:6379> get age
(nil)
posted @ 2019-12-26 20:48  星火撩原  阅读(75)  评论(0编辑  收藏  举报