Skip to content

Commit

Permalink
Simplify ExampleApp
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 ca8dda5 commit ad10c52
Showing 1 changed file with 12 additions and 41 deletions.
53 changes: 12 additions & 41 deletions java/examples/src/main/java/glide/examples/ExamplesApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@
package glide.examples;

import glide.api.RedisClient;
import glide.api.RedisClusterClient;
import glide.examples.clients.GlideClient;
import glide.examples.clients.GlideClusterClient;
import glide.api.models.configuration.NodeAddress;
import glide.api.models.configuration.RedisClientConfiguration;
import java.util.concurrent.ExecutionException;

public class ExamplesApp {

// main application entrypoint
public static void main(String[] args) {
runGlideExamples();

// uncomment to test against a Redis instance with cluster-mode enabled
// runGlideClusterModeExamples();
}

private static void runGlideExamples() {
ConnectionSettings settings = new ConnectionSettings("localhost", 6379, false, false);
String host = "localhost";
Integer port = 6379;
boolean useSsl = false;

RedisClientConfiguration config =
RedisClientConfiguration.builder()
.address(NodeAddress.builder().host(host).port(port).build())
.useTLS(useSsl)
.build();

try {
RedisClient client = GlideClient.connectToGlide(settings);
RedisClient client = RedisClient.CreateClient(config).get();

System.out.println("Glide PING: " + client.ping().get());
System.out.println("Glide PING: " + client.ping("found you").get());
Expand All @@ -31,37 +35,4 @@ private static void runGlideExamples() {
e.printStackTrace();
}
}

private static void runGlideClusterModeExamples() {
ConnectionSettings settings = new ConnectionSettings("localhost", 8000, false, true);

try {
RedisClusterClient client = GlideClusterClient.connectToGlide(settings);

System.out.println("Glide PING: ");
System.out.println(">>>> " + client.ping().get());

System.out.println("Glide PING(msg): ");
System.out.println(">>>> " + client.ping("msg").get());

} catch (ExecutionException | InterruptedException e) {
System.out.println("Glide example failed with an exception: ");
e.printStackTrace();
}
}

/** Redis-client settings */
public static class ConnectionSettings {
public final String host;
public final int port;
public final boolean useSsl;
public final boolean clusterMode;

public ConnectionSettings(String host, int port, boolean useSsl, boolean clusterMode) {
this.host = host;
this.port = port;
this.useSsl = useSsl;
this.clusterMode = clusterMode;
}
}
}

0 comments on commit ad10c52

Please sign in to comment.