Redis¶
Requires the redis extra:
uv add "rn-forge-auth[redis]"
rn_forge.auth.redis is not re-exported from rn_forge.auth — import it
directly:
from rn_forge.auth.redis import RedisSessionStore
rn_forge.auth.redis
¶
Redis implementations of the session, transaction, replay and version stores.
Requires the redis extra and Redis 6.2 or later.
RedisAuthorizationVersions(client, *, prefix=DEFAULT_PREFIX)
¶
:class:~rn_forge.auth.context_cache.AuthorizationVersions over Redis.
Each bump is an INCR, so it is visible to every process that shares the
Redis server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Redis
|
The Redis client. |
required |
prefix
|
str
|
Prepended to every key. |
DEFAULT_PREFIX
|
RedisReplayStore(client, *, prefix=DEFAULT_PREFIX)
¶
:class:~rn_forge.auth.stores.ReplayStore over Redis.
:meth:record_once is one SET ... NX EX.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Redis
|
The Redis client. |
required |
prefix
|
str
|
Prepended to every key. |
DEFAULT_PREFIX
|
RedisSessionStore(client, *, prefix=DEFAULT_PREFIX, clock=_utc_now)
¶
:class:~rn_forge.auth.stores.SessionStore over Redis.
Each session is a JSON value whose key expires at the earlier of the idle
expiry and SessionInfo.expires_at. :meth:rotate removes the old key
with GETDEL before it writes the new one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Redis
|
The Redis client. |
required |
prefix
|
str
|
Prepended to every key. |
DEFAULT_PREFIX
|
clock
|
Callable[[], datetime]
|
Returns the current time as an aware datetime. |
_utc_now
|
create(session, *, idle_ttl)
¶
Store session under a new random ID.
delete(session_id)
¶
Remove the session.
get(session_id)
¶
Return the session without changing its expiry.
rotate(session_id, *, idle_ttl)
¶
Move the session to a new ID.
touch(session_id, *, idle_ttl)
¶
Reset the key's expiry to the idle timeout, capped at expires_at.
RedisTransactionStore(client, *, prefix=DEFAULT_PREFIX)
¶
:class:~rn_forge.auth.stores.TransactionStore over Redis.
:meth:consume is one GETDEL, so exactly one caller receives a
transaction whichever process it runs in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Redis
|
The Redis client. |
required |
prefix
|
str
|
Prepended to every key. |
DEFAULT_PREFIX
|