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

redis-toolbox

v1.0.1

Published

Redis utilities that allows developers to utilize Redis for Session Management, Job Queue processing and so on.

Readme

redis-toolbox

Redis toolbox banner

Redis utilities that allows developers to utilize Redis for Session Management, Job Queue processing and so on.

Installation

npm i redis-toolbox --save

Session Tools

The session tools provided here allows you to turn your redis host into a session manager for anything. It is designed to be agnostic to any specific product type and are all promise based which can be used for Async/Await calls

Sample Setup

import {
  RedisSessionManager, RedisSessionOptions, onRedisSessionErrorCallback, RedisSessionObject,
} from 'redis-toolbox';

const redisOptions: RedisSessionOptions = {
  host: process.env.REDIS_HOST,
  port: parseInt(process.env.REDIS_PORT || '80', 10),
  db: process.env.REDIS_DB ? parseInt(process.env.REDIS_DB, 10) : undefined,
  password: process.env.REDIS_PASS,
  sessionMaxTTL: process.env.USER_SESSION_MAX_TTL ? parseInt(process.env.USER_SESSION_MAX_TTL, 10) : 21600,
  sessionRefreshTTL: true,
  sessionInactiveTTL: process.env.USER_SESSION_IDLE_TTL ? parseInt(process.env.USER_SESSION_IDLE_TTL, 10) : 1800,
};

const onSessionError: onRedisSessionErrorCallback = async (err: Error): Promise<boolean> => {
  // do whatever async tasks like send metrics, alerts, etc.
  console.log(`Error on session: ${err.message}`);
  return false;
};

const session = new RedisSessionManager(redisOptions, onSessionError);

Session related imports from the toolbox

On the sample above, we first imported the major components of a redis session.

  • RedisSessionManager - The class that encapsulates the session management
  • RedisSessionOptions - An object that extends the RedisOptions (ioredis)
  • onRedisSessionErrorCallback - Defines a function that will be called whenever an error occurs in the session
  • RedisSessionObject - Defines the data that gets stored for the session

RedisSessionOptions

Next we had defined the redis options. The rest of the configurations are from ioredis (host, port, etc.) what is added are the 3 session behavior properties

  • sessionMaxTTL (integer)(default 6 hours) - The maximum time (in seconds) a redis session instance lives (TTL). once the session reaches this, its gone for good
  • sessionRefreshTTL (boolean)(default false) - Defines if the session expires by being idle. This allows you to create long sessionMaxTTL but enforce an auto session kill when the user shows no activity for lets say 5-15 minutes
  • sessionInactiveTTL (integer)(default 30 minutes) - if sessionRefreshTTL is true, this is applied as the max idle time a user can have before the session times out.

onRedisSessionErrorCallback

After that we need to implement the error callback defined by onRedisSessionErrorCallback . This allows you the chance to perform anything necessary before the module throws an Error. You can send alerts, metrics etc. on this function. this expects a return value however of boolean. Returning true acknowledges that you have handled the error yourself and telling the module to "do not bother throwing the error". sending false makes the module proceed to throw the error.

RedisSessionManager instance

Finally, we create a new session instance from RedisSessionManager. It requires only 2 parameters which we did in the 2nd and 3rd step. The RedisSessionOptions object and the Error callback.


We can now start utilizing the session functions

const newsession: RedisSessionObject = await session.createSession();
const samesession: RedisSessionObject = await session.retrieveSession(newsession.sessionId);
const delta = { name: 'Adonis Lee Villamor', email: '[email protected]' }
const isUpdated = await session.updateSession(samesession.sessionId, delta as any); //isUpdated will be true if success
const isDestroyed = await session.destroySession(samesession.sessionID);