From 3fb2ebd4d15a0a96f1f7f017695d20fca8218110 Mon Sep 17 00:00:00 2001 From: Andrew Carbonetto Date: Mon, 26 Feb 2024 15:32:41 -0800 Subject: [PATCH] Update jedis sync client with thread pooling (#978) * Update jedis sync client with thread pooling (#86) * Add jedis threadpool for standalone client Signed-off-by: Andrew Carbonetto --------- Signed-off-by: Andrew Carbonetto * Java-Jedis: Only set the pool for standalone Signed-off-by: Andrew Carbonetto * Spotless Signed-off-by: Andrew Carbonetto * Rename field in jedis client Signed-off-by: Andrew Carbonetto --------- Signed-off-by: Andrew Carbonetto --- .../benchmarks/clients/jedis/JedisClient.java | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/java/benchmarks/src/main/java/glide/benchmarks/clients/jedis/JedisClient.java b/java/benchmarks/src/main/java/glide/benchmarks/clients/jedis/JedisClient.java index a79b757a2c..a2fb669334 100644 --- a/java/benchmarks/src/main/java/glide/benchmarks/clients/jedis/JedisClient.java +++ b/java/benchmarks/src/main/java/glide/benchmarks/clients/jedis/JedisClient.java @@ -6,18 +6,24 @@ import java.util.Set; import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisCluster; import redis.clients.jedis.JedisPool; -import redis.clients.jedis.commands.JedisCommands; /** A Jedis client with sync capabilities. See: https://github.com/redis/jedis */ public class JedisClient implements SyncClient { - - private JedisCommands jedis; + boolean isClusterMode; + private JedisPool jedisStandalonePool; + private JedisCluster jedisCluster; @Override public void closeConnection() { - // nothing to do + if (jedisCluster != null) { + jedisCluster.close(); + } + if (jedisStandalonePool != null) { + jedisStandalonePool.close(); + } } @Override @@ -27,27 +33,38 @@ public String getName() { @Override public void connectToRedis(ConnectionSettings connectionSettings) { - if (connectionSettings.clusterMode) { - jedis = + isClusterMode = connectionSettings.clusterMode; + if (isClusterMode) { + jedisCluster = new JedisCluster( Set.of(new HostAndPort(connectionSettings.host, connectionSettings.port)), DefaultJedisClientConfig.builder().ssl(connectionSettings.useSsl).build()); } else { - try (JedisPool pool = + jedisStandalonePool = new JedisPool( - connectionSettings.host, connectionSettings.port, connectionSettings.useSsl)) { - jedis = pool.getResource(); - } + connectionSettings.host, connectionSettings.port, connectionSettings.useSsl); } } @Override public void set(String key, String value) { - jedis.set(key, value); + if (isClusterMode) { + jedisCluster.set(key, value); + } else { + try (Jedis jedis = jedisStandalonePool.getResource()) { + jedis.set(key, value); + } + } } @Override public String get(String key) { - return jedis.get(key); + if (isClusterMode) { + return jedisCluster.get(key); + } else { + try (Jedis jedis = jedisStandalonePool.getResource()) { + return jedis.get(key); + } + } } }