一、前言
剛剛接觸Redis不久,對項目中存在的幾個Bean都是幹嘛用的,一直不理解。這些Bean包括:redisConnectionFactory、redisTemplate、redisCacheManager和jedis。
1. redisConnectionFactory: 集中管理連接
2. redisTemplate:
2.1 原文:The template offers a high-level abstraction for Redis interactions. While RedisConnection offers low level methods that accept and return binary values
(byte arrays), the template takes care of serialization and connection management, freeing the user from dealing with such details.
2.2 說明:從2.1我們可以看出redisTemplate提供了一個更高抽象級別做交互。
3. redisCacheManager:
當我們把Redis作爲緩存使用時,可以結合Spring Cache相關。此時用到了redisCacheManager。
4. jedis
jedis客戶端,像操作數據庫一樣, 使用redis的原生命令執行操作。
疑問:爲什麼使用redisTemplate:官網上的回答:Once
configured, the template is thread-safe and can be reused across multiple instances.
二、RedisTemplate中提供的操作視圖
從上圖可以發現,redisTemplate提供了各種redis基本數據類型的操作。
三、官方文檔
四、關鍵詞等記錄
4.1 Redis高可用:RedisSentinelConfiguration
4.2 As with the other Spring
templates, RedisTemplate and StringRedisTemplate allow the developer to talk directly to Redis through the RedisCallback interface. This gives complete control to the developer as it talks directly to the RedisConnection. Note that the callback receives an
instance of StringRedisConnection when a StringRedisTemplate is used.
4.3 序列化相關