Skip to content

RedisSessionStore

The SessionStore on Redis.

  • SessionStore

new RedisSessionStore(redis, options?): RedisSessionStore

Redis

RedisSessionStoreOptions = {}

RedisSessionStore

readonly epochTtlMs: number

How long a user’s epoch outlives its last write; createAuth refuses a device token that is not a clock skew shorter.

SessionStore.epochTtlMs


readonly maxSessionTtlMs: number

The longest session this store guards; createAuth refuses a longer remember-me TTL.

SessionStore.maxSessionTtlMs

bumpEpoch(userId): Promise<number>

Atomically increments and returns the epoch. Its TTL must outlive every session.

string

Promise<number>

SessionStore.bumpEpoch


create(session, ttlMs): Promise<void>

Stores the session with a TTL of ttlMs and indexes it under its user.

StoredSession

number

Promise<void>

SessionStore.create


delete(userId, ids): Promise<string[]>

Deletes the sessions and removes them from the user’s index. Should return the ids this call removed (the ones that still existed), so that of concurrent deletes of one session exactly one reports it: the per-user cap reports evictions from it. A store that returns nothing is taken to have removed every id it was given, and racing evictions may then report a session twice.

string

readonly string[]

Promise<string[]>

SessionStore.delete


epochTtlRemaining(userId): Promise<number>

Remaining TTL of the user’s epoch in ms (-2 when absent).

string

Promise<number>


get(id): Promise<StoredSession<unknown> | null>

string

Promise<StoredSession<unknown> | null>

SessionStore.get


getEpoch(userId): Promise<number>

The user’s revocation epoch; 0 when never bumped.

string

Promise<number>

SessionStore.getEpoch


listByUser(userId): Promise<StoredSession<unknown>[]>

The user’s sessions that still exist (expired ones are not returned).

string

Promise<StoredSession<unknown>[]>

SessionStore.listByUser


touch(session): Promise<boolean>

Replaces the stored value ONLY IF the session still exists, keeping its TTL (Redis: SET ... XX KEEPTTL). Returns false when it is gone. Must never recreate a deleted session, even when racing a delete.

StoredSession

Promise<boolean>

SessionStore.touch