Configuration
A Broker needs a connection to a Redis or Valkey server. The recommended way is environment variables read by Broker.from_env(), so the same code runs locally, in CI and in production. You can also pass a URL, a Settings object, or a client you built yourself.
Environment variables
export RILLKIT_URL=redis://localhost:6379/0from rillkit import Broker
broker = Broker.from_env()Broker.from_env() (and Settings.from_env()) read these. Every connection variable also has the name RillKit 0.1 used, so existing deployments need no change; when both are set, the RILLKIT_ one wins.
| Variable | Also read as | Default | Notes |
|---|---|---|---|
RILLKIT_URL | REDIS_URL | none | The server URL: redis://, rediss:// (TLS) or unix://. On a cluster, one seed node |
RILLKIT_HOST | REDIS_HOST | localhost | used when no URL is set |
RILLKIT_PORT | REDIS_PORT | 6379 | used when no URL is set |
RILLKIT_DB | REDIS_DB | 0 | used when no URL is set |
RILLKIT_USERNAME | REDIS_USERNAME | none | used when no URL is set |
RILLKIT_PASSWORD | REDIS_PASSWORD | none | used when no URL is set |
RILLKIT_SSL | REDIS_SSL | off | 1, true or yes (any case) turn TLS on. Used when no URL is set |
RILLKIT_SOCKET_TIMEOUT | REDIS_SOCKET_TIMEOUT | 15 | seconds, or none for no timeout. Must be longer than block_ms (see below) |
RILLKIT_MAX_CONNECTIONS | REDIS_MAX_CONNECTIONS | client default | Connection-pool cap. redis-py 8 defaults to 100; raise it for producers with many threads or consumers with 100+ lanes |
RILLKIT_BACKEND | redis | The client library: redis (redis-py) or valkey (valkey-py) | |
RILLKIT_MODE | standalone | standalone or cluster | |
RILLKIT_CLUSTER_NODES | none | Cluster seed nodes, host:port,host:port | |
RILLKIT_KEY_LAYOUT | depends on mode | plain or hashtag, see Keys | |
RILLKIT_KEY_PREFIX | none | A prefix for hash-tagged keys, for several apps on one server. Implies hashtag | |
RILLKIT_TENANT | none | A tenant id inside every hash tag. Implies hashtag with the prefix rk | |
RILLKIT_CONFIG | none | Path of a config file | |
RILLKIT_CONTROL | off | off or relay, see Control plane | |
RILLKIT_CONTROL_URL | none | relay mode: the url of rillkit-server | |
RILLKIT_API_KEY | none | relay mode: the worker's API key | |
RILLKIT_NODE_ID | <hostname>-<pid> | The node's name on the control plane | |
RILLKIT_CAPTURE_LOGS | off | Store each handler run's logs for the dashboard (log capture) | |
RILLKIT_INSPECT_MESSAGES | off | Let the dashboard show payloads and DLQ error texts, and edit DLQ entries (control plane) | |
RILLKIT_TRACE_RECORDS | off | Keep per-trace records, so the dashboard can draw a trace across streams (control plane) | |
RILLKIT_CONTROL_INSECURE | off | Allow a ws:///http:// control url on a non-local host |
A URL or separate fields, whichever suits your platform:
export RILLKIT_URL="rediss://app:secret@cache.internal:6379/0"export RILLKIT_HOST=cache.internal
export RILLKIT_PORT=6379
export RILLKIT_DB=0
export RILLKIT_USERNAME=app
export RILLKIT_PASSWORD=secret
export RILLKIT_SSL=true# Valkey with valkey-py
export RILLKIT_URL=redis://valkey.internal:6379/0
export RILLKIT_BACKEND=valkey
# a cluster
export RILLKIT_MODE=cluster
export RILLKIT_CLUSTER_NODES=10.0.0.1:7000,10.0.0.2:7000,10.0.0.3:7000The 0.1 names take the prefix you pass, so Settings.from_env("MYAPP_REDIS_") falls back to MYAPP_REDIS_URL, MYAPP_REDIS_HOST and so on. The RILLKIT_ names are always read as they are. An empty variable counts as unset.
Precedence
From strongest to weakest:
- Keyword arguments to
Settings.from_env(...), such asSettings.from_env(backend="valkey"). - A URL:
RILLKIT_URL, elseREDIS_URL(<prefix>URL). - Without a URL, the separate fields: for each one,
RILLKIT_<NAME>, elseREDIS_<NAME>.
A URL replaces the host, port, database, username, password and TLS variables, and those are not read when one is set (in either naming). If you set one of their RILLKIT_ names next to a URL anyway, RillKit logs a warning naming the ignored variables. RILLKIT_SOCKET_TIMEOUT applies either way.
Without RILLKIT_BACKEND the backend is Redis, and without RILLKIT_MODE the mode is standalone, so a deployment that only sets REDIS_URL (or REDIS_HOST and friends) behaves exactly as before.
import os
from rillkit import Broker, Settings
# the RILLKIT_* variables
os.environ.update(RILLKIT_URL="redis://localhost:6380/0", RILLKIT_BACKEND="valkey")
broker = Broker.from_env()
print(type(broker.client).__name__, broker.client.ping(), broker.keys)
# credentials in the url are percent-encoded, and never printed
os.environ["RILLKIT_URL"] = "redis://app:s3cr%40t@localhost:6380/0"
print(repr(Settings.from_env()).split(", host")[0])
# an older deployment that only sets REDIS_URL behaves as before
for name in ("RILLKIT_URL", "RILLKIT_BACKEND"):
del os.environ[name]
os.environ["REDIS_URL"] = "redis://localhost:6379/0"
legacy = Settings.from_env()
print(legacy.backend, legacy.mode, legacy.url)
# when both are set, RILLKIT_URL wins
os.environ["RILLKIT_URL"] = "redis://localhost:6380/0"
print(Settings.from_env().url)Valkey True PlainKeys()
Settings(url='redis://app:***@localhost:6380/0'
redis standalone redis://localhost:6379/0
redis://localhost:6380/0Broker.from_env(prefix="REDIS_", **kwargs) passes extra keyword arguments such as middlewares=[...] or keys=... to Broker. To override settings, build them yourself: Broker(settings=Settings.from_env(backend="valkey")).
Config file
Optional. RillKit reads one only when RILLKIT_CONFIG=<path> or config=<path> names it; a file in the working directory is never picked up on its own. TOML and JSON work out of the box, YAML with pip install "rillkit[yaml]".
[connection] # Settings fields, same names as the RILLKIT_* variables
url = "rediss://cache.internal:6379/0"
backend = "valkey"
mode = "cluster"
password_env = "CACHE_PASSWORD" # the variable that holds it, or password_file = "/run/secrets/pw"
[keys]
layout = "hashtag" # or prefix = "shop", tenant = "t-42"
[control]
mode = "relay"
url = "https://rillkit.example.com"
api_key_env = "RILLKIT_API_KEY"broker = Broker.from_env(config="rillkit.toml") # or RILLKIT_CONFIG=rillkit.toml- The environment wins over the file, and code wins over both.
- Secrets are referenced, never stored:
password,api_keyand aurlwith a password in it are refused. Use<name>_envor<name>_file. - An unknown section or field raises
ConfigurationError.
Redis or Valkey
RillKit talks to the server through either client library. redis-py is the default and is always installed. valkey-py is an optional extra:
pip install "rillkit[valkey]"Then set RILLKIT_BACKEND=valkey, or Settings(backend="valkey") in code.
The backend chooses the client library, not the server: both libraries talk to both servers, since Valkey keeps the Redis protocol, and URLs use the redis:// and rediss:// schemes with either one. Everything else in RillKit (streams, retries, the DLQ, middleware) behaves the same.
| Backend | Standalone | Cluster |
|---|---|---|
redis (default) | redis.Redis | redis.RedisCluster |
valkey | valkey.Valkey | valkey.ValkeyCluster |
For clusters, see Redis and Valkey Cluster.
Credentials in URLs
export RILLKIT_URL="redis://username:password@hostname:6379/0" # ACL user
export RILLKIT_URL="redis://:password@hostname:6379/0" # password only (the default user)
export RILLKIT_URL="rediss://username:password@hostname:6379/0" # the same over TLSCharacters that mean something in a URL (@ : / % # ? and so on) must be percent-encoded in the username and password. p@ss:w/rd becomes p%40ss%3Aw%2Frd. In Python:
from urllib.parse import quote
url = f"rediss://{quote(user, safe='')}:{quote(password, safe='')}@redis.example.com:6379/0"Which credentials win when there are two sources:
- Credentials in the URL win.
usernameandpasswordset separately onSettingsare used only when the URL has none. Settings.from_env()does not readRILLKIT_USERNAME/RILLKIT_PASSWORD(orREDIS_USERNAME/REDIS_PASSWORD) when a URL is set, the same as RillKit 0.1. Put the credentials in the URL, or use the separate fields without one.
Passwords never appear in the repr of a Settings (or in its URL), so logging a Settings is safe.
In code
A URL
broker = Broker("redis://localhost:6379/0")
broker = Broker("redis://:secret@redis.internal:6379/2")With no arguments, Broker() connects to localhost:6379, db 0, with redis-py.
Settings
Settings is a dataclass with every option, including the ones that have no environment variable:
from rillkit import Broker, Settings
broker = Broker(settings=Settings(
backend="valkey",
url="rediss://app:secret@valkey.internal:6379/0",
client_kwargs={"health_check_interval": 30},
))
broker = Broker(settings=Settings(
host="redis.internal", port=6380, db=2, username="app", password="secret", ssl=True,
))If url is set, host, port, db and ssl are ignored (the URL says all of that).
Client options
client_kwargs passes any other option straight to the client constructor: timeouts, pool size, health checks, decoding, TLS certificates. It has no environment variable, so combine it with the environment like this:
from rillkit import Broker, Settings
broker = Broker(settings=Settings.from_env(
max_connections=500, # or RILLKIT_MAX_CONNECTIONS=500
client_kwargs={
"socket_connect_timeout": 5,
"socket_timeout": 15,
"health_check_interval": 30,
"ssl_ca_certs": "/etc/ssl/certs/ca.pem",
},
))The connection pool is capped at 100 with redis-py 8
A Broker shares one client and therefore one pool. Every command in flight borrows a connection; when the pool is empty and its cap is reached, the next command fails with Too many connections instead of waiting. A producer with many threads (or a web app) can hit that quickly; so can a consumer with more than 100 lanes.
Set max_connections (RILLKIT_MAX_CONNECTIONS) to peak concurrent commands plus headroom. It is per process: with several worker processes, each gets its own pool, so keep processes × max_connections under the server's maxclients. If you would rather wait than fail, inject a client built on BlockingConnectionPool with Broker(client=...). valkey-py defaults its pool to effectively unlimited, so this only bites redis-py users.
The options are checked against the client that will be built, so a typo fails at once instead of being dropped:
- An option the client does not accept raises
ConfigurationErrornaming it. - Options with their own
Settingsfield (host,port,db,username,password,ssl, andstartup_nodes, which iscluster_nodes) are refused inclient_kwargs. Set the field instead. socket_timeoutis allowed in both places;client_kwargswins.- Cluster clients forward only some options to their nodes and silently ignore the rest. RillKit refuses an option the cluster client would ignore, and a cluster-only option (such as
require_full_coverage) in standalone mode.
Which options exist depends on the client library and its version. The redis-py and valkey-py lists are similar but not identical (for example ssl_check_hostname is redis-py only).
TLS and managed Redis or Valkey (Upstash and friends)
Hosted services usually require TLS. Use a rediss:// URL (note the double s):
export RILLKIT_URL="rediss://default:YOUR_PASSWORD@eu1-example-12345.upstash.io:6379"export RILLKIT_HOST=eu1-example-12345.upstash.io
export RILLKIT_PORT=6379
export RILLKIT_PASSWORD=YOUR_PASSWORD
export RILLKIT_SSL=truebroker = Broker("rediss://default:YOUR_PASSWORD@eu1-example-12345.upstash.io:6379")Certificate options (ssl_ca_certs, ssl_certfile, ssl_keyfile, ssl_cert_reqs, ...) go in client_kwargs.
Blocking reads and server timeouts
RillKit blocks in XREADGROUP for up to block_ms (5 seconds by default). Some managed proxies close idle connections or limit command duration. If you see repeated connection errors in the logs, lower block_ms and check the provider's idle timeout. RillKit logs the error and retries after 5 seconds rather than crashing.
Bring your own client
Pass any client you have configured: redis.Redis, redis.RedisCluster, valkey.Valkey or valkey.ValkeyCluster (custom pools, retries, Sentinel, and so on):
import valkey
from rillkit import Broker
client = valkey.Valkey(host="valkey.internal", socket_timeout=10, health_check_interval=30)
broker = Broker(client=client)RillKit uses the client as it is and does not build another one. It picks the key layout from the client type: plain names for a standalone client, hash-tagged names for a cluster client. It works with both decode_responses=False (the default) and True. Two cautions:
- A client
socket_timeoutshorter thanblock_msmakes blocking reads time out. RillKit checks the client's timeout when the consumer starts and, if needed, shortens its own blocking reads to one second under it, logging a warning. This matters on redis-py 8, whose defaultsocket_timeoutis 5 seconds, the same as the defaultblock_ms. Clients that RillKit builds fromSettingsuse 15 seconds. broker.stop()closes the client, so do not share a client you still need afterwards.
Supported versions
| Supported | Tested in CI | |
|---|---|---|
| Python | 3.9 to 3.13 | 3.9, 3.10, 3.11, 3.12, 3.13 |
| redis-py | 5.0 and newer | the locked version (7.0 on Python 3.9, 8.x on newer) and the newest release |
| valkey-py | 6.1.1 to 6.2.x | 6.1.1 on Python 3.9 and 3.10, 6.2 on 3.11 and newer (6.2 needs Python 3.11) |
| Redis server | 6.2 and newer | Redis 7, standalone and cluster |
| Valkey server | 7.2 and newer | Valkey 8, standalone and cluster |