以前使用过Jedis,后面因项目需要使用spring-data-redis,设置一个键值及其过期时间后怎么都不对。

源代码:

redisTemplate.opsForValue().set(key, value,100l);

于是,不得不翻出api:

Overwrite parts of key starting at the specified offset with given value.

才发现第三个参数不是timeout,而是offset。

正确的代码应该是:

redisTemplate.opsForValue().set(key, value,timeout,TimeUnit.SECONDS);

 

相关文章:

  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2022-01-11
  • 2021-06-02
猜你喜欢
  • 2021-12-08
  • 2021-12-29
相关资源
相似解决方案