spring-data-redis 使用

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

你可能感兴趣的:(spring-data-redis 使用)