Redis教程

RedissonConfProperty

本文主要是介绍RedissonConfProperty,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
@Configuration
public class RedissonConfProperty {

    @Value("${spring.redis.cluster.nodes:}")
    private String clusters;

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

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

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

    /**
     * RedissonClient bean
     *
     * @return RedissonClient
     * @throws IOException IOException
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() throws IOException {
        // 1、创建配置
        Config config = new Config();
        if (!StringUtils.isEmpty(clusters)) {
            String[] clusterNodes = clusters.split(",");
            for (int i = 0; i < clusterNodes.length; i++) {
                clusterNodes[i] = "redis://" + clusterNodes[i];
            }
            config.setCodec(new JsonJacksonCodec())
                .useClusterServers()
                .addNodeAddress(clusterNodes)
                .setPassword(redisPassword)
                .setSlaveConnectionMinimumIdleSize(24)
                .setMasterConnectionMinimumIdleSize(24);
        } else {
            config.setCodec(new JsonJacksonCodec())
                .useSingleServer()
                .setAddress("redis://" + redisHost + ":" + redisPort)
                .setPassword(redisPassword);
        }
        return Redisson.create(config);
    }
}
这篇关于RedissonConfProperty的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!