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 a common 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 asyncio
from glide import GlideClient, NodeAddress
async def string_operations():
client = GlideClient([NodeAddress("localhost", 6379)])
try:
# Set a key-value pair
await client.set("user:1000", "john_doe")
print("✓ Key set successfully")
# Get the value
value = await client.get("user:1000")
print(f"✓ Retrieved value: {value}")
finally:
await client.close()
if __name__ == "__main__":
asyncio.run(string_operations())

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

# Set multiple keys at once
await client.mset({"user:1001": "alice", "user:1002": "bob", "user:1003": "charlie"})
print("✓ Multiple keys set")
# Get multiple keys at once
values = await client.mget(["user:1001", "user:1002", "user:1003"])
print(f"✓ Retrieved values: {values}")

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

deleted_count = await client.delete(["user:1001", "user:1002", "user:1003"])
print(f"✓ Deleted {deleted_count} keys")

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