Class KnoluxRedisAutoConfiguration
java.lang.Object
com.knolux.redis.KnoluxRedisAutoConfiguration
@AutoConfiguration
@EnableConfigurationProperties(KnoluxRedisProperties.class)
public class KnoluxRedisAutoConfiguration
extends Object
Redis 自動設定。
根據 knolux.redis.url 的 URL scheme 自動建立下列 Bean:
LettuceConnectionFactory— 連線工廠StringRedisTemplate— 字串操作模板RedisTemplate— 物件操作模板(key 與 hash key 使用字串序列化)
支援兩種連線模式:
redis://— Standalone 直連模式redis-sentinel://— Sentinel 高可用模式
所有 Bean 均標注 ConditionalOnMissingBean,
可由使用者定義同型別的 Bean 覆寫預設行為。
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.data.redis.connection.lettuce.LettuceConnectionFactory建立LettuceConnectionFactory。redisTemplate(org.springframework.data.redis.connection.RedisConnectionFactory factory) 建立通用RedisTemplate,key 與 hash key 使用StringRedisSerializer。org.springframework.data.redis.core.StringRedisTemplatestringRedisTemplate(org.springframework.data.redis.connection.RedisConnectionFactory factory) 建立StringRedisTemplate,適用於純字串型 key/value 操作。
-
Constructor Details
-
KnoluxRedisAutoConfiguration
-
-
Method Details
-
redisConnectionFactory
@Bean @ConditionalOnMissingBean(org.springframework.data.redis.connection.RedisConnectionFactory.class) public org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory redisConnectionFactory()建立LettuceConnectionFactory。根據
knolux.redis.url的 scheme 判斷模式:redis://使用 Standalone,redis-sentinel://使用 Sentinel。- Returns:
- 設定好的
LettuceConnectionFactory - Throws:
IllegalArgumentException- 若knolux.redis.url未設定或為空
-
stringRedisTemplate
@Bean @ConditionalOnMissingBean(org.springframework.data.redis.core.StringRedisTemplate.class) public org.springframework.data.redis.core.StringRedisTemplate stringRedisTemplate(org.springframework.data.redis.connection.RedisConnectionFactory factory) 建立StringRedisTemplate,適用於純字串型 key/value 操作。- Parameters:
factory- Redis 連線工廠- Returns:
- 設定好的
StringRedisTemplate
-
redisTemplate
@Bean @ConditionalOnMissingBean(name="redisTemplate") public org.springframework.data.redis.core.RedisTemplate<String,Object> redisTemplate(org.springframework.data.redis.connection.RedisConnectionFactory factory) 建立通用RedisTemplate,key 與 hash key 使用StringRedisSerializer。- Parameters:
factory- Redis 連線工廠- Returns:
- 設定好的
RedisTemplate
-