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 Details

  • 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