Skip to content

Commit

Permalink
Add LettuceAsyncClusterClient
Browse files Browse the repository at this point in the history
Signed-off-by: acarbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Nov 7, 2023
1 parent 9d303c0 commit cb5541e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javababushka.benchmarks.jedis.JedisClient;
import javababushka.benchmarks.jedis.JedisPseudoAsyncClient;
import javababushka.benchmarks.lettuce.LettuceAsyncClient;
import javababushka.benchmarks.lettuce.LettuceAsyncClusterClient;
import javababushka.benchmarks.lettuce.LettuceClient;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
Expand Down Expand Up @@ -56,7 +57,11 @@ public static void main(String[] args) {
testClientSetGet(LettuceClient::new, runConfiguration, false);
break;
case LETTUCE_ASYNC:
testClientSetGet(LettuceAsyncClient::new, runConfiguration, true);
if (runConfiguration.clusterModeEnabled) {
testClientSetGet(LettuceAsyncClusterClient::new, runConfiguration, true);
} else {
testClientSetGet(LettuceAsyncClient::new, runConfiguration, true);
}
break;
case BABUSHKA:
System.out.println("Babushka not yet configured");
Expand Down Expand Up @@ -96,6 +101,13 @@ private static Options getOptions() {
options.addOption(
Option.builder("clientCount").hasArg(true).desc("Number of clients to run [1]").build());
options.addOption(Option.builder("tls").hasArg(false).desc("TLS [false]").build());
options.addOption(
Option.builder("clusterModeEnabled")
.hasArg(false)
.desc("Is cluster-mode enabled, other standalone mode is used [false]")
.build());
options.addOption(
Option.builder("debugLogging").hasArg(false).desc("Verbose logs [false]").build());

return options;
}
Expand Down Expand Up @@ -171,6 +183,8 @@ private static RunConfiguration verifyOptions(CommandLine line) throws ParseExce
}

runConfiguration.tls = line.hasOption("tls");
runConfiguration.clusterModeEnabled = line.hasOption("clusterModeEnabled");
runConfiguration.debugLogging = line.hasOption("debugLogging");

return runConfiguration;
}
Expand Down Expand Up @@ -227,7 +241,8 @@ public static class RunConfiguration {
public int port;
public int[] clientCount;
public boolean tls;
public boolean debugLogging = false;
public boolean clusterModeEnabled;
public boolean debugLogging;

public RunConfiguration() {
configuration = "Release";
Expand All @@ -243,6 +258,8 @@ public RunConfiguration() {
port = 6379;
clientCount = new int[] {1, 2};
tls = false;
clusterModeEnabled = false;
debugLogging = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
*/
package javababushka.benchmarks.lettuce;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.async.RedisAsyncCommands;
import io.lettuce.core.RedisURI;
import io.lettuce.core.cluster.RedisClusterClient;
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
import io.lettuce.core.cluster.api.async.RedisAdvancedClusterAsyncCommands;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javababushka.benchmarks.AsyncClient;
import javababushka.benchmarks.utils.ConnectionSettings;

public class LettuceAsyncClient implements AsyncClient {
public class LettuceAsyncClusterClient implements AsyncClient {

RedisClient client;
RedisAsyncCommands asyncCommands;
StatefulRedisConnection<String, String> connection;
RedisClusterClient client;
RedisAdvancedClusterAsyncCommands asyncCommands;
StatefulRedisClusterConnection<String, String> connection;

@Override
public void connectToRedis() {
Expand All @@ -25,13 +26,13 @@ public void connectToRedis() {

@Override
public void connectToRedis(ConnectionSettings connectionSettings) {
client =
RedisClient.create(
String.format(
"%s://%s:%d",
connectionSettings.useSsl ? "rediss" : "redis",
connectionSettings.host,
connectionSettings.port));
RedisURI uri =
RedisURI.builder()
.withHost(connectionSettings.host)
.withPort(connectionSettings.port)
.withSsl(connectionSettings.useSsl)
.build();
client = RedisClusterClient.create(uri);
connection = client.connect();
asyncCommands = connection.async();
}
Expand Down

0 comments on commit cb5541e

Please sign in to comment.