# RedissonConfig.java

    package cloud.wconnect.frontoffice.config;

    import jakarta.annotation.PostConstruct;
    import org.redisson.Redisson;
    import org.redisson.api.RedissonClient;
    import org.redisson.codec.JsonJacksonCodec;
    import org.redisson.config.Config;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;

    /**
     * Redisson 配置
     *
     * @author lichen
     * @date 2025/3/13
     */
    @Configuration
    public class RedissonConfig {

        @Value("${spring.data.redis.host}")
        private String redisHost;

        @Value("${spring.data.redis.port}")
        private int redisPort;

        @Value("${spring.data.redis.password:}")
        private String redisPassword;

        @Value("${spring.data.redis.database:0}")
        private int redisDatabase;

        @PostConstruct
        private void init() {
            redisPassword = redisPassword.isEmpty() ? null : redisPassword;
        }

        /**
         * 注入RedissonClient配置
         *
         * @return org.redisson.api.RedissonClient
         * @author lichen
         * @date 2025/3/13
         */
        @Bean
        public RedissonClient redissonClient() {
            Config config = new Config();
            config.setCodec(new JsonJacksonCodec());
            String address = String.format("redis://%s:%d", redisHost, redisPort);
            config.useSingleServer()
                    .setAddress(address)
                    .setPassword(redisPassword)
                    .setDatabase(redisDatabase)
                    //定义Redis服务器响应的超时时间，单位为毫秒，默认值为2000毫秒（即2秒）
                    .setTimeout(2000)
                    //定义了一个Redis连接池的最大池大小，用于限制Redis连接池中同时存在的最大连接数
                    .setConnectionPoolSize(10)
                    //定义了一个Redis连接的最小空闲连接数，用于保持Redis连接池中的最小空闲连接数，默认值为0
                    .setConnectionMinimumIdleSize(5);
            return Redisson.create(config);
        }

    }