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
    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.
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 key layout.
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.

VariableMaps toDefault if unset
RILLKIT_URLurl (wins over <prefix>URL)None
<prefix>URLurlNone
<prefix>HOSThost"localhost"
<prefix>PORTport (as int)6379
<prefix>DBdb (as int)0
<prefix>USERNAMEusername, only without a URLNone
<prefix>PASSWORDpassword, only without a URLNone
<prefix>SSLssl: true for 1, true, yes (any case)False
<prefix>SOCKET_TIMEOUTsocket_timeout: seconds, or none/off/015.0
RILLKIT_BACKENDbackend"redis"
RILLKIT_MODEmode"standalone"
RILLKIT_CLUSTER_NODEScluster_nodes, comma-separated()
RILLKIT_KEY_LAYOUTkey_layoutNone

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.

RillKit is released under the MIT License.