expire : 设置给定键多少秒后过期
ttl : 查看给定的键还有多少秒
pttl : 查看给定的键还有多少毫秒
persist : 移除键的过期时间,即 持久
expireat : 设定给定键在unix时间戳为过期时间
pexpire : 设置给定键多少毫秒后过期
pexpireat : 设置给定键多少unix时间戳的毫秒后过期
127.0.0.1:6379> set age 18# expire : 设置给定键多少秒后过期,下例:表示60秒后过期
127.0.0.1:6379> expire age 60# ttl : 查看给定的键还有多少秒
127.0.0.1:6379> ttl age# pttl : 查看给定的键还有多少毫秒
127.0.0.1:6379> pttl age# persist : 移除键的过期时间,即 持久
127.0.0.1:6379> persist age# expireat : 设定给定键在unix时间戳为过期时间
127.0.0.1:6379> expireat age 1669640818# pexpire : 设置给定键多少毫秒后过期
127.0.0.1:6379> pexpire age 60000# pexpireat : 设置给定键多少unix时间戳的毫秒后过期
127.0.0.1:6379> pexpireat age 1669640818000
multi : 表示事务开始
exec : 表示事务输入完毕,开始执行
discard : 表示放弃之前输入的命令,并关闭事务,清除事务的上下文。
watch : 监视一个key或多个key,如果事务执行之前被其他命令改动,则事务将会被打断。
unwatch : 解除监视一个key或多个key
127.0.0.1:6379> set age 30
127.0.0.1:6379> set weight 85
127.0.0.1:6379> set height 175
127.0.0.1:6379> multi
127.0.0.1:6379> incr age
127.0.0.1:6379> incr weight
127.0.0.1:6379> incr height
127.0.0.1:6379> exec
31
86
176
127.0.0.1:6379> set age 30
127.0.0.1:6379> set weight 85
127.0.0.1:6379> set height 175
127.0.0.1:6379> multi
127.0.0.1:6379> incr age
127.0.0.1:6379> incr weight
127.0.0.1:6379> incr height
127.0.0.1:6379> discard
127.0.0.1:6379> get age
30
这里涉及到乐观锁的概念,乐观锁严格意义上来说是一种监视的方法,再配合某种语言的重试的机制可以实现在一段时间内的重试的功能。
乐观锁的实现就是使用了版本的机制。
127.0.0.1:6379> set age 200
127.0.0.1:6379> watch age
127.0.0.1:6379> multi# 另外启动一个客户端去修改age
第二个客户端 127.0.0.1:6379> set age 300# 然后在原来的客户端执行下面语句
127.0.0.1:6379> set age 100
127.0.0.1:6379> exec
127.0.0.1:6379> get age
300
上一篇:【前端】HTML认知
下一篇:Yolov5算法解读