package com.fs.core.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;

@Configuration
public class RedissonConfig {

    @Value("${spring.redis.port}")
    private String port;

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

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

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient() {
        String address = "redis://" + host + ":" + port;
        Config config = new Config();
        config.useSingleServer()
                .setAddress(address) // 设置连接地址
                .setConnectionMinimumIdleSize(10) // 最小空闲连接数
                .setConnectionPoolSize(64); // 最大连接数
        if (null!=password&&!"".equals(password)) {
            config.useSingleServer().setPassword(password);
        }
        return Redisson.create(config);
    }

}
