package com.kexue.skills.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.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Redisson配置类
 *
 * @author 王志维
 * @since 2026-01-28
 */
@Configuration
public class RedissonConfig {

    @Value("${common.redis.host}")
    private String host;

    @Value("${common.redis.port}")
    private int port;

    @Value("${common.redis.password}")
    private String password;

    @Value("${common.redis.database}")
    private int database;

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient() {
        Config config = new Config();
        
        // 单节点模式
        config.useSingleServer()
                .setAddress("redis://" + host + ":" + port)
                .setPassword(password)
                .setDatabase(database)
                .setConnectionMinimumIdleSize(5)
                .setConnectionPoolSize(20)
                .setTimeout(10000);
        
        return Redisson.create(config);
    }

}
