Skip to content

Commit

Permalink
Combine clients for benchmarking
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Feb 13, 2024
1 parent ad10c52 commit 2259992
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,48 +1,67 @@
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.benchmarks.clients.glide;

import glide.api.BaseClient;
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 GlideAsyncClient implements AsyncClient<String> {
private RedisClient redisClient;
private BaseClient redisClient;

@Override
public void connectToRedis(ConnectionSettings connectionSettings) {

if (connectionSettings.clusterMode) {
throw new RuntimeException("Use client GlideAsyncClusterClient");
}
RedisClientConfiguration config =
RedisClientConfiguration.builder()
.address(
NodeAddress.builder()
.host(connectionSettings.host)
.port(connectionSettings.port)
.build())
.useTLS(connectionSettings.useSsl)
.build();
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);
}

try {
redisClient = RedisClient.CreateClient(config).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
} else {
RedisClientConfiguration config =
RedisClientConfiguration.builder()
.address(
NodeAddress.builder()
.host(connectionSettings.host)
.port(connectionSettings.port)
.build())
.useTLS(connectionSettings.useSsl)
.build();

try {
redisClient = RedisClient.CreateClient(config).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
}

@Override
public CompletableFuture<String> asyncSet(String key, String value) {
return redisClient.customCommand(new String[] {"Set", key, value}).thenApply(r -> (String) r);
return redisClient.set(key, value);
}

@Override
public CompletableFuture<String> asyncGet(String key) {
return redisClient.customCommand(new String[] {"Get", key}).thenApply(r -> (String) r);
return redisClient.get(key);
}

@Override
Expand Down

This file was deleted.

0 comments on commit 2259992

Please sign in to comment.