zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

spring-data-redis 使用

RedisSpring Data 使用
2023-09-11 14:21:41 时间

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