By default, PyBreaker stores circuit breaker state in local memory viaDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/danielfm/pybreaker/llms.txt
Use this file to discover all available pages before exploring further.
CircuitMemoryStorage. This means every process or application instance maintains its own independent circuit state — one instance can have an open circuit while another runs normally. For multi-process or multi-instance deployments (e.g., multiple web workers, containerised services, or horizontally scaled APIs), use CircuitRedisStorage to share state across all instances so they act as a single coordinated circuit breaker.
Installation
Basic Redis Setup
Create a Redis connection and pass aCircuitRedisStorage instance as the state_storage argument when constructing your circuit breaker.
CircuitRedisStorage is the initial state — the state written to Redis if no key exists yet. Use pybreaker.STATE_CLOSED to start the circuit closed (normal operation).
Using with Django Redis
If your project usesdjango-redis, you can obtain the configured Redis connection from Django’s cache backend and pass it directly to CircuitRedisStorage.
default cache backend in settings.py is not configured with OPTIONS: {"CLIENT_CLASS": "...", "DECODE_RESPONSES": True} — see the warning above.
Multiple Breakers with Namespaces
When you have more than one circuit breaker sharing the same Redis connection, each breaker must be given a uniquenamespace. Without namespaces, all breakers write to the same Redis keys and will corrupt each other’s state.
<namespace>:pybreaker:<key>. Without a namespace, keys are stored as pybreaker:<key>.
Fallback State
If Redis becomes unavailable (e.g., connection refused, timeout),CircuitRedisStorage falls back to a configurable default state rather than crashing. The fallback_circuit_state parameter controls this behaviour.
fallback_circuit_state=pybreaker.STATE_CLOSED means that when Redis is unreachable, the circuit breaker will allow calls through (fail open). If you prefer to block calls when Redis is down, set fallback_circuit_state=pybreaker.STATE_OPEN.
Redis Cluster Mode
Standard Redis transactions (MULTI/EXEC) are not supported in Redis Cluster deployments when keys span multiple hash slots. Enable cluster_mode=True to use a non-transactional write path that is compatible with Redis Cluster.
Redis Keys
CircuitRedisStorage maintains four keys in Redis per circuit breaker instance. The key format is pybreaker:<key> when no namespace is set, or <namespace>:pybreaker:<key> when a namespace is provided.
| Key | Description |
|---|---|
fail_counter | Current consecutive failure count |
success_counter | Current consecutive success count (used in half-open state) |
state | Current state string — one of closed, open, or half-open |
opened_at | Unix timestamp (integer) of when the circuit was last opened |
