Registry / messaging / redis-scheduler

redis-scheduler

JSON →
library1.0.0jsnpmunverified

A Node.js library (v1.0.0) that uses Redis keyspace notifications to trigger timed events. Inspired by Codezuki's blog post, it allows scheduling, rescheduling, and cancelling events with multiple handlers per key. Requires Redis 2.8+ with keyspace notifications enabled (notify-keyspace-events Ex). Unlike typical job queues, it leverages Redis' native expiry mechanism. Stable but not actively maintained; last release was several years ago. Suitable for simple timer-based tasks but not for high-throughput or persistent job queues.

npm install redis-scheduler
INSTALL
IMPORT
SIG · REDIS-SCHEDULER
R
redis-scheduler
messagingjavascriptv1.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.

Scheduler
✓ const Scheduler = require('redis-scheduler');
✗ import Scheduler from 'redis-scheduler';
This package uses CommonJS. ESM import is not supported.
Scheduler
✓ const scheduler = new Scheduler({ host: 'localhost', port: 6379 });
Options object is required. If null, defaults to { host: 'localhost', port: 6379, db: 0 }.
schedule
✓ scheduler.schedule({ key: 'test', expire: 1000, handler: fn }, cb);
✗ scheduler.schedule({ key: 'test', expire: new Date(), handler: fn }, cb);
expire can be a number (milliseconds from now) or a Date object. Handler is called with (err, key).

Initializes a redis-scheduler instance, schedules an event with a 2-second delay, and closes the scheduler after 5 seconds.

const Scheduler = require('redis-scheduler'); // Create a scheduler instance const scheduler = new Scheduler({ host: 'localhost', port: 6379 }); // Define a handler function function myHandler(err, key) { console.log(`Event triggered for key: ${key}`); } // Schedule an event in 2 seconds scheduler.schedule({ key: 'my-event', expire: 2000, handler: myHandler }, function(err) { if (err) { console.error('Error scheduling:', err); } else { console.log('Event scheduled'); } }); // Close the scheduler after some time setTimeout(() => { scheduler.end(); console.log('Scheduler closed'); }, 5000);
Debug
Known issues
gotchaKeyspace notifications must be enabled in Redis configuration: 'notify-keyspace-events Ex'.
fix
Set notify-keyspace-events Ex in redis.conf or via CONFIG SET notify-keyspace-events Ex.
affects: >=0.0.0
gotchaRedis 2.8.0 or higher is required. Older versions do not support keyspace notifications.
fix
Upgrade Redis to version 2.8.0 or later.
affects: >=0.0.0
deprecatedThe package uses the 'redis' npm package which may have breaking changes in newer versions.
fix
Pin the 'redis' dependency version to avoid incompatibilities.
affects: >=1.0.0
gotchaHandler removal on cancel may not clean up all references if multiple patterns match the same key.
fix
Use distinct keys for different events to prevent accidental cross-cleanup.
affects: >=0.0.0
Errors
Common errors & fixes
Error: ERR DISABLED keyspace notifications are not enabled
Redis keyspace notifications are not turned on.
fix
Run 'redis-cli config set notify-keyspace-events Ex' or set it in redis.conf.
TypeError: scheduler.schedule is not a function
Using incorrect import (e.g., ESM import) or packaging issue.
fix
Use require('redis-scheduler') as CommonJS; ensure the package is installed correctly.
Error: ReplyError: ERR value is not a valid expire time
expire parameter is not a number or Date object.
fix
Pass a valid number of milliseconds or a Date object to expire.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
redisrequiredRedis client used to interact with the Redis server
Agent activity
12 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
redis-scheduler — npm install redis-scheduler · libregistry