网络上有一些设置键的过期时间的代码:

this.redisTemplate.opsForValue().set("max", tempCount);
this.redisTemplate.expire("max",tempTime,TimeUnit.SECONDS);

这对应的Redis命令中的set和expire

然而,Redis中还有一条setex命令可以直接设置有过期时间的key

在RedisTemplate中直接被划入了set的重载方法中

redisTemplate.opsForValue().set(codeKey, code, 20, TimeUnit.SECONDS);

表示20秒过期,可以设置时间的计数单位,有分,小时,年,月,日等

相关文章:

  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2021-05-15
  • 2021-07-09
  • 2022-02-18
  • 2021-07-24
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案