SpringDataRedis持续更新部分值使用方式

官方文档:https://docs.spring.io/spring-data/redis/docs/2.3.4.RELEASE/reference/html/#redis.repositories.partial-updates

SpringDataRedis文档13.9部分介绍了使用持续部分更新值的方式,但是文中的template对象并没有说明是Repository对象还是RedisKeyValueTemplate对象,所以,下面分析以下代码:

Redis提供了org.springframework.data.keyvalue.repository.KeyValueRepository仓库接口,对应的实现类:org.springframework.data.keyvalue.repository.support.SimpleKeyValueRepository

 

分析 SimpleKeyValueRepository 类:

 

 

 方法签名:org.springframework.data.keyvalue.core.KeyValueTemplate#insert(T objectToInsert) 

 

 

 

 

 

 

 先看以下execute的方法主体

 

 

 1:意思就是说函数接口Lambda表达式最终通过调用org.springframework.data.redis.core.RedisKeyValueAdapter#put方法

目前分析到这里

 

接下来分析RedisKeyValueTemplate实现类

 

 

 第一个update方法的super.update语句就是调用KeyValueTemplate实现类中转了一下

 上图是第一个update方法调用的中转的语句主题,最终调用的位置都是一样的

 

 

我们想使用Redis的持续更新部分值,那么就需要使用

PartialUpdate类

 

 

 上图是官方文档的使用说明。

 

 

所以操作Repository和操作RedisKeyValueTemplate类的功能不会少,就是 通知事件,更新生存时间都会进而更新的,,,

 

 

以上内容都是通过代码排查,并未进行过精确的Debug分析,如有错误,请提醒

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章