Skip to main content
This release was yanked — the latest version of @leotermine/redismq is 0.3.4. Jump to latest

yanked

A simple, lightweight and efficient job queue system for Deno, Node.js, and Bun. Built on Redis, it offers high-performance task scheduling and processing.

This package works with Node.js, Deno, Bun
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
70%
Published
2 weeks ago (0.2.0)

Redis-MQ

A lightweight message queue system built on Redis, supporting cron jobs and one-off tasks.

Installation

npm install @leotermine/redismq

Quick Start

import { QueueManager } from "@leotermine/redismq";
import { Redis } from "ioredis";

// 1. Configure Redis
const redisConfig = {
  port: 6379,
  host: 'localhost', // or the host in use
  username: '',
  password: '',
  maxRetriesPerRequest: null,
  enableReadyCheck: false,
};

// 2. Initialize Redis client
const client = new Redis(redisConfig);

// 3. Initialize Queue Manager
const contextApp = {}; // Optional context passed to job handlers
const app = QueueManager.init(client, contextApp, 1); // Last param is concurrency

// 4. Define a job
const myJob = {
  path: 'category/job-name', // Must follow 'category/name' format
  run: (ctx, job) => {
    console.log('Job running!', job);
  },
  options: {
    repeat: {
      pattern: '* * * * *' // Cron pattern (optional)
    },
    attempts: 3 // Retry attempts (optional)
  }
};

// 5. Register job
app.registerJob(myJob);

// 6. Start processing
app.processJobs();

// 7. Add one-off job (optional)
app.addJob('category/job-name', {
  data: 'your-data'
}, {
  attempts: 3
});

Job Types

Cron Jobs

const cronJob = {
  path: 'crons/hello-world',
  run: (ctx, job) => {
    console.log("Running on schedule");
  },
  options: {
    repeat: {
      pattern: "* * * * *" // Runs every minute
    }
  }
};

One-off Jobs

const oneOffJob = {
  path: 'tasks/send-email',
  run: (ctx, job) => {
    console.log("Running once");
  }
};

API Reference

QueueManager

  • init(redisClient, context, concurrency): Initialize queue manager
  • registerJob(job): Register a new job type
  • addJob(path, data, options): Add a job instance
  • processJobs(): Start processing jobs
  • getAllJobs(): Get all jobs in queues

Job Options

interface JobOptions {
  repeat?: {
    pattern: string;    // Cron pattern
  };
  attempts?: number;    // Retry attempts
  _id?: string;        // Custom job ID
  priority?: number;    // Job priority
  delayUntil?: Date;   // Delay execution
}

License

MIT

Add Package

deno add jsr:@leotermine/redismq

Import symbol

import * as redismq from "@leotermine/redismq";

---- OR ----

Import directly with a jsr specifier

import * as redismq from "jsr:@leotermine/redismq";

Add Package

npx jsr add @leotermine/redismq

Import symbol

import * as redismq from "@leotermine/redismq";

Add Package

yarn dlx jsr add @leotermine/redismq

Import symbol

import * as redismq from "@leotermine/redismq";

Add Package

pnpm dlx jsr add @leotermine/redismq

Import symbol

import * as redismq from "@leotermine/redismq";

Add Package

bunx jsr add @leotermine/redismq

Import symbol

import * as redismq from "@leotermine/redismq";