@Override
    public int addListener(StatusListener listener) {
        RFuture<Integer> future = addListenerAsync(listener);
        return commandExecutor.get(future.toCompletableFuture());
    }
@Test
    public void testReattachPatternTopicListenersOnClusterFailover() {
        withNewCluster((nodes2, redisson) -> {
            RedisCluster nodes = redisson.getRedisNodes(RedisNodes.CLUSTER);
            for (RedisClusterMaster master : nodes.getMasters()) {
                master.setConfig("notify-keyspace-events", "K$");
            }
            for (RedisClusterSlave slave : nodes.getSlaves()) {
                slave.setConfig("notify-keyspace-events", "K$");
            }

            AtomicInteger subscriptions = new AtomicInteger();
            AtomicInteger messagesReceived = new AtomicInteger();

            RPatternTopic topic =
                    redisson.getPatternTopic("__keyspace*__:i*", StringCodec.INSTANCE);
            topic.addListener(new PatternStatusListener() {
                @Override
                public void onPUnsubscribe(String pattern) {}

                @Override
                public void onPSubscribe(String pattern) {
                    subscriptions.incrementAndGet();
                }
            });
            topic.addListener(String.class,
                    (pattern, channel, msg) -> messagesReceived.incrementAndGet());
            assertThat(subscriptions.get()).isEqualTo(1);

            try {
                sendCommands(redisson, "dummy").join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            await().atMost(30, TimeUnit.SECONDS).until(() -> {
                return messagesReceived.get() == 100;
            });

            List<ContainerState> masters = getMasterNodes(nodes2);
            for (ContainerState master : masters) {
                String r = execute(master, "redis-cli", "exists", "i99");
                if (r.contains("1")) {
                    stop(master);
                    break;
                }
            }

            await().atMost(30, TimeUnit.SECONDS).until(() -> {
                return subscriptions.get() == 2;
            });

            for (RedisClusterMaster master : nodes.getMasters()) {
                master.setConfig("notify-keyspace-events", "K$");
            }

            redisson.getBucket("i99").set("");
            await().atMost(1, TimeUnit.SECONDS).until(() -> {
                System.out.println("messagesReceived.get() " + messagesReceived.get());
                return messagesReceived.get() == 101;
            });
        });
    }