Skip to content

Redis

The Redis source reads mappings from a Redis database. It suits deployments where mappings change often, or are shared by several proxies. Every proxy reads the same store, and a change made by one is seen by all once their cache entries expire. Each proxy still caches lookups, so Redis is read only on cache misses.

[mapping]
source = "redis"
normalize = "lowercase"
[mapping.redis]
url = "redis://10.0.3.1:6379"
key_prefix = "route:"
pool_size = 16
KeyDefaultDescription
urlrequiredConnection URL of the Redis server.
key_prefixroute:Prefix added to each identifier to form the key.
pool_size16Number of connections kept open to the server.

The url follows the Redis URL syntax, with an optional password and database number. The proxy connects without TLS: a rediss:// URL is rejected at startup with invalid redis url. A Redis server on another host is therefore reached over a protected network.

Each mapping is a string value, under the key formed by key_prefix and the normalised identifier. With the default prefix, for example, the destination of [email protected] is read from route:[email protected]. A lookup is a GET, and a missing key or an empty value means that the account has no mapping:

GET route:[email protected] -> "legacy"
GET route:[email protected] -> "stalwart"

Mappings can be maintained with ordinary Redis commands:

Terminal window
redis-cli SET route:[email protected] stalwart
redis-cli DEL route:[email protected]

The Redis source can be written through the management API, which uses SET and DEL on the prefixed keys. The API lists Redis mappings with SCAN, matching the keys that start with the prefix. Redis cannot count the keys of one prefix cheaply, so the number of mappings, in total and per destination, is not reported for this source. A change made in Redis by another tool is seen by a proxy when the cache entry expires, or at once when the entry is invalidated through the management API.