Basic Examples
Standalone Valkey
Section titled “Standalone Valkey”// 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(); } }}Cluster Valkey
Section titled “Cluster Valkey”// 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(); } }}Scala and Kotlin Examples
Section titled “Scala and Kotlin Examples”See our Scala and Kotlin examples to learn how to use Valkey GLIDE in Scala and Kotlin projects.
Accessing tests
Section titled “Accessing tests”For more examples, you can refer to the test folder unit tests and integration tests.
Benchmarks
Section titled “Benchmarks”You can run benchmarks using ./gradlew run. You can set arguments using the args flag like:
Returns the command help output
./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.
./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.
./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 fileconcurrentTasks: number of concurrent tasksclients: one of: all|jedis|lettuce|glideclientCount: client counthost: Valkey server host urlport: Valkey server port numbertls: Valkey TLS configured
Known issues
Section titled “Known issues”Conflict in netty and protobuf internal Valkey GLIDE dependencies with project dependencies using Valkey GLIDE.
- Issue link: https://github.com/valkey-io/valkey-glide/issues/3402.
- Workarounds mentioned in this issue: https://github.com/valkey-io/valkey-glide/issues/3367