Registry / database / fastify-session-redis-store

fastify-session-redis-store

JSON →
library7.1.2jsnpmunverified

Fastify Session Redis Store is a Redis-backed session store for @fastify/session, providing persistent session storage for Fastify applications. Current stable version is 7.1.2, released under a regular cadence with minor patches. It requires Node.js 16+ and @fastify/session version 10 or above. Key differentiators include full TypeScript support, ioredis compatibility, and simple integration with Fastify's session plugin. Unlike generic session stores, it is purpose-built for Fastify and @fastify/session, ensuring minimal configuration and optimal performance.

npm install fastify-session-redis-store
INSTALL
IMPORT
SIG · FASTIFY-SESSION-RE
F
fastify-session-redis-store
databasejavascriptv7.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FastifySessionRedisStore
import FastifySessionRedisStore from 'fastify-session-redis-store'
const FastifySessionRedisStore = require('fastify-session-redis-store')
Package is ESM-only. Use import syntax. For CommonJS, you must use dynamic import or transpilation.
RedisStoreOptions
import type { RedisStoreOptions } from 'fastify-session-redis-store'
TypeScript type for store options. Available since version 7.0.0.
FastifySessionRedisStore.default
import store from 'fastify-session-redis-store'
import { default as store } from 'fastify-session-redis-store'
Default export is the store class. Named default import is redundant.

Shows how to integrate Redis session store into a Fastify app with @fastify/redis and @fastify/session, including registration and a sample route using sessions.

import Fastify from 'fastify'; import fastifySession from '@fastify/session'; import FastifyRedis from '@fastify/redis'; import RedisStore from 'fastify-session-redis-store'; const app = Fastify(); await app.register(FastifyRedis, { host: '127.0.0.1', port: 6379 }); app.register(fastifySession, { secret: process.env.SESSION_SECRET ?? 'a secret with minimum length of 32 characters', cookie: { secure: false }, store: new RedisStore({ client: app.redis, prefix: 'sess:' }), }); app.get('/', async (request, reply) => { request.session.visits = (request.session.visits || 0) + 1; return { visits: request.session.visits }; }); await app.listen({ port: 3000 });
Debug
Known issues
breakingESM-only since v7.0.0. CommonJS require() no longer works.
fix
Use import syntax or migrate to ESM. For Node.js, set 'type': 'module' in package.json or use .mjs extension.
affects: >=7.0.0
gotchaStore must receive a Redis client from @fastify/redis, not a vanilla ioredis client.
fix
Use app.redis after registering @fastify/redis. Do not create a new ioredis client manually.
affects: *
breakingRemoved support for Node.js <16 as of v7.0.0.
fix
Upgrade Node.js to version 16 or higher.
affects: >=7.0.0
deprecatedDeprecated 'ttl' option in favor of session's ttl setting in @fastify/session.
fix
Use 'cookie.maxAge' or session configuration in @fastify/session instead of store options.
affects: >=6.0.0
gotchaIncompatible with @fastify/session versions <10. Will fail silently or throw errors.
fix
Ensure @fastify/session is version 10 or later.
affects: *
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.
Using CommonJS require() to load an ESM-only package.
fix
Switch to dynamic import: const RedisStore = (await import('fastify-session-redis-store')).default;
TypeError: client.hmset is not a function
Passing a vanilla Redis client instead of @fastify/redis client.
fix
Register @fastify/redis and use app.redis as the client.
Error: Cannot find module '@fastify/session'
Missing peer dependency @fastify/session.
fix
Run: npm install @fastify/session
ReferenceError: process is not defined
Using process.env in a browser or unsupported environment.
fix
Ensure the code runs in Node.js (not browser). For browser bundlers, provide environment variables via DefinePlugin or equivalent.
Upgrade
Version history
7.1.2latest on npm
Audit
Dependencies
@fastify/sessionrequiredPeer dependency - required for session management with Fastify
Agent activity
5 hits · last 30 days
node
4
Resources
fastify-session-redis-store — npm install fastify-session-redis-store · libregistry