I have a requirement of supporting the multiple redis connections.
The requirement is Why Can't we have a Generic Connection Object like Connection instead of having the StatefulRedisConnection and StatefulRedisClusterConnection ?
Why we have RedisClient and RedisClusterClient instead of generic Client object that can connect to any of the types of connection like Standalone, Sentinel and Cluster?
How to achieve the factory pattern by switching the Standalone, cluster or sentinel when I say connectionType=cluster (or) connectionType=sentinel in commandline args?
RedisClient client = RedisClient.create(redisURI); AbstractRedisClient abstractRedisClient = RedisClient.create(redisURI); abstractRedisClient = RedisClusterClient.create(redisURI); AbstractRedisClient finalAbstractRedisClient = abstractRedisClient; GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(() -> (finalAbstractRedisClient instanceof RedisClient) ? ((RedisClient) finalAbstractRedisClient).connect() : ((RedisClusterClient) finalAbstractRedisClient).connect(), new GenericObjectPoolConfig()); try (StatefulRedisConnection<String, String> connection = pool.borrowObject()) { RedisCommands<String, String> commands = connection.sync(); pong = commands.ping(); }