Redis 中 Redisson 客户端的 MasterSlaveServersConfig 问题

issue on MasterSlaveServersConfig with Redisson client in Redis

提问人:sb-0205 提问时间:3/22/2023 更新时间:3/22/2023 访问量:145

问:

如何使用 redisson MasterSlaveServersConfig 时解决 bean 创建异常

这是适用于 useSingleServer 的代码片段

@Configuration
public class RedisConfig {
    @Bean
    public Config config() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://localhost:6379");
        return config;
    }

    @Bean(name = "springCM")
    public CacheManager cacheManager(Config config) {
        CacheManager manager = Caching.getCachingProvider().getCacheManager();
        manager.createCache("cache", RedissonConfiguration.fromConfig(config));
        manager.createCache("userList", RedissonConfiguration.fromConfig(config));
        return manager;
    }


    @Bean
    ProxyManager<String> proxyManager(CacheManager cacheManager) {
        return new JCacheProxyManager<>(cacheManager.getCache("cache"));
    }
}

我应该做什么修改才能使useMasterSlaveServers()工作。 我已经完成了以下操作,但是出现bean创建异常

@Bean(destroyMethod = "shutdown")
    RedissonClient redisson() throws IOException {
        Config config = new Config();
        config.useMasterSlaveServers()
                // use "rediss://" for SSL connection
                .setMasterAddress("redis://127.0.0.1:6379")
                .addSlaveAddress("redis://127.0.0.1:6389");
        return Redisson.create(config);
    }

    @Bean(name = "springCM")
    public CacheManager cacheManager(RedissonClient redissonClient) {
        CacheManager manager = Caching.getCachingProvider().getCacheManager();
        manager.createCache("cache", RedissonConfiguration.fromInstance(redissonClient));
        manager.createCache("userList", RedissonConfiguration.fromInstance(redissonClient));
        return manager;
    }

    @Bean
    ProxyManager<String> proxyManager(CacheManager cacheManager) {
        return new JCacheProxyManager<>(cacheManager.getCache("cache"));
    }
spring-boot redis redisson redis-cache

评论

0赞 Nikita Koksharov 4/17/2023
你能分享一下例外吗?

答: 暂无答案