0

I am trying to setup a connection listener for my redisson client. It is not getting invoked on both connect/disconnect.

Tried the code mentioned on the redisson github which is as per below:

public void createRedisClient(Handler<AsyncResult<Redis>> handler) {

    ConfigRetriever configRetriever = UDSFBootStrapper.getInstance().getConfigRetriever();

    configRetriever.getConfig(
            config -> {                 
                String redisUrl = config.result().getString("redisip");
                redisUrl += ":";
                redisUrl += config.result().getInteger("redisport");
                Config rconfig = new Config();

                rconfig.setTransportMode(TransportMode.EPOLL);
                rconfig.useClusterServers()
                      .addNodeAddress(UdsfConstants.REDIS_CONNECTION_PREFIX + redisUrl);

                rclient = Redisson.create(rconfig);

                rclient.getNodesGroup().addConnectionListener(new ConnectionListener() {

                    //@Override
                    public void onConnect(InetSocketAddress inetSocketAddress) {
                        logger.info("Redis server connected");
                    }

                    //@Override
                    public void onDisconnect(InetSocketAddress inetSocketAddress) {
                        logger.info("Redis server disconnected");
                    }
                });

            });
    }
coder123
  • 1
  • 1
  • Could you share full code example you use for testing? Here is a test case used by Redisson https://github.com/redisson/redisson/blob/18a6cea368804b4e22fd48f00e33cb4131d6ba6c/redisson/src/test/java/org/redisson/RedissonTest.java#L295 – Nikita Koksharov Aug 22 '19 at 12:01
  • @NikitaKoksharov i have added the full function code. Redis connection is working fine. But listeners are not getting invoked. I have seen the test code and if i take the id of the connection listerner, it is not 0, its a random number. Im using 3.7.1 for redisson, also tried with the latest version. – coder123 Aug 26 '19 at 13:04
  • I see that by calling rclient.shutdown() the onDisconnect listener is being called. But if i remove the LAN cable which connects with the redis or plug it back, the listeners are not called. The redisConnection should break/make at this point. Please comment. – coder123 Aug 26 '19 at 13:29
  • you need to set `pingConnectionInterval = 1000` setting in this case. – Nikita Koksharov Aug 27 '19 at 13:33

0 Answers0