redis set设置有效时间问题

今天查看redis数据库数据的,无意中发现一条本应该删掉的set数据还一直存在,以为是代码的bug没有给数据设置有效值,结果重新啃了半天的代码,发现都在初始化的时候设置了有效值,经过多次试验发现,set结构的数据在更新数据的时候,会重置有效期,于是去官网上看了下:

The timeout will only be cleared by commands that delete or overwrite the contents of the key, including DEL, SET, GETSET and all the *STORE commands. This means that all the operations that conceptually alter the value stored at the key without replacing it with a new one will leave the timeout untouched. For instance, incrementing the value of a key with INCR, pushing a new value into a list with LPUSH, or altering the field value of a hash with HSET are all operations that will leave the timeout untouched.

这句话的意思就是类似于del、set、getset等所有重写或者是删除的命令都会重置key的有效时间,但是类似于incr、lpush、hset等概念上更改key的值则不会改变有效时间。

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值