Redis Sentinel client with mandatory mutual TLS for high-availability Redis clusters
Project description
grass-redis
Redis Sentinel client with mandatory mutual TLS.
Features
- Automatic failover via Sentinel
- Connection pooling and caching
- Read replicas for load distribution
- Mandatory TLS with client certificates
Installation
pip install -e libs/python/grass-redis
Quick Start
from pathlib import Path
from grass_redis import (
RedisSentinelClient,
SentinelConfig,
load_passwords_from_env,
load_sentinel_hosts_from_env,
)
# Load from environment (never hardcode)
sentinel_hosts = load_sentinel_hosts_from_env() # $REDIS_SENTINEL_HOSTS
passwords = load_passwords_from_env() # /etc/redis/certs/passwords.env
config = SentinelConfig(
sentinel_hosts=sentinel_hosts,
databases=passwords,
certs_dir=Path("/etc/redis/certs"),
)
with RedisSentinelClient(config) as client:
primary = client.get_primary("db1")
primary.set("key", "value")
replica = client.get_replica("db1")
value = replica.get("key")
Configuration
Environment (optional):
export REDIS_SENTINEL_HOSTS="host1:26379,host2:26379,host3:26379"
Deploy certs via Ansible to /etc/redis/certs/:
client.crt- Client certificate (644)client.key- Private key (600)ca.crt- CA certificate (644)passwords.env- Passwords (600)
passwords.env format:
REDIS_SCRAPER_DB1_PASSWORD=xxx
REDIS_SCRAPER_DB2_PASSWORD=yyy
Names are converted: REDIS_SCRAPER_DB1_PASSWORD → database scraper-db1
API
SentinelConfig:
sentinel_hosts- List[(host, port)]databases- Dict[db_name, password]certs_dir- Path (default: /etc/redis/certs)
RedisSentinelClient:
get_primary(db)- Connection for writesget_replica(db)- Connection for readsdiscover_primary(db)- Get current primary addresstest_connection(db)- PING test
See grass-platform/reference_implementation/python/redis/ for examples.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grass_redis-0.1.0.tar.gz.
File metadata
- Download URL: grass_redis-0.1.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc90c8e14479b6c4cc70444853374406d6b02780e03668dd777e2d04056aa1d9
|
|
| MD5 |
03751c883b4d102c20647176941a0a10
|
|
| BLAKE2b-256 |
77c75d01d4be7903c2c8a5dc408ef4a14f5ebe5f442647d9cb52b61d4a137838
|
File details
Details for the file grass_redis-0.1.0-py3-none-any.whl.
File metadata
- Download URL: grass_redis-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28707d77f024e21baa06c04b827c686900133799979ad3e35c18c8f6f422ac6b
|
|
| MD5 |
6555a91fa6972a6c6abb34d7bf3b3a05
|
|
| BLAKE2b-256 |
056192a7ee8cc3a21fcda07cc9fa911850418a3007087c2e4aaf638d1e42b724
|