Skip to content

Basic Operations

Now that you have a working connection, let’s explore the fundamental operations you can perform with Valkey GLIDE.

To communicate with Valkey, GLIDE clients provide methods for users to send commands to Valkey. Under the hood, all clients share the same Rust core to communicate with Valkey. This makes their behavior consistent between the different languages while still supporting language specific features.

To update keys in Valkey, clients can send SET and GET commands.

import glide.api.GlideClient;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.api.models.configuration.NodeAddress;
import glide.api.models.commands.SetOptions;
public class StringOperations {
public static void main(String[] args) {
GlideClientConfiguration config = GlideClientConfiguration.builder()
.address(NodeAddress.builder().host("localhost").port(6379).build())
.build();
try (GlideClient client = GlideClient.createClient(config).get()) {
// Set a key-value pair
client.set("user:1000", "john_doe").get();
System.out.println("✓ Key set successfully");
// Get the value
String value = client.get("user:1000").get();
System.out.println("✓ Retrieved value: " + value);
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}

Clients can send MSET and MGET commands, which are used to set/get keys and values atomically.

// Set multiple keys at once
Map<String, String> keyValues = Map.of(
"user:1001", "alice",
"user:1002", "bob",
"user:1003", "charlie"
);
client.mset(keyValues).get();
System.out.println("✓ Multiple keys set");
// Get multiple keys at once
String[] keys = {"user:1001", "user:1002", "user:1003"};
String[] values = client.mget(keys).get();
System.out.println("✓ Retrieved values: " + Arrays.toString(values));

Clients can also send DEL commands to delete a list of keys.

String[] keys = {"user:1001", "user:1002", "user:1003"};
Long deletedCount = client.del(keys).get();
System.out.println("✓ Deleted " + deletedCount + " keys");

Now that you understand the basics, take a look at some other topics on Valkey GLIDE: