Valkey GLIDE Async client
Valkey GLIDE (General Language Independent Driver for the Enterprise) is an official open-source client library for Valkey and Redis OSS. Built with a Rust core and language-specific wrappers, it offers high-performance, reliability, and consistency across multiple languages. The Python client, currently at version 2.3.1, provides both asynchronous and synchronous interfaces and is regularly updated to support new Valkey features and best practices.
Warnings
- gotcha OpenTelemetry can only be initialized once per process. Attempting to re-initialize it will not apply new configurations and requires a full application restart for changes to take effect.
- gotcha Connecting to a TLS-enabled Valkey server without setting `use_tls=True` in the client configuration will result in connection timeouts.
- gotcha Currently, Alpine Linux / MUSL is NOT officially supported for the Python client. Users on these platforms may encounter compilation or runtime issues.
- gotcha Automatic compression/decompression in Valkey GLIDE is NOT compatible with Valkey commands that manipulate string data on the server side.
- gotcha The synchronous Python client (from `glide_sync`) introduced in version 2.1 does not yet support all features available in the asynchronous client, specifically: Pub/Sub, Cluster scan, configuring an In-flight request limit, and OpenTelemetry integration.
Install
-
pip install valkey-glide
Imports
- GlideClient
from glide import GlideClient, NodeAddress
- GlideClusterClient
from glide import GlideClusterClient, NodeAddress
- GlideClient (sync)
from glide_sync import GlideClient, NodeAddress
- GlideClusterClient (sync)
from glide_sync import GlideClusterClient, NodeAddress
Quickstart
import asyncio
from glide import GlideClient, GlideClusterClient, NodeAddress
import os
async def main():
# Example for a standalone Valkey instance
# Ensure a Valkey server is running on localhost:6379 (e.g., via Docker)
# docker run -d --name valkey-server -p 6379:6379 valkey/valkey:latest
print("\n--- Standalone Client Example ---")
standalone_client = GlideClient([NodeAddress("localhost", 6379)])
try:
pong_response = await standalone_client.ping()
print(f"Standalone PING response: {pong_response}")
await standalone_client.set("mykey", "myvalue")
value = await standalone_client.get("mykey")
print(f"Standalone GET mykey: {value}")
except Exception as e:
print(f"Error with Standalone Client: {e}")
finally:
await standalone_client.close()
# Example for a Valkey cluster instance
# Replace with actual cluster addresses
# For local testing, you might need a local Valkey cluster setup
print("\n--- Cluster Client Example ---")
cluster_addresses = [NodeAddress(os.environ.get('VALKEY_CLUSTER_HOST', 'localhost'), int(os.environ.get('VALKEY_CLUSTER_PORT', '7000')))]
cluster_client = GlideClusterClient(cluster_addresses)
try:
cluster_pong_response = await cluster_client.ping()
print(f"Cluster PING response: {cluster_pong_response}")
await cluster_client.set("cluster_key", "cluster_value")
cluster_value = await cluster_client.get("cluster_key")
print(f"Cluster GET cluster_key: {cluster_value}")
except Exception as e:
print(f"Error with Cluster Client: {e}")
finally:
await cluster_client.close()
if __name__ == "__main__":
asyncio.run(main())