以前使用过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);

微信公众号: 架构师日常笔记 欢迎关注!
浙公网安备 33010602011771号