Registry / storage / fastify-redis-session

fastify-redis-session

JSON →
library2.0.0jsnpmunverified

Redis store for fastify-session using ioredis. Current stable version is 2.0.0, released 2020-12-14. It integrates with @mgcrea/fastify-session to provide Redis-backed session storage for Fastify applications. Differentiators: uses ioredis (modern Redis client with Cluster/Sentinel support), ships TypeScript definitions, lightweight store implementation. Alternative to connect-redis for Koa/Express ecosystems. Release cadence is low; last release over 3 years ago.

npm install fastify-redis-session
INSTALL
IMPORT
SIG · FASTIFY-REDIS-SESS
F
fastify-redis-session
storagejavascriptv2.0.0
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.

RedisStore
import { RedisStore } from 'fastify-redis-session'
const RedisStore = require('fastify-redis-session')
Named export; not default. Works in both ESM and CJS contexts due to TypeScript compilation.
FastifySessionOptions
import { FastifySessionOptions } from '@mgcrea/fastify-session'
import { FastifySessionOptions } from 'fastify-redis-session'
Type is re-exported from fastify-session, not from this package.
RedisStore (type)
import type { RedisStore } from 'fastify-redis-session'
import { RedisStore } from 'fastify-redis-session'
TypeScript allows extracting type separately; not required but reduces bundle.

Sets up a Fastify server with Redis-backed session storage using fastify-redis-session.

import fastify from 'fastify'; import fastifyCookie from 'fastify-cookie'; import fastifySession from '@mgcrea/fastify-session'; import Redis from 'ioredis'; import { RedisStore } from 'fastify-redis-session'; const app = fastify(); app.register(fastifyCookie); app.register(fastifySession, { store: new RedisStore({ client: new Redis('redis://localhost:6379'), ttl: 86400 }), secret: 'a secret with minimum length of 32 characters', cookie: { maxAge: 86400 }, }); app.get('/', (request, reply) => { request.session.views = (request.session.views || 0) + 1; reply.send({ views: request.session.views }); }); app.listen(3000);
Debug
Known issues
breakingVersion 2.0.0 changed the export from default to named export.
fix
Use `import { RedisStore } from 'fastify-redis-session'` instead of `import RedisStore from 'fastify-redis-session'`.
affects: >=2.0.0
deprecatedfastify-cookie is deprecated; use @fastify/cookie instead.
fix
Replace `fastify-cookie` with `@fastify/cookie` in both package.json and import statements.
affects: >=2.0.0
gotchaThe `secret` option in fastify-session must be at least 32 characters long, else session will fail silently.
fix
Provide a secret string of at least 32 characters.
affects: all
gotchaRedisStore expects a `client` option; if you pass an existing Redis client without proper connection, session storage will fail.
fix
Ensure the Redis client is connected before registering the session plugin.
affects: all
Errors
Common errors & fixes
RedisStore is not a constructor
Trying to use `new RedisStore()` after incorrectly importing the module as default export.
fix
Use `import { RedisStore } from 'fastify-redis-session'` instead of default import.
Cannot find module '@mgcrea/fastify-session' or its corresponding type declarations.
Missing peer dependency `@mgcrea/fastify-session`.
fix
Run `npm install @mgcrea/fastify-session`.
TypeError: Cannot read property 'session' of undefined
Missing registration of fastify-cookie before fastify-session.
fix
Ensure `fastify.register(fastifyCookie)` is called before registering fastify-session.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
ioredisrequiredPeer dependency; required to create Redis client passed to RedisStore.
Agent activity
32 hits · last 30 days
node
30
Amazon
1
Resources
fastify-redis-session — npm install fastify-redis-session · libregistry