Registry / messaging / simple-redis-safe-work-queue

simple-redis-safe-work-queue

JSON →
library3.1.1jsnpmunverified

A Redis-backed work queue for Node.js producers and consumers, providing safe and simple job processing. Version 3.1.1 is the latest stable release. It supports Lua scripting for atomic operations and includes features like configurable timeouts, retries, concurrency control, and watchdog timers for stalled jobs. Compared to alternatives like Bull or Kue, this library offers a minimal API with separate client and worker constructors, events for lifecycle hooks, and simple job push/fetch mechanics. It requires Redis 2.6+ and has no external dependencies beyond the redis client.

npm install simple-redis-safe-work-queue
INSTALL
IMPORT
SIG · SIMPLE-REDIS-SAFE-
S
simple-redis-safe-work-queue
messagingjavascriptv3.1.1
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.

Queue
✓ import Queue from 'simple-redis-safe-work-queue'
✗ const { Queue } = require('simple-redis-safe-work-queue')
Default import is the module itself; named export pattern is incorrect. CommonJS require works too.
client
✓ const client = Queue.client('queue-name')
✗ const client = new Queue.client('queue-name')
Queue.client is a factory function, not a constructor. Do not use `new`.
worker
✓ const worker = Queue.worker('queue-name', handler, options)
✗ const worker = new Queue.worker()
Queue.worker is a factory function. Options object is optional and can include properties like maxConcurrency, maxRetries, etc.

Demonstrates creating a producer (client) and consumer (worker) for a simple Redis work queue.

import Queue from 'simple-redis-safe-work-queue'; // Producer const client = Queue.client('email-queue'); client.push({ to: 'user@example.com', subject: 'Hello', body: 'World' }, (err) => { if (err) console.error('Push error:', err); }); // Consumer const worker = Queue.worker('email-queue', (job, done) => { console.log('Processing job:', job); // Simulate async work setTimeout(() => { done(); }, 1000); }); worker.on('ready', () => console.log('Worker ready')); worker.on('error', (err) => console.error('Worker error:', err));
Debug
Known issues
breakingVersion 2.x to 3.x: Queue.client and Queue.worker are now factory functions instead of constructors. Do not use `new`.
fix
Use `const client = Queue.client('name')` and `const worker = Queue.worker('name', fn)` without `new`.
affects: >=3.0.0
deprecatedThe `.listen()` method is deprecated in favor of `.fetch()`. Using `.listen()` may cause long polling behavior.
fix
Use `.fetch()` instead of `.listen()`.
affects: >=3.0.0
gotchaIf `autoListen` is true (default), the worker starts listening immediately upon creation. This may cause unexpected behavior if you want to set up event handlers first.
fix
Set `autoListen: false` in worker options and call `.listen()` or `.fetch()` manually after setting up handlers.
affects: >=1.0.0
gotchaWhen using `.fetch()` with `autoListen: false`, the method returns null if no messages are available. Ensure your code handles null responses correctly.
fix
Check for null before processing: `worker.fetch((err, job) => { if (job) { /* process job */ } });`
affects: >=3.0.0
gotchaThe `push()` callback is called after the job is added to Redis. It does not indicate that the job has been processed.
fix
Use events like 'work done' on the worker to get processing completion notification.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Queue.client is not a constructor
Using `new` with Queue.client in version 3.x.
fix
Use `const client = Queue.client('name')` without `new`.
Error: Redis connection refused
Redis server is not running or invalid host/port.
fix
Start Redis server or check host/port options: `Queue.client('name', { host: 'localhost', port: 6379 })`
Error: ERR Error running script (call to f_...): @user_script:1: bad argument #1 to 'replicate_commands'
Redis version is lower than 2.6 or Lua scripting is disabled.
fix
Upgrade Redis to 2.6+ with scripting enabled.
Upgrade
Version history
3.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
simple-redis-safe-work-queue — npm install simple-redis-safe-work-queue · libregistry