Synchronous Client
Starting with version 2.1, Glide introduces a new synchronous Python client, alongside the existing default asynchronous client.
The following features were added to the sync client in subsequent releases:
| Feature | Version |
|---|---|
| Cluster Scan | v2.2.0 |
| In-flight Request Limit | v2.3.0 |
| OpenTelemetry | v2.3.0 |
| PubSub | v2.3.0 |
Installing
Section titled “Installing”The synchronous Python GLIDE client is available through pypi.
pip install valkey-glide-syncUsing the Synchronous Client
Section titled “Using the Synchronous Client”The synchronous client is located under the glide_sync module. Its API is similar to the asynchronous client making it interchangeable in most cases with the exception of not having to use the await keyword.
Example
Section titled “Example”The following example compares the synchronous vs asynchronous clients usage for a standalone configuration.
from glide_sync import ( GlideClient, GlideClientConfiguration, NodeAddress, BatchOptions, Batch)
addresses = [ NodeAddress(host="primary.example.com", port=6379), NodeAddress(host="replica1.example.com", port=6379), NodeAddress(host="replica2.example.com", port=6379) ]client_config = GlideClientConfiguration(addresses)
client = GlideClient.create(client_config)
# Configure batch optionsoptions = BatchOptions(timeout=2000) # 2-second timeout
pipeline = Batch()pipeline.set("key1", "value1")
results = client.exec(pipeline, options=options)print("Pipeline Results:", results)from glide import ( GlideClient, GlideClientConfiguration, NodeAddress, BatchOptions, Batch)
addresses = [ NodeAddress(host="primary.example.com", port=6379), NodeAddress(host="replica1.example.com", port=6379), NodeAddress(host="replica2.example.com", port=6379) ]client_config = GlideClientConfiguration(addresses)
client = await GlideClient.create(client_config)
# Configure batch optionsoptions = BatchOptions(timeout=2000) # 2-second timeout
pipeline = Batch()pipeline.set("key1", "value1")
results = await client.exec(pipeline, options=options)print("Pipeline Results:", results)