首页 > 解决方案 > 如何向 Redis 集群发布/订阅消息

问题描述

我的项目使用 Redis(Jedis 客户端)作为缓存管理器。这是我用来操纵与redis集群的连接的bean

@Bean(destroyMethod = "close")
    @ConditionalOnProperty(value = "spring.cache.type", havingValue = "redis")
    public JedisCluster jedisCluster(@Value("${spring.redis.host}") String host,
                                     @Value("${spring.redis.port}") int port,
                                     @Value("${spring.redis.password}") String password) {
        Set<HostAndPort> jedisClusterNode = new HashSet<>();
        jedisClusterNode.add(new HostAndPort(host, port));
        JedisPoolConfig defaultConfig = new JedisPoolConfig()
        return new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT,
                DEFAULT_REDIRECTIONS, kcService.getKey(password), "lhs_redis", defaultConfig);
    }

现在我想使用 Redis 的 pub/sub 功能,基于此链接https://medium.com/@bhanuchaddha/using-redis-pub-sub-with-spring-boot-ea0d7a8c27af看起来他们可以为独立的 redis 做.

那么有人知道如何为 Redis 集群设置 Pub/Sub 吗?

谢谢

标签: javaspring-bootredisjedis

解决方案


推荐阅读