v1.0.0-LTS — 95%+ Test Coverage

The Python Redis Swiss Army Knife

wredis is a production-grade Python library that wraps Redis into 12 elegant managers with dual sync/async APIs, cache decorators with hit/miss metrics, Sentinel and Cluster HA, and over 200 ready-to-run examples.

12

Data Structures

200+

Ready Examples

95%+

Test Coverage

Sync+Async

Dual APIs

LTS

Enterprise Ready

Core Capabilities

Redis, Reimagined

Every Redis primitive wrapped in a clean, type-safe, and resilient manager.

Dual Sync / Async

Full synchronous and asyncio APIs. Import from wredis.sync or wredis.aio — same ergonomics, zero lock-in.

Cache Decorators

@cache and @async_cache with built-in hit/miss/error metrics, TTL management, and custom key builders. Cache-Aside pattern in one line.

High Availability

Redis Sentinel auto-failover and Redis Cluster hash-slot routing. Automatic master discovery and replica detection.

Smart Retry Engine

Exponential backoff decorator for @retry and @async_retry. Configurable attempts, delays, and exception filtering.

Rich Error Hierarchy

12 exception types from WRedisError down to QueueError, StreamError, PubSubError. Catch precisely, never silence.

Validation & Safety

Built-in key length, TTL range, bitmap offset, score validity checks. Fail-fast before commands reach Redis.

Full Coverage

12 Data Structures, One Library

From Bitmaps to Streams — every Redis data type has a dedicated manager with CRUD + TTL + existence checks.

Bitmap

Set, get, count bits

RedisBitmapManager

Hash

CRUD, JSON serialize, TTL

RedisHashManager

Set

Add, members, membership, remove

RedisSetManager

Sorted Set

Rank, score, range, increment

RedisSortedSetManager

Queue

Thread consumers, gzip, retries

RedisQueueManager

Pub/Sub

Publish, subscribe, decorators

RedisPubSubManager

Streams

Consumer groups, XACK, XREAD

RedisStreamManager

Geo

Geoadd, distance, radius search

RedisGeoManager

HyperLogLog

Probabilistic counting, merge

RedisHyperLogLogManager

Pipeline

Batch commands, atomic sets

RedisPipelineManager

Transaction

WATCH/MULTI/EXEC, SET NX

RedisTransactionManager

Cache Decorator

@cache with hit-rate metrics

RedisCacheManager
Zero Boilerplate

One Import,
Full Control

Every manager is self-contained with connection pooling, retry logic, auto-decoding, and verbose logging built in. Use sync for simplicity, async for scale.

  • Connection pooling with retry-on-timeout
  • Automatic bytes-to-string decoding
  • Context manager support (with statement)
  • Full mypy type-safety, 0 warnings
from wredis.sync import RedisHashManager
from wredis.decorators import cache, CacheMetrics

# Track performance
metrics = CacheMetrics()

# One-line caching
@cache(ttl=60, metrics=metrics)
def get_user(user_id: str) -> dict:
    return {"id": user_id, "name": "Alice"}

# Hash operations
hm = RedisHashManager(host="localhost")
hm.create_hash("users", "u:1", {"role": "admin"}, ttl=300)
user = hm.read_hash("users", "u:1")

# Check metrics anytime
print(metrics) # CacheMetrics(hits=5, misses=2, ...)
High Availability

Production Hardened

Two HA strategies for mission-critical Redis deployments.

Redis Sentinel

SentinelRedisManager — automatic failover with master/slave topology.

  • Auto master discovery & failover
  • Slave read-replica support
  • Role detection (is_master)
  • Multi-node Sentinel support

Redis Cluster

ClusterRedisManager — distributed hash-slot routing at scale.

  • Automatic slot routing
  • Cluster state monitoring
  • Node & slot discovery
  • Replica wait & health checks
Learn by Example

200+ Examples, 15 Levels Deep

From "hello world" to advanced enterprise patterns — every concept is demonstrated with runnable code.

15 Levels

Sync Base

Init, health check, context managers, retry, FastAPI integration, connection pooling, error handling, custom managers, logging, multiple DBs, batch ops, pipelines, testing, pool monitoring.

15 Levels

Async Base

Async init, health check, context managers, retry, FastAPI integration, concurrent ops, connection pooling, error handling, custom managers, logging, multiple DBs, worker patterns, cache decorators, rate limiters.

15 Levels

Cache Patterns

Basic metrics, hit-rate monitoring, multi-zone cache, TTL impact, cache warming, invalidation, dashboard patterns, alerting, manual recording, async metrics, performance comparison, custom key builder, error handling.

15 Levels

Exception Handling

Exception hierarchy, specific error catching, custom messages, validation errors, operation recovery, transaction errors, serialization errors, logging integration, retry on specific errors, graceful degradation, queue/stream/pubsub error handling.

15 Levels

Retry Patterns

Basic retry, custom exceptions, backoff timing, Redis read/write ops, DB connection, API calls, circuit breaker, logging, wrapper pattern, batch ops, fallback, timeout, async retry, FastAPI integration.

15 Levels

Serialization

Basic, nested dicts, lists, unicode, none values, booleans, datetime, custom objects, large data, round-trip, error handling, tuples, long strings, Redis storage pattern.

Per Module

Data Structure Examples

Bitmap (read/write), Hash (CRUD), Sets, Sorted Sets, Queue (producer/consumer), Pub/Sub (pub/sub), Streams, Geo, HyperLogLog, Pipeline, Transaction — all with sync and async variants.

Bonus

HA & Environment

Sentinel basic, Cluster basic, Docker Compose with redislabs/redismod + Redis Commander UI.

Browse Examples Folder
W

Wisrovi Ecosystem

wredis is part of the Wisrovi library family — designed to bridge the gap between complex enterprise infrastructure and clean, maintainable Python code. Every library is fully typed, rigorously tested, and production-hardened.

Explore Wisrovi Libraries

Build Resilient Redis Systems

pip install wredis — one command, 12 data structures, infinite possibilities.