Skip to content

Basic Examples

// You can run this example code in Main.java.
import glide.api.GlideClient;
import glide.api.models.configuration.NodeAddress;
import glide.api.models.configuration.GlideClientConfiguration;
import java.util.concurrent.ExecutionException;
import static glide.api.models.GlideString.gs;
public class Main {
public static void main(String[] args) {
runGlideExamples();
}
private static void runGlideExamples() {
String host = "localhost";
Integer port = 6379;
boolean useSsl = false;
GlideClientConfiguration config =
GlideClientConfiguration.builder()
.address(NodeAddress.builder().host(host).port(port).build())
.useTLS(useSsl)
// It is recommended to set a timeout for your specific use case
.requestTimeout(500) // 500ms timeout
.build();
try (GlideClient client = GlideClient.createClient(config).get()) {
System.out.println("PING: " + client.ping(gs("PING")).get());
System.out.println("PING(found you): " + client.ping( gs("found you")).get());
System.out.println("SET(apples, oranges): " + client.set(gs("apples"), gs("oranges")).get());
System.out.println("GET(apples): " + client.get(gs("apples")).get());
} catch (ExecutionException | InterruptedException e) {
System.out.println("Glide example failed with an exception: ");
e.printStackTrace();
}
}
}
// You can run this example code in Main.java.
import glide.api.GlideClusterClient;
import glide.api.models.configuration.NodeAddress;
import glide.api.models.configuration.GlideClusterClientConfiguration;
import glide.api.models.configuration.RequestRoutingConfiguration;
import java.util.concurrent.ExecutionException;
import static glide.api.models.GlideString.gs;
public class Main {
public static void main(String[] args) {
runGlideExamples();
}
private static void runGlideExamples() {
String host = "localhost";
Integer port1 = 7001;
Integer port2 = 7002;
Integer port3 = 7003;
Integer port4 = 7004;
Integer port5 = 7005;
Integer port6 = 7006;
boolean useSsl = false;
GlideClusterClientConfiguration config =
GlideClusterClientConfiguration.builder()
.address(NodeAddress.builder().host(host).port(port1).port(port2).port(port3).port(port4).port(port5).port(port6).build())
.useTLS(useSsl)
// It is recommended to set a timeout for your specific use case
.requestTimeout(500) // 500ms timeout
.build();
try (GlideClusterClient client = GlideClusterClient.createClient(config).get()) {
System.out.println("PING: " + client.ping(gs("PING")).get());
System.out.println("PING(found you): " + client.ping( gs("found you")).get());
System.out.println("SET(apples, oranges): " + client.set(gs("apples"), gs("oranges")).get());
System.out.println("GET(apples): " + client.get(gs("apples")).get());
} catch (ExecutionException | InterruptedException e) {
System.out.println("Glide example failed with an exception: ");
e.printStackTrace();
}
}
}

See our Scala and Kotlin examples to learn how to use Valkey GLIDE in Scala and Kotlin projects.

For more examples, you can refer to the test folder unit tests and integration tests.

You can run benchmarks using ./gradlew run. You can set arguments using the args flag like:

Returns the command help output

Terminal window
./gradlew run --args="--help"

Runs all benchmark clients against a local instance with TLS enabled using data sizing 100 and 1000 bytes, 10 and 100 concurrent tasks, 1 and 5 parallel clients.

Terminal window
./gradlew run --args="--resultsFile=output --dataSize \"100 1000\" --concurrentTasks \"10 100\" --clients all --host localhost --port 6279 --clientCount \"1 5\" --tls"

Runs GLIDE client against a local cluster instance on port 52756 using data sizing 4000 bytes, and 1000 concurrent tasks.

Terminal window
./gradlew run --args="--resultsFile=output --dataSize \"4000\" --concurrentTasks \"1000\" --clients glide --host 127.0.0.1 --port 52746 --clusterModeEnabled"

The following arguments are accepted:

  • resultsFile: the results output file
  • concurrentTasks: number of concurrent tasks
  • clients: one of: all|jedis|lettuce|glide
  • clientCount: client count
  • host: Valkey server host url
  • port: Valkey server port number
  • tls: Valkey TLS configured

Conflict in netty and protobuf internal Valkey GLIDE dependencies with project dependencies using Valkey GLIDE.