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

@psyqueue/backend-redis

v0.1.0

Published

> Redis backend for PsyQueue. High-throughput production storage using ioredis.

Readme

@psyqueue/backend-redis

Redis backend for PsyQueue. High-throughput production storage using ioredis.

Installation

npm install psyqueue @psyqueue/backend-redis

Usage

import { PsyQueue } from 'psyqueue'
import { redis } from '@psyqueue/backend-redis'

const q = new PsyQueue()
q.use(redis({ host: 'localhost', port: 6379 }))

q.handle('email.send', async (ctx) => {
  const { to, subject } = ctx.job.payload as any
  await sendEmail(to, subject)
  return { sent: true }
})

await q.start()

// Start a worker pool with concurrency:10
q.startWorker('email.send', { concurrency: 10 })

await q.enqueue('email.send', { to: '[email protected]', subject: 'Hello' })

Configuration

| Option | Type | Default | Description | |--------|------|---------|-------------| | host | string | 'localhost' | Redis host | | port | number | 6379 | Redis port | | password | string | - | Redis password | | db | number | 0 | Redis database number | | url | string | - | Full Redis connection URL | | keyPrefix | string | 'psyqueue:' | Prefix for all Redis keys |

Architecture

The Redis backend uses a hybrid data model designed for throughput:

Hybrid List + Sorted Set

  • Default-priority jobs (priority = 0) use a Redis LIST (RPUSH to enqueue, RPOP to dequeue) -- O(1) on both sides.
  • Priority jobs (priority > 0) use a sorted set for ordering, then get promoted to the front of the ready list (LPUSH) so they are dequeued before normal jobs.

This means the common case (no priority) avoids sorted-set overhead entirely.

Blocking Dequeue (BRPOPLPUSH)

When used with startWorker(), a dedicated blocking connection waits on BRPOPLPUSH until a job arrives. This eliminates polling overhead and provides near-instant job pickup. The adapter sets supportsBlocking: true to signal this capability to the worker pool.

Hash Field Packing

Each job is stored as a Redis hash with 13 fields (down from ~30):

  • Hot fields (individual hash fields): id, queue, name, payload, status, priority, attempt, max_retries, completion_token, created_at, started_at, completed_at
  • Cold fields (packed into _ext JSON blob): backoff settings, workflow IDs, tenant IDs, trace IDs, schema version, metadata, deadlines, cron expressions, results, errors

This reduces memory per job and the number of fields Lua scripts need to read/write.

Lua Scripts

All critical operations are implemented as atomic Lua scripts:

  • DEQUEUE_SCRIPT -- RPOP N job IDs from the ready list and activate them atomically.
  • ACK_AND_FETCH_SCRIPT -- Ack the current job AND dequeue the next in a single call (reduces per-job round-trips from 3 to 2).
  • NACK_SCRIPT -- Handles requeue (immediate or delayed), dead-letter, and fail in one call.
  • ENQUEUE_PRIORITY_SCRIPT -- ZADD to the priority sorted set + promote to the ready list.
  • POLL_SCHEDULED_SCRIPT -- Move due jobs from the scheduled sorted set to the ready list.

Active Set

Active job tracking uses a plain Redis set (SADD/SREM) instead of a sorted set, since active jobs don't need ordering.

Performance

| Metric | PsyQueue Redis | BullMQ Redis | |--------|---------------|-------------| | Processing throughput | 7,989 jobs/sec | 6,187 jobs/sec |

Benchmark: 5,000 jobs, concurrency:10, no-op handler, measured after ack. PsyQueue is 1.29x faster than BullMQ.

When to Use

  • Production multi-worker deployments
  • High-throughput job processing (7,989+ jobs/sec)
  • Real-time applications needing sub-millisecond latency
  • When you already have Redis in your infrastructure

Exports

  • redis(opts?) -- Plugin factory function
  • RedisBackendAdapter -- The adapter class
  • serializeJobToHash(job) -- Serialize a Job to a Redis hash (hot/cold field packing)
  • deserializeJobFromHash(hash) -- Deserialize a Redis hash back to a Job

Documentation

See Backend Plugins for detailed configuration and migration guides.

License

MIT