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分析,如有錯誤,請提醒

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