Registry / database / redis-sessions

redis-sessions

JSON →
library4.0.0jsnpmunverified

Advanced session store for Redis supporting multiple apps, token-based sessions, activity tracking, and optional in-memory caching. Current stable version 4.0.0 (2025) uses async/await (breaking from v3 callbacks). Provides create, get, set, kill, killall, activity, soid, killsoid, soapp methods. Ships TypeScript types. Designed for cross-platform session sharing via REST (rest-sessions) or Express (connect-redis-sessions), both currently incompatible with v4.0.0. Performance: 1000 creates in ~140ms, 1000 gets in ~90ms on 2018 MacBook Pro. Engine requirement: Node >=16.

npm install redis-sessions
INSTALL
IMPORT
SIG · REDIS-SESSIONS
R
redis-sessions
databasejavascriptv4.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.

default
import RedisSessions from 'redis-sessions'
const RedisSessions = require('redis-sessions')
ESM-only since v4.0.0 due to async/await migration. CommonJS require() will fail.
RedisSessions
import RedisSessions from 'redis-sessions'
import { RedisSessions } from 'redis-sessions'
The package exports a single class as default export. Named import { RedisSessions } is incorrect.
RedisSessionsOptions
import RedisSessions from 'redis-sessions'
TypeScript types include RedisSessionsOptions interface; no separate named type export needed as options are passed to constructor.

Initializes redis-sessions client, creates a session, gets it, sets custom data, kills it, and checks activity count.

import RedisSessions from 'redis-sessions'; const rs = new RedisSessions({ host: '127.0.0.1', port: 6379, }); // Create a session for user 'user123' in app 'myapp' const { token } = await rs.create({ app: 'myapp', id: 'user123' }); // Get the session using the token const session = await rs.get({ app: 'myapp', token }); console.log('Session data:', session); // Set additional data await rs.set({ app: 'myapp', token, d: { role: 'admin', lastLogin: Date.now() } }); // Kill the session await rs.kill({ app: 'myapp', token }); // Get activity count (active sessions in last 60 seconds) const activeCount = await rs.activity({ app: 'myapp', time: 60 }); console.log('Active sessions:', activeCount);
Debug
Known issues
breakingv4.0.0 switched from callbacks to async/await. Code using callbacks will break.
fix
Replace callbacks with async/await or use .then().
affects: >=4.0.0
breakingconnect-redis-sessions and rest-sessions are incompatible with v4.0.0.
fix
Stay on v3.x for Express integration, or wait for updated packages.
affects: >=4.0.0
breakingMethod signatures changed in v4.0.0 (e.g., create() returns {token}, not callback).
fix
Update calls to match new async signatures. See migration guide.
affects: >=4.0.0
deprecatedNode.js versions below 16 are no longer supported since v4.0.0.
fix
Upgrade Node to 16+.
affects: >=4.0.0
gotchaWhen using caching, the cache is flushed only on set() and kill*() methods, not on get() or create(). Cached sessions return stale idle and r keys.
fix
Use cachetime appropriately; avoid relying on idle/r for precise tracking if caching enabled.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: RedisSessions is not a constructor
Using CommonJS require() on v4 ESM-only package.
fix
Use import statement: import RedisSessions from 'redis-sessions'
Error: The 'id' field is required
Calling create() without providing an 'id' in options.
fix
Provide an id field: rs.create({ app: 'myapp', id: 'user123' })
Error: The 'token' field is required
Calling get() without providing a token.
fix
Provide the token returned from create(): rs.get({ app: 'myapp', token })
Error: Redis connection refused - connect ECONNREFUSED 127.0.0.1:6379
Redis server is not running or host/port misconfigured.
fix
Start Redis server or configure host/port correctly: new RedisSessions({ host: '192.168.0.20', port: 6379 })
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
redisrequiredRequired for connecting to Redis, used as the underlying store
Agent activity
21 hits · last 30 days
node
18
Meta
1
OpenAI (training)
1
Resources
redis-sessions — npm install redis-sessions · libregistry