Skip to main content

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 writes
  • get_replica(db) - Connection for reads
  • discover_primary(db) - Get current primary address
  • test_connection(db) - PING test

See grass-platform/reference_implementation/python/redis/ for examples.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grass_redis-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grass_redis-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

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

Hashes for grass_redis-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bc90c8e14479b6c4cc70444853374406d6b02780e03668dd777e2d04056aa1d9
MD5 03751c883b4d102c20647176941a0a10
BLAKE2b-256 77c75d01d4be7903c2c8a5dc408ef4a14f5ebe5f442647d9cb52b61d4a137838

See more details on using hashes here.

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

Hashes for grass_redis-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28707d77f024e21baa06c04b827c686900133799979ad3e35c18c8f6f422ac6b
MD5 6555a91fa6972a6c6abb34d7bf3b3a05
BLAKE2b-256 056192a7ee8cc3a21fcda07cc9fa911850418a3007087c2e4aaf638d1e42b724

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page