spring-redis-data的一个坑

事故原因:

运维报告redis内存直线上升,然后查询发现都是setrange操作,review代码,没法发现setrange操作

代码如下:

redisTemplate.opsForValue().set(groupid+xxxResult.getSeriesNo(), JSON.toJSONString(xxxRquestDTO),1000*60L)

赶紧查一下api:

set(K key, V value, long offset)

Overwrite parts of key starting at the specified offset with given value.
 
开发的本意设置超时时间,改成这个api:
set(K key, V value, long timeout, TimeUnit unit)
Set the value and expiration timeout for key.
快速上线后问题解决。
 
分析:
1. set(K key, V value, long offset) 这个存储键值是以range的
2.spring重写的这个和set(K key, V value, long timeout, TimeUnit unit) 太容易让人误解了
3.其实中间件封装好了,不需要设置时间单元,但因这次是旧项目改造,直接使用spring-data-redis导致的。
原文地址:https://www.cnblogs.com/davidwang456/p/8807370.html