Valkey GLIDE Sync Client

2.3.1 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a standalone Valkey or Redis OSS instance using the synchronous Glide client, perform a simple PING, SET, and GET operation, and then close the client. It uses environment variables for host and port, falling back to localhost:6379 for local testing. Remember to use `.get()` to retrieve results from the synchronous client's future-like return values.

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()

view raw JSON →