A Redis-based key expiration and event scheduling library for Node.js (v1.1.8). It allows scheduling key expiration via timeout, absolute date, cron pattern, or immediate expiry, and provides event handlers that fire when keys expire, including regex pattern matching. Unlike simple Redis TTL, redis-expiry persists scheduled expirations across application restarts by storing metadata in Redis. Supports CRUD operations and rescheduling. Suitable for timed tasks, cron jobs, and cache invalidation with guaranteed execution after restart. Release cadence is sporadic; last update was 2020.
npm install redis-expiryNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Initializes redis-expiry with two Redis clients, schedules a key to expire in 10 seconds, attaches an expiration handler, then removes the scheduler.
Pass a second Redis client instance instead: redisExpiry(setterClient, getterClient).
Always await the result of rexp.set(...).timeout(...) or chain .then() to ensure scheduling completes.
Implement your own reconnection logic on the Redis clients, or use a single client and pass it twice (though this may risk blocking).
In your handler callback, accept the third argument 'stop' and call stop() when you want to halt the cron repetition.
Set the 'maxConcurrent' option in rexp.on(pattern, callback, { maxConcurrent: 1 }) to serialize callbacks for the same pattern.Use require('redis-expiry') instead, or use dynamic import if you must use ESM: const redisExpiry = (await import('redis-expiry')).default;Create a second Redis client and pass it: redisExpiry(setterClient, getterClient).
Ensure both Redis clients are connected before initializing redis-expiry. Use Redis client's 'ready' event or connect() method.
Verify the cron expression format (e.g., '*/4 * * * * *' for every 4 seconds). Refer to https://www.npmjs.com/package/cron-parser for valid syntax.