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

 

posted on 2015-09-18 11:50  一天不进步,就是退步  阅读(1207)  评论(0编辑  收藏  举报