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