Valkey GLIDE Sync Client
Valkey GLIDE Sync is an official open-source Valkey client library for Python, designed to interact with Valkey and Redis OSS in a synchronous manner. It supports both standalone and cluster deployments, offering features like automatic topology discovery, read-from-replica options, and OpenTelemetry integration. The library is part of the Valkey organization and aims for high performance and reliability, currently at version 2.3.1.
Warnings
- breaking In version 2.1, the Python package structure underwent a significant change. Previously, core components might have been accessible directly under `glide`. Now, synchronous client classes are specifically under `glide_sync`, and shared components are under `glide_shared`. This change can break existing imports if not updated.
- gotcha Valkey GLIDE offers both synchronous (`valkey-glide-sync`) and asynchronous (`valkey-glide`) Python clients. Ensure you install and import from the correct package (`glide_sync` for sync, `glide` for async) based on your application's concurrency model. Mixing them or using the wrong package can lead to unexpected behavior or `AttributeError`s.
- gotcha When executing commands with the synchronous client, the methods return a future-like object. You must explicitly call `.get()` on the result of a command (e.g., `client.ping().get()`) to retrieve the actual value or wait for completion. Failing to do so will result in an unawaited future object.
- gotcha For cluster deployments, you must use `GlideClusterClient` and `GlideClusterClientConfiguration`. For standalone deployments, use `GlideClient` and `GlideClientConfiguration`. Using the wrong client type for your Redis/Valkey setup will result in connection or command execution errors.
- gotcha OpenTelemetry configuration can only be initialized once per process. If you need to change OpenTelemetry settings, your application must be restarted to apply the new configuration.
Install
-
pip install valkey-glide-sync
Imports
- GlideClient
from glide_sync import GlideClient
- GlideClusterClient
from glide_sync import GlideClusterClient
- GlideClientConfiguration
from glide_sync import GlideClientConfiguration
- NodeAddress
from glide_sync import NodeAddress
Quickstart
import os
from glide_sync import GlideClient, GlideClientConfiguration, NodeAddress
# Configure connection details (e.g., from environment variables)
HOST = os.environ.get('GLIDE_HOST', 'localhost')
PORT = int(os.environ.get('GLIDE_PORT', '6379'))
PASSWORD = os.environ.get('GLIDE_PASSWORD', '') # Optional
# For Standalone client
config = GlideClientConfiguration(
addresses=[NodeAddress(host=HOST, port=PORT)],
password=PASSWORD if PASSWORD else None # Set password only if provided
)
# Create and connect the client (sync method)
try:
client = GlideClient.create(config).get()
response = client.ping().get()
print(f"Ping response: {response}")
client.set('mykey', 'myvalue').get()
value = client.get('mykey').get()
print(f"Retrieved value for 'mykey': {value}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
if 'client' in locals() and client:
client.close()