From 2c466ffcdeec03c70e6156e1e3e37be112367e02 Mon Sep 17 00:00:00 2001 From: Andrew Carbonetto Date: Thu, 8 Feb 2024 23:33:44 -0800 Subject: [PATCH 1/8] Re-add examples and benchmarking app Signed-off-by: Andrew Carbonetto --- .../glide/benchmarks/BenchmarkingApp.java | 1 + .../glide/GlideAsyncClusterClient.java | 63 +++++++++++++++++++ .../glide/examples/clients/GlideClient.java | 28 +++++++++ .../examples/clients/GlideClusterClient.java | 28 +++++++++ 4 files changed, 120 insertions(+) create mode 100644 java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClusterClient.java create mode 100644 java/examples/src/main/java/glide/examples/clients/GlideClient.java create mode 100644 java/examples/src/main/java/glide/examples/clients/GlideClusterClient.java diff --git a/java/benchmarks/src/main/java/glide/benchmarks/BenchmarkingApp.java b/java/benchmarks/src/main/java/glide/benchmarks/BenchmarkingApp.java index 9c5d196699..7836865cc9 100644 --- a/java/benchmarks/src/main/java/glide/benchmarks/BenchmarkingApp.java +++ b/java/benchmarks/src/main/java/glide/benchmarks/BenchmarkingApp.java @@ -6,6 +6,7 @@ import glide.benchmarks.clients.glide.GlideAsyncClient; import glide.benchmarks.clients.jedis.JedisClient; import glide.benchmarks.clients.lettuce.LettuceAsyncClient; +import glide.benchmarks.clients.glide.GlideAsyncClient; import java.util.Arrays; import java.util.Optional; import java.util.stream.Stream; diff --git a/java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClusterClient.java b/java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClusterClient.java new file mode 100644 index 0000000000..8b6f08ebf0 --- /dev/null +++ b/java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClusterClient.java @@ -0,0 +1,63 @@ +/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ +package glide.benchmarks.clients.glide; + +import glide.api.RedisClient; +import glide.api.RedisClusterClient; +import glide.api.models.configuration.NodeAddress; +import glide.api.models.configuration.RedisClientConfiguration; +import glide.api.models.configuration.RedisClusterClientConfiguration; +import glide.benchmarks.clients.AsyncClient; +import glide.benchmarks.utils.ConnectionSettings; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +/** A Glide client with async capabilities */ +public class GlideAsyncClusterClient implements AsyncClient { + private RedisClusterClient redisClient; + + @Override + public void connectToRedis(ConnectionSettings connectionSettings) { + if (!connectionSettings.clusterMode) { + throw new RuntimeException("Use client GlideAsyncClient"); + } + RedisClusterClientConfiguration config = + RedisClusterClientConfiguration.builder() + .address( + NodeAddress.builder() + .host(connectionSettings.host) + .port(connectionSettings.port) + .build()) + .useTLS(connectionSettings.useSsl) + .build(); + + try { + redisClient = RedisClusterClient.CreateClient(config).get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + } + + @Override + public CompletableFuture asyncSet(String key, String value) { + return redisClient.customCommand(new String[] {"Set", key, value}).thenApply(r -> "Ok"); + } + + @Override + public CompletableFuture asyncGet(String key) { + return redisClient.customCommand(new String[] {"Get", key}).thenApply(r -> (String) r.getSingleValue()); + } + + @Override + public void closeConnection() { + try { + redisClient.close(); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } + } + + @Override + public String getName() { + return "Glide Cluster Async"; + } +} diff --git a/java/examples/src/main/java/glide/examples/clients/GlideClient.java b/java/examples/src/main/java/glide/examples/clients/GlideClient.java new file mode 100644 index 0000000000..b6100fa6d2 --- /dev/null +++ b/java/examples/src/main/java/glide/examples/clients/GlideClient.java @@ -0,0 +1,28 @@ +/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ +package glide.examples.clients; + +import glide.api.RedisClient; +import glide.api.models.configuration.NodeAddress; +import glide.api.models.configuration.RedisClientConfiguration; +import glide.examples.ExamplesApp; +import java.util.concurrent.ExecutionException; + +/** Connect to Jedis client. See: https://github.com/redis/jedis */ +public class GlideClient { + public static RedisClient connectToGlide(ExamplesApp.ConnectionSettings connectionSettings) + throws ExecutionException, InterruptedException { + if (connectionSettings.clusterMode) { + throw new RuntimeException("Not implemented"); + } + RedisClientConfiguration config = + RedisClientConfiguration.builder() + .address( + NodeAddress.builder() + .host(connectionSettings.host) + .port(connectionSettings.port) + .build()) + .useTLS(connectionSettings.useSsl) + .build(); + return RedisClient.CreateClient(config).get(); + } +} diff --git a/java/examples/src/main/java/glide/examples/clients/GlideClusterClient.java b/java/examples/src/main/java/glide/examples/clients/GlideClusterClient.java new file mode 100644 index 0000000000..9ebd7a0f47 --- /dev/null +++ b/java/examples/src/main/java/glide/examples/clients/GlideClusterClient.java @@ -0,0 +1,28 @@ +/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ +package glide.examples.clients; + +import glide.api.RedisClusterClient; +import glide.api.models.configuration.NodeAddress; +import glide.api.models.configuration.RedisClusterClientConfiguration; +import glide.examples.ExamplesApp; +import java.util.concurrent.ExecutionException; + +/** Connect to Jedis client. See: https://github.com/redis/jedis */ +public class GlideClusterClient { + public static RedisClusterClient connectToGlide(ExamplesApp.ConnectionSettings connectionSettings) + throws ExecutionException, InterruptedException { + if (!connectionSettings.clusterMode) { + throw new RuntimeException("Not implemented"); + } + RedisClusterClientConfiguration config = + RedisClusterClientConfiguration.builder() + .address( + NodeAddress.builder() + .host(connectionSettings.host) + .port(connectionSettings.port) + .build()) + .useTLS(connectionSettings.useSsl) + .build(); + return RedisClusterClient.CreateClient(config).get(); + } +} From 8658bba42ad4df7810aca628f0e02142f4cc5348 Mon Sep 17 00:00:00 2001 From: Andrew Carbonetto Date: Thu, 8 Feb 2024 23:42:01 -0800 Subject: [PATCH 2/8] Spotless Signed-off-by: Andrew Carbonetto --- .../src/main/java/glide/benchmarks/BenchmarkingApp.java | 1 - .../benchmarks/clients/glide/GlideAsyncClusterClient.java | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/java/benchmarks/src/main/java/glide/benchmarks/BenchmarkingApp.java b/java/benchmarks/src/main/java/glide/benchmarks/BenchmarkingApp.java index 7836865cc9..9c5d196699 100644 --- a/java/benchmarks/src/main/java/glide/benchmarks/BenchmarkingApp.java +++ b/java/benchmarks/src/main/java/glide/benchmarks/BenchmarkingApp.java @@ -6,7 +6,6 @@ import glide.benchmarks.clients.glide.GlideAsyncClient; import glide.benchmarks.clients.jedis.JedisClient; import glide.benchmarks.clients.lettuce.LettuceAsyncClient; -import glide.benchmarks.clients.glide.GlideAsyncClient; import java.util.Arrays; import java.util.Optional; import java.util.stream.Stream; diff --git a/java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClusterClient.java b/java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClusterClient.java index 8b6f08ebf0..29a9be8fef 100644 --- a/java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClusterClient.java +++ b/java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClusterClient.java @@ -1,10 +1,8 @@ /** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ package glide.benchmarks.clients.glide; -import glide.api.RedisClient; import glide.api.RedisClusterClient; import glide.api.models.configuration.NodeAddress; -import glide.api.models.configuration.RedisClientConfiguration; import glide.api.models.configuration.RedisClusterClientConfiguration; import glide.benchmarks.clients.AsyncClient; import glide.benchmarks.utils.ConnectionSettings; @@ -21,7 +19,7 @@ public void connectToRedis(ConnectionSettings connectionSettings) { throw new RuntimeException("Use client GlideAsyncClient"); } RedisClusterClientConfiguration config = - RedisClusterClientConfiguration.builder() + RedisClusterClientConfiguration.builder() .address( NodeAddress.builder() .host(connectionSettings.host) @@ -44,7 +42,9 @@ public CompletableFuture asyncSet(String key, String value) { @Override public CompletableFuture asyncGet(String key) { - return redisClient.customCommand(new String[] {"Get", key}).thenApply(r -> (String) r.getSingleValue()); + return redisClient + .customCommand(new String[] {"Get", key}) + .thenApply(r -> (String) r.getSingleValue()); } @Override From e4b385c0c0e6b00b5dc19fd650b27b9fb5293f11 Mon Sep 17 00:00:00 2001 From: Andrew Carbonetto Date: Mon, 12 Feb 2024 22:36:53 -0800 Subject: [PATCH 3/8] Add jedis threadpool for standalone client Signed-off-by: Andrew Carbonetto --- .../benchmarks/clients/jedis/JedisClient.java | 32 ++++++------- .../clients/jedis/JedisClusterClient.java | 45 +++++++++++++++++++ 2 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 java/benchmarks/src/main/java/glide/benchmarks/clients/jedis/JedisClusterClient.java 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..49f5a84b50 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 @@ -3,21 +3,18 @@ import glide.benchmarks.clients.SyncClient; import glide.benchmarks.utils.ConnectionSettings; -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; + private JedisPool jedisPool; + private JedisCluster jedisCluster; @Override public void closeConnection() { - // nothing to do + jedisPool.close(); } @Override @@ -28,26 +25,23 @@ public String getName() { @Override public void connectToRedis(ConnectionSettings connectionSettings) { if (connectionSettings.clusterMode) { - jedis = - new JedisCluster( - Set.of(new HostAndPort(connectionSettings.host, connectionSettings.port)), - DefaultJedisClientConfig.builder().ssl(connectionSettings.useSsl).build()); - } else { - try (JedisPool pool = - new JedisPool( - connectionSettings.host, connectionSettings.port, connectionSettings.useSsl)) { - jedis = pool.getResource(); - } + throw new RuntimeException("Use JedisClsuterClient for cluster-mode client"); } + jedisPool = + new JedisPool(connectionSettings.host, connectionSettings.port, connectionSettings.useSsl); } @Override public void set(String key, String value) { - jedis.set(key, value); + try (Jedis jedis = jedisPool.getResource()) { + jedis.set(key, value); + } } @Override public String get(String key) { - return jedis.get(key); + try (Jedis jedis = jedisPool.getResource()) { + return jedis.get(key); + } } } diff --git a/java/benchmarks/src/main/java/glide/benchmarks/clients/jedis/JedisClusterClient.java b/java/benchmarks/src/main/java/glide/benchmarks/clients/jedis/JedisClusterClient.java new file mode 100644 index 0000000000..5c12606f1a --- /dev/null +++ b/java/benchmarks/src/main/java/glide/benchmarks/clients/jedis/JedisClusterClient.java @@ -0,0 +1,45 @@ +/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ +package glide.benchmarks.clients.jedis; + +import glide.benchmarks.clients.SyncClient; +import glide.benchmarks.utils.ConnectionSettings; +import java.util.Set; +import redis.clients.jedis.DefaultJedisClientConfig; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.JedisCluster; + +/** A Jedis cluster client with sync capabilities. See: https://github.com/redis/jedis */ +public class JedisClusterClient implements SyncClient { + private JedisCluster jedisCluster; + + @Override + public void closeConnection() { + jedisCluster.close(); + } + + @Override + public String getName() { + return "Jedis"; + } + + @Override + public void connectToRedis(ConnectionSettings connectionSettings) { + if (connectionSettings.clusterMode) { + jedisCluster = + new JedisCluster( + Set.of(new HostAndPort(connectionSettings.host, connectionSettings.port)), + DefaultJedisClientConfig.builder().ssl(connectionSettings.useSsl).build()); + } + throw new RuntimeException("Use JedisClient for standalone client"); + } + + @Override + public void set(String key, String value) { + jedisCluster.set(key, value); + } + + @Override + public String get(String key) { + return jedisCluster.get(key); + } +} From b39114fd3b5058a2b6eeb92bdd40879859d6b2f0 Mon Sep 17 00:00:00 2001 From: Andrew Carbonetto Date: Mon, 12 Feb 2024 22:54:32 -0800 Subject: [PATCH 4/8] Add jedis threadpool for standalone client Signed-off-by: Andrew Carbonetto --- .../benchmarks/clients/jedis/JedisClient.java | 26 +++++++++-- .../clients/jedis/JedisClusterClient.java | 45 ------------------- 2 files changed, 22 insertions(+), 49 deletions(-) delete mode 100644 java/benchmarks/src/main/java/glide/benchmarks/clients/jedis/JedisClusterClient.java 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 49f5a84b50..d3ff24b69b 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 @@ -3,18 +3,24 @@ import glide.benchmarks.clients.SyncClient; import glide.benchmarks.utils.ConnectionSettings; +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.util.JedisClusterCRC16; /** A Jedis client with sync capabilities. See: https://github.com/redis/jedis */ public class JedisClient implements SyncClient { + boolean isClusterMode; private JedisPool jedisPool; private JedisCluster jedisCluster; @Override public void closeConnection() { jedisPool.close(); + jedisCluster.close(); } @Override @@ -22,10 +28,22 @@ public String getName() { return "Jedis"; } + private Jedis getConnection(String key) { + if (isClusterMode) { + return new Jedis(jedisCluster.getConnectionFromSlot(JedisClusterCRC16.getSlot(key))); + } else { + return jedisPool.getResource(); + } + } + @Override public void connectToRedis(ConnectionSettings connectionSettings) { - if (connectionSettings.clusterMode) { - throw new RuntimeException("Use JedisClsuterClient for cluster-mode client"); + isClusterMode = connectionSettings.clusterMode; + if (isClusterMode) { + jedisCluster = + new JedisCluster( + Set.of(new HostAndPort(connectionSettings.host, connectionSettings.port)), + DefaultJedisClientConfig.builder().ssl(connectionSettings.useSsl).build()); } jedisPool = new JedisPool(connectionSettings.host, connectionSettings.port, connectionSettings.useSsl); @@ -33,14 +51,14 @@ public void connectToRedis(ConnectionSettings connectionSettings) { @Override public void set(String key, String value) { - try (Jedis jedis = jedisPool.getResource()) { + try (Jedis jedis = getConnection(key)) { jedis.set(key, value); } } @Override public String get(String key) { - try (Jedis jedis = jedisPool.getResource()) { + try (Jedis jedis = getConnection(key)) { return jedis.get(key); } } diff --git a/java/benchmarks/src/main/java/glide/benchmarks/clients/jedis/JedisClusterClient.java b/java/benchmarks/src/main/java/glide/benchmarks/clients/jedis/JedisClusterClient.java deleted file mode 100644 index 5c12606f1a..0000000000 --- a/java/benchmarks/src/main/java/glide/benchmarks/clients/jedis/JedisClusterClient.java +++ /dev/null @@ -1,45 +0,0 @@ -/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ -package glide.benchmarks.clients.jedis; - -import glide.benchmarks.clients.SyncClient; -import glide.benchmarks.utils.ConnectionSettings; -import java.util.Set; -import redis.clients.jedis.DefaultJedisClientConfig; -import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.JedisCluster; - -/** A Jedis cluster client with sync capabilities. See: https://github.com/redis/jedis */ -public class JedisClusterClient implements SyncClient { - private JedisCluster jedisCluster; - - @Override - public void closeConnection() { - jedisCluster.close(); - } - - @Override - public String getName() { - return "Jedis"; - } - - @Override - public void connectToRedis(ConnectionSettings connectionSettings) { - if (connectionSettings.clusterMode) { - jedisCluster = - new JedisCluster( - Set.of(new HostAndPort(connectionSettings.host, connectionSettings.port)), - DefaultJedisClientConfig.builder().ssl(connectionSettings.useSsl).build()); - } - throw new RuntimeException("Use JedisClient for standalone client"); - } - - @Override - public void set(String key, String value) { - jedisCluster.set(key, value); - } - - @Override - public String get(String key) { - return jedisCluster.get(key); - } -} From 53c247f7eeae5cca750fdc207765aca2063236c9 Mon Sep 17 00:00:00 2001 From: Andrew Carbonetto Date: Tue, 13 Feb 2024 00:14:38 -0800 Subject: [PATCH 5/8] Remove unused example clients Signed-off-by: Andrew Carbonetto --- .../glide/examples/clients/GlideClient.java | 28 ------------------- .../examples/clients/GlideClusterClient.java | 28 ------------------- 2 files changed, 56 deletions(-) delete mode 100644 java/examples/src/main/java/glide/examples/clients/GlideClient.java delete mode 100644 java/examples/src/main/java/glide/examples/clients/GlideClusterClient.java diff --git a/java/examples/src/main/java/glide/examples/clients/GlideClient.java b/java/examples/src/main/java/glide/examples/clients/GlideClient.java deleted file mode 100644 index b6100fa6d2..0000000000 --- a/java/examples/src/main/java/glide/examples/clients/GlideClient.java +++ /dev/null @@ -1,28 +0,0 @@ -/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ -package glide.examples.clients; - -import glide.api.RedisClient; -import glide.api.models.configuration.NodeAddress; -import glide.api.models.configuration.RedisClientConfiguration; -import glide.examples.ExamplesApp; -import java.util.concurrent.ExecutionException; - -/** Connect to Jedis client. See: https://github.com/redis/jedis */ -public class GlideClient { - public static RedisClient connectToGlide(ExamplesApp.ConnectionSettings connectionSettings) - throws ExecutionException, InterruptedException { - if (connectionSettings.clusterMode) { - throw new RuntimeException("Not implemented"); - } - RedisClientConfiguration config = - RedisClientConfiguration.builder() - .address( - NodeAddress.builder() - .host(connectionSettings.host) - .port(connectionSettings.port) - .build()) - .useTLS(connectionSettings.useSsl) - .build(); - return RedisClient.CreateClient(config).get(); - } -} diff --git a/java/examples/src/main/java/glide/examples/clients/GlideClusterClient.java b/java/examples/src/main/java/glide/examples/clients/GlideClusterClient.java deleted file mode 100644 index 9ebd7a0f47..0000000000 --- a/java/examples/src/main/java/glide/examples/clients/GlideClusterClient.java +++ /dev/null @@ -1,28 +0,0 @@ -/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ -package glide.examples.clients; - -import glide.api.RedisClusterClient; -import glide.api.models.configuration.NodeAddress; -import glide.api.models.configuration.RedisClusterClientConfiguration; -import glide.examples.ExamplesApp; -import java.util.concurrent.ExecutionException; - -/** Connect to Jedis client. See: https://github.com/redis/jedis */ -public class GlideClusterClient { - public static RedisClusterClient connectToGlide(ExamplesApp.ConnectionSettings connectionSettings) - throws ExecutionException, InterruptedException { - if (!connectionSettings.clusterMode) { - throw new RuntimeException("Not implemented"); - } - RedisClusterClientConfiguration config = - RedisClusterClientConfiguration.builder() - .address( - NodeAddress.builder() - .host(connectionSettings.host) - .port(connectionSettings.port) - .build()) - .useTLS(connectionSettings.useSsl) - .build(); - return RedisClusterClient.CreateClient(config).get(); - } -} From ab0b3b34fcd6c04a3771850c7547a72bc5ca8ecb Mon Sep 17 00:00:00 2001 From: Andrew Carbonetto Date: Wed, 14 Feb 2024 22:46:54 -0800 Subject: [PATCH 6/8] Split cluster and standalone jedis clients Signed-off-by: Andrew Carbonetto --- .../benchmarks/clients/jedis/JedisClient.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 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 d3ff24b69b..9bbc3c4bee 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 @@ -9,7 +9,6 @@ import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisCluster; import redis.clients.jedis.JedisPool; -import redis.clients.jedis.util.JedisClusterCRC16; /** A Jedis client with sync capabilities. See: https://github.com/redis/jedis */ public class JedisClient implements SyncClient { @@ -28,14 +27,6 @@ public String getName() { return "Jedis"; } - private Jedis getConnection(String key) { - if (isClusterMode) { - return new Jedis(jedisCluster.getConnectionFromSlot(JedisClusterCRC16.getSlot(key))); - } else { - return jedisPool.getResource(); - } - } - @Override public void connectToRedis(ConnectionSettings connectionSettings) { isClusterMode = connectionSettings.clusterMode; @@ -51,15 +42,23 @@ public void connectToRedis(ConnectionSettings connectionSettings) { @Override public void set(String key, String value) { - try (Jedis jedis = getConnection(key)) { - jedis.set(key, value); + if (isClusterMode) { + jedisCluster.set(key, value); + } else { + try (Jedis jedis = jedisPool.getResource()) { + jedis.set(key, value); + } } } @Override public String get(String key) { - try (Jedis jedis = getConnection(key)) { - return jedis.get(key); + if (isClusterMode) { + return jedisCluster.get(key); + } else { + try (Jedis jedis = jedisPool.getResource()) { + return jedis.get(key); + } } } } From 46896e63b8f4d7130c924c9217d8a7129d7369ec Mon Sep 17 00:00:00 2001 From: Andrew Carbonetto Date: Wed, 14 Feb 2024 22:48:53 -0800 Subject: [PATCH 7/8] Fix null exceptions Signed-off-by: Andrew Carbonetto --- .../java/glide/benchmarks/clients/jedis/JedisClient.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 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 9bbc3c4bee..bf9007bea0 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 @@ -18,8 +18,12 @@ public class JedisClient implements SyncClient { @Override public void closeConnection() { - jedisPool.close(); - jedisCluster.close(); + if (jedisCluster != null) { + jedisCluster.close(); + } + if (jedisPool != null) { + jedisPool.close(); + } } @Override From 3658015c4a3014587bb4813aaef4adab69ca6fec Mon Sep 17 00:00:00 2001 From: Andrew Carbonetto Date: Thu, 15 Feb 2024 15:19:07 -0800 Subject: [PATCH 8/8] Fix merge conflict Signed-off-by: Andrew Carbonetto --- .../glide/GlideAsyncClusterClient.java | 63 ------------------- 1 file changed, 63 deletions(-) delete mode 100644 java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClusterClient.java diff --git a/java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClusterClient.java b/java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClusterClient.java deleted file mode 100644 index 29a9be8fef..0000000000 --- a/java/benchmarks/src/main/java/glide/benchmarks/clients/glide/GlideAsyncClusterClient.java +++ /dev/null @@ -1,63 +0,0 @@ -/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ -package glide.benchmarks.clients.glide; - -import glide.api.RedisClusterClient; -import glide.api.models.configuration.NodeAddress; -import glide.api.models.configuration.RedisClusterClientConfiguration; -import glide.benchmarks.clients.AsyncClient; -import glide.benchmarks.utils.ConnectionSettings; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -/** A Glide client with async capabilities */ -public class GlideAsyncClusterClient implements AsyncClient { - private RedisClusterClient redisClient; - - @Override - public void connectToRedis(ConnectionSettings connectionSettings) { - if (!connectionSettings.clusterMode) { - throw new RuntimeException("Use client GlideAsyncClient"); - } - RedisClusterClientConfiguration config = - RedisClusterClientConfiguration.builder() - .address( - NodeAddress.builder() - .host(connectionSettings.host) - .port(connectionSettings.port) - .build()) - .useTLS(connectionSettings.useSsl) - .build(); - - try { - redisClient = RedisClusterClient.CreateClient(config).get(); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - } - - @Override - public CompletableFuture asyncSet(String key, String value) { - return redisClient.customCommand(new String[] {"Set", key, value}).thenApply(r -> "Ok"); - } - - @Override - public CompletableFuture asyncGet(String key) { - return redisClient - .customCommand(new String[] {"Get", key}) - .thenApply(r -> (String) r.getSingleValue()); - } - - @Override - public void closeConnection() { - try { - redisClient.close(); - } catch (ExecutionException e) { - throw new RuntimeException(e); - } - } - - @Override - public String getName() { - return "Glide Cluster Async"; - } -}