npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@reaatech/session-continuity-storage-redis

v0.1.0

Published

Redis storage adapter for session-continuity-kit

Readme

@reaatech/session-continuity-storage-redis

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Redis storage adapter implementing IStorageAdapter from @reaatech/session-continuity. Uses hashes for session/metadata, sorted sets for message ordering, and native EXPIRE for TTL — ideal for low-latency, high-throughput deployments.

Installation

npm install @reaatech/session-continuity-storage-redis redis
# or
pnpm add @reaatech/session-continuity-storage-redis redis

Feature Overview

  • Implements IStorageAdapter — drop-in replacement for any storage backend
  • Sorted set message ordering — messages scored by a monotonic per-session sequence (atomic INCR), so insertion order is stable even within the same millisecond; supports offset, limit, and direction (asc/desc)
  • Optimistic concurrencyupdateSession honors expectedVersion via a WATCH/MULTI/EXEC transaction, throwing ConcurrencyError on a stale write
  • Native Redis TTLEXPIRE applied to session hashes and message keys
  • User index — fast user-based lookups via a Redis Set (user:{userId}:sessions)
  • Content type preservation — round-trips both plain text and structured MessageContent correctly

Quick Start

import { RedisAdapter } from '@reaatech/session-continuity-storage-redis';
import { SessionManager } from '@reaatech/session-continuity';
import { createClient } from 'redis';

const redis = createClient({ url: 'redis://localhost:6379' });
await redis.connect();

const manager = new SessionManager({
  storage: new RedisAdapter({ client: redis, ttlSeconds: 3600 }),
  tokenCounter: myTokenCounter,
});

API Reference

RedisAdapter

Constructor

new RedisAdapter(config: RedisAdapterConfig)

RedisAdapterConfig

| Property | Type | Default | Description | | ------------ | ----------------- | ---------- | ------------------------------------------------ | | client | RedisClientType | (required) | node-redis v4+ client instance | | ttlSeconds | number | — | Default TTL in seconds for sessions and messages |

Key Design

| Key Pattern | Type | Description | | ------------------------ | ---------- | ------------------------------------------- | | session:{id} | Hash | Session fields | | session:{id}:messages | Sorted Set | Message IDs scored by createdAt.getTime() | | message:{id} | Hash | Message fields | | user:{userId}:sessions | Set | Session IDs for a user (index) |

Public Methods

| Method | Notes | | ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | createSession(session) | Stores as hash; optional EXPIRE; adds to user index if userId present | | getSession(id) | HGETALL — returns null if hash is empty | | updateSession(id, updates) | Replaces hash (DEL + HSET) to clear removed fields; resets TTL; updates user index if userId changed | | deleteSession(id) | Removes from user index, deletes all messages, deletes session hash | | listSessions(filters?) | Uses user index for fast userId-only lookups; otherwise SCANs session:*. Tags filtered client-side (OR semantics) | | addMessage(sessionId, message) | Adds to sorted set + creates message hash; applies TTL if configured | | getMessages(sessionId, options?) | Note: after and before not supported. Uses ZRANGE/ZREVRANGE for offset/limit/order. Role filtering is client-side and applied after pagination. | | updateMessage(sessionId, messageId, updates) | TSets message hash; throws StorageError if not found | | deleteMessage(sessionId, messageId) | Removes from sorted set + deletes message hash | | deleteAllMessages(sessionId) | Pipelines DEL commands for all message IDs + sorted set | | getExpiredSessions(before) | Scans session:* keys and checks expiresAt in each hash | | health() | PING | | close() | client.quit() |

All methods throw StorageError("redis") on failure.

Content Type Handling

The adapter preserves the content type of messages to correctly round-trip both plain text strings and structured multi-modal content arrays. An internal contentType field ("string" or "json") is stored alongside the content.

Usage Patterns

With Connection Management

import { createClient } from 'redis';
import { RedisAdapter } from '@reaatech/session-continuity-storage-redis';

const redis = createClient({ url: 'redis://localhost:6379' });

redis.on('error', (err) => console.error('Redis client error', err));
await redis.connect();

const adapter = new RedisAdapter({ client: redis, ttlSeconds: 7200 });

// Graceful shutdown
process.on('SIGTERM', async () => {
  await adapter.close();
  process.exit(0);
});

With SessionManager and Cleanup

import { SessionManager } from '@reaatech/session-continuity';
import { RedisAdapter } from '@reaatech/session-continuity-storage-redis';
import { TiktokenTokenizer } from '@reaatech/session-continuity-tokenizers';

const manager = new SessionManager({
  storage: new RedisAdapter({ client: redis, ttlSeconds: 3600 }),
  tokenCounter: new TiktokenTokenizer('gpt-4'),
  sessionTTL: 3600,
  cleanupInterval: 300,
});

// Redis TTL handles expiration natively;
// cleanupInterval provides application-level backup

Related Packages

License

MIT