Skip to content

Settings ​

pythonpython
from rillkit import Settings
pythonpython
@dataclass
class Settings:
    url: Optional[str] = None
    host: str = "localhost"
    port: int = 6379
    db: int = 0
    password: Optional[str] = None
    ssl: bool = False
    socket_timeout: Optional[float] = 15.0
    max_connections: Optional[int] = None
    backend: str = "redis"
    mode: str = "standalone"
    username: Optional[str] = None
    cluster_nodes: Sequence[Union[str, tuple[str, int]]] = ()
    key_layout: Optional[str] = None
    client_kwargs: Mapping[str, Any] = field(default_factory=dict)
FieldDefaultDescription
urlNoneA URL (redis://, rediss://, unix://). If set, host, port, db and ssl are ignored. On a cluster it is one seed node.
host"localhost"Server host (or the seed node on a cluster without url and cluster_nodes).
port6379Server port.
db0Database number. Must be 0 on a cluster.
passwordNonePassword. Used only when url has no credentials.
sslFalseUse TLS.
socket_timeout15.0Read timeout in seconds, None for none. Keep it above block_ms.
max_connectionsNoneCap on the client's connection pool. None keeps the client library's default: 100 with redis-py 8, effectively unlimited with valkey-py. Raise it for producers with many threads or consumers with more than 100 lanes; the next command otherwise fails with Too many connections.
backend"redis""redis" (redis-py) or "valkey" (valkey-py, needs rillkit[valkey]).
mode"standalone""standalone" or "cluster".
usernameNoneACL username. Used only when url has no credentials.
cluster_nodes()Cluster seed nodes: "host:port" or (host, port). A comma-separated string also works.
key_layoutNone"plain" or "hashtag"; None means plain standalone and hash-tagged on a cluster. See Keys.
client_kwargs{}Extra options for the client constructor, checked against what that client accepts. See client options.

Invalid values raise ConfigurationError when the Settings is created (backend, mode, key_layout, cluster_nodes) or when the client is built (client_kwargs, cluster database).

The repr hides passwords, the password in url, and client_kwargs values whose name contains password, secret, token or credential.

Settings.from_env ​

pythonpython
Settings.from_env(prefix: str = "REDIS_", **overrides) -> Settings

Reads these environment variables. Keyword arguments override them. For each connection field a non-empty RILLKIT_ variable wins over the <prefix> one (REDIS_ by default); an empty one counts as unset.

VariableFallbackMaps toDefault if unset
RILLKIT_URL<prefix>URLurlNone
RILLKIT_HOST<prefix>HOSThost"localhost"
RILLKIT_PORT<prefix>PORTport (as int)6379
RILLKIT_DB<prefix>DBdb (as int)0
RILLKIT_USERNAME<prefix>USERNAMEusername, only without a URLNone
RILLKIT_PASSWORD<prefix>PASSWORDpassword, only without a URLNone
RILLKIT_SSL<prefix>SSLssl: true for 1, true, yes (any case)False
RILLKIT_SOCKET_TIMEOUT<prefix>SOCKET_TIMEOUTsocket_timeout: seconds, or none/off/015.0
RILLKIT_MAX_CONNECTIONS<prefix>MAX_CONNECTIONSmax_connections (as int)None (client default)
RILLKIT_BACKENDbackend"redis"
RILLKIT_MODEmode"standalone"
RILLKIT_CLUSTER_NODEScluster_nodes, comma-separated()
RILLKIT_KEY_LAYOUTkey_layoutNone
RILLKIT_KEY_PREFIXkey_prefixNone
RILLKIT_TENANTtenantNone

Settings.from_env(prefix="REDIS_", *, config=None, **overrides): config (else RILLKIT_CONFIG) names a config file whose [connection] and [keys] sections fill in what the environment leaves unset.

When a URL is set, the username and password variables are not read, and host, port, db and ssl are ignored by the client. Setting RILLKIT_HOST, PORT, DB, USERNAME, PASSWORD or SSL next to a URL logs a warning on the rillkit logger.

Settings.client ​

pythonpython
Settings.client() -> redis.Redis | redis.RedisCluster | valkey.Valkey | valkey.ValkeyCluster

Builds a new client for backend and mode:

  • standalone with url: Redis.from_url(url, ...) (or Valkey.from_url)
  • standalone without: Redis(host=..., port=..., db=..., ssl=..., ...)
  • cluster: RedisCluster(startup_nodes=[...], ...), or RedisCluster.from_url(url, startup_nodes=[...], ...) with a URL

plus socket_timeout, username/password when they apply, and client_kwargs.

Settings.key_builder ​

pythonpython
Settings.key_builder() -> KeyBuilder

The key builder for key_layout, or the default for mode.

See Configuration and Redis and Valkey Cluster.

The RillKit SDKs are released under the Apache License 2.0.