Redis
Requires the redis extra:
rn_forge.auth.redis is not re-exported from rn_forge.auth — import it
directly:
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
|
bump(account_id)
Increase the account's version.
bump_all()
Increase the global version.
current(account_id)
Read the account and global versions with one MGET.
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
|
is_sid_revoked(issuer, sid)
Return whether the revocation key exists.
record_once(key, *, ttl)
Record key with SET NX EX.
revoke_sid(issuer, sid, *, ttl)
Mark the session revoked with SET EX.
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
|
consume(transaction_id)
Remove and return the transaction with GETDEL.
save(transaction, *, ttl)
Store transaction with SET ... EX.