content: package com.xzll.common.config;
  
  import org.redisson.Redisson;
  import org.redisson.api.RedissonClient;
  import org.redisson.config.Config;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Primary;
  
  /**
   * Redisson配置类
   * 用于配置Redisson客户端
   */
  @Configuration
  @ConditionalOnProperty(name = "spring.redis.host")
  public class RedissonConfig {
  
      @Value("${spring.redis.host:localhost}")
      private String host;
  
      @Value("${spring.redis.port:6379}")
      private int port;
  
      @Value("${spring.redis.database:0}")
      private int database;
  
      @Value("${spring.redis.password:}")
      private String password;
  
      @Value("${spring.redis.timeout:10000}")
      private int timeout;
  
      @Value("${spring.redis.lettuce.pool.max-active:64}")
      private int maxActive;
  
      @Value("${spring.redis.lettuce.pool.max-idle:10}")
      private int maxIdle;
  
      @Value("${spring.redis.lettuce.pool.min-idle:0}")
      private int minIdle;
  
      @Bean
      @Primary
      public RedissonClient redissonClient() {
          Config config = new Config();
          
          // 单机模式配置
          config.useSingleServer()
                  .setAddress("redis://" + host + ":" + port)
                  .setDatabase(database)
                  .setConnectionPoolSize(maxActive)
                  .setConnectionMinimumIdleSize(minIdle)
                  .setConnectTimeout(timeout)
                  .setIdleConnectionTimeout(10000)
                  .setRetryAttempts(3)
                  .setRetryInterval(1500)
                  .setKeepAlive(true)
                  .setTcpNoDelay(true);
          
          // 如果有密码，设置密码
          if (password != null && !password.isEmpty()) {
              config.useSingleServer().setPassword(password);
          }
          
          return Redisson.create(config);
      }
  } 