Skip to content

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 ​

terminalbash
export RILLKIT_URL=redis://localhost:6379/0
pythonpython
from 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.

VariableAlso read asDefaultNotes
RILLKIT_URLREDIS_URLnoneThe server URL: redis://, rediss:// (TLS) or unix://. On a cluster, one seed node
RILLKIT_HOSTREDIS_HOSTlocalhostused when no URL is set
RILLKIT_PORTREDIS_PORT6379used when no URL is set
RILLKIT_DBREDIS_DB0used when no URL is set
RILLKIT_USERNAMEREDIS_USERNAMEnoneused when no URL is set
RILLKIT_PASSWORDREDIS_PASSWORDnoneused when no URL is set
RILLKIT_SSLREDIS_SSLoff1, true or yes (any case) turn TLS on. Used when no URL is set
RILLKIT_SOCKET_TIMEOUTREDIS_SOCKET_TIMEOUT15seconds, or none for no timeout. Must be longer than block_ms (see below)
RILLKIT_MAX_CONNECTIONSREDIS_MAX_CONNECTIONSclient defaultConnection-pool cap. redis-py 8 defaults to 100; raise it for producers with many threads or consumers with 100+ lanes
RILLKIT_BACKENDredisThe client library: redis (redis-py) or valkey (valkey-py)
RILLKIT_MODEstandalonestandalone or cluster
RILLKIT_CLUSTER_NODESnoneCluster seed nodes, host:port,host:port
RILLKIT_KEY_LAYOUTdepends on modeplain or hashtag, see Keys
RILLKIT_KEY_PREFIXnoneA prefix for hash-tagged keys, for several apps on one server. Implies hashtag
RILLKIT_TENANTnoneA tenant id inside every hash tag. Implies hashtag with the prefix rk
RILLKIT_CONFIGnonePath of a config file
RILLKIT_CONTROLoffoff or relay, see Control plane
RILLKIT_CONTROL_URLnonerelay mode: the url of rillkit-server
RILLKIT_API_KEYnonerelay mode: the worker's API key
RILLKIT_NODE_ID<hostname>-<pid>The node's name on the control plane
RILLKIT_CAPTURE_LOGSoffStore each handler run's logs for the dashboard (log capture)
RILLKIT_INSPECT_MESSAGESoffLet the dashboard show payloads and DLQ error texts, and edit DLQ entries (control plane)
RILLKIT_TRACE_RECORDSoffKeep per-trace records, so the dashboard can draw a trace across streams (control plane)
RILLKIT_CONTROL_INSECUREoffAllow a ws:///http:// control url on a non-local host

A URL or separate fields, whichever suits your platform:

URLbash
export RILLKIT_URL="rediss://app:secret@cache.internal:6379/0"
Separate fieldsbash
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
terminalbash
# 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:7000

The 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:

  1. Keyword arguments to Settings.from_env(...), such as Settings.from_env(backend="valkey").
  2. A URL: RILLKIT_URL, else REDIS_URL (<prefix>URL).
  3. Without a URL, the separate fields: for each one, RILLKIT_<NAME>, else REDIS_<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.

g_config.pypython
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)
outputtext
Valkey True PlainKeys()
Settings(url='redis://app:***@localhost:6380/0'
redis standalone redis://localhost:6379/0
redis://localhost:6380/0

Broker.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]".

rillkit.tomltoml
[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"
pythonpython
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_key and a url with a password in it are refused. Use <name>_env or <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:

terminalbash
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.

BackendStandaloneCluster
redis (default)redis.Redisredis.RedisCluster
valkeyvalkey.Valkeyvalkey.ValkeyCluster

For clusters, see Redis and Valkey Cluster.

Credentials in URLs ​

terminalbash
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 TLS

Characters 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:

pythonpython
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. username and password set separately on Settings are used only when the URL has none.
  • Settings.from_env() does not read RILLKIT_USERNAME/RILLKIT_PASSWORD (or REDIS_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 ​

pythonpython
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:

pythonpython
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:

pythonpython
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 ConfigurationError naming it.
  • Options with their own Settings field (host, port, db, username, password, ssl, and startup_nodes, which is cluster_nodes) are refused in client_kwargs. Set the field instead.
  • socket_timeout is allowed in both places; client_kwargs wins.
  • 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):

RILLKIT_URLbash
export RILLKIT_URL="rediss://default:YOUR_PASSWORD@eu1-example-12345.upstash.io:6379"
Separate fieldsbash
export RILLKIT_HOST=eu1-example-12345.upstash.io
export RILLKIT_PORT=6379
export RILLKIT_PASSWORD=YOUR_PASSWORD
export RILLKIT_SSL=true
In codepython
broker = 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):

pythonpython
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_timeout shorter than block_ms makes 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 default socket_timeout is 5 seconds, the same as the default block_ms. Clients that RillKit builds from Settings use 15 seconds.
  • broker.stop() closes the client, so do not share a client you still need afterwards.

Supported versions ​

SupportedTested in CI
Python3.9 to 3.133.9, 3.10, 3.11, 3.12, 3.13
redis-py5.0 and newerthe locked version (7.0 on Python 3.9, 8.x on newer) and the newest release
valkey-py6.1.1 to 6.2.x6.1.1 on Python 3.9 and 3.10, 6.2 on 3.11 and newer (6.2 needs Python 3.11)
Redis server6.2 and newerRedis 7, standalone and cluster
Valkey server7.2 and newerValkey 8, standalone and cluster

The RillKit SDKs are released under the Apache License 2.0.