Redis session adapter
Session adapter for Redis provided by the Redis session adapter package. This only handles sessions, and not users or keys.
import { redis } from "@lucia-auth/adapter-session-redis";
const redis: (
client: RedisClientType,
prefixes?: {
session: string;
userSessions: string;
}
) => InitializeAdapter<SessionAdapter>;
Parameters#
name | type | optional | description |
---|---|---|---|
client | RedisClientType | Redis client | |
prefixes | Record<string, string> | ✓ | Key prefixes |
Installation#
npm i @lucia-auth/adapter-session-redis
pnpm add @lucia-auth/adapter-session-redis
yarn add @lucia-auth/adapter-session-redis
Key prefixes#
Key are defined as a combination of a prefix and an id so everything can be stored in a single Redis instance. By default, sessions are stored as session:<session_id>
and user-sessions relationships are stored as user_sessions:<user_id>
.
Usage#
import { lucia } from "lucia";
import { redis } from "@lucia-auth/adapter-session-redis";
import { createClient } from "redis";
const redisClient = createClient({
// ...
});
const auth = lucia({
adapter: {
user: userAdapter, // any normal adapter for storing users/keys
session: redis(redisClient)
}
// ...
});