Skip to content

Simplest possible implementation to put, pop and bury jobs with Redis as backend.

Notifications You must be signed in to change notification settings

slowmove/redis-task-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis Task Queue

Simplest possible implementation to put, pop and bury jobs with Redis as backend.

https://nodei.co/npm/redis-task-queue.png?downloads=true&downloadRank=true&stars=true

Install

npm install redis-task-queue

Requires a Redis instance to connect to.

Usage

You may set your redis connection configuration either by environment variables or in the construction options. Default it connects to a local default instance of redis (127.0.0.1:6379)

Possible environment variables

REDIS_HOST = <default localhost>
REDIS_PORT = <default 6379>
REDIS_PASSWORD = <default empty>
const redisTaskQueue = new RedisTaskQueue({
  port: 6379,
  host: "127.0.0.1",
  password: ""
});

Client

const RedisTaskQueue = require("redis-task-queue");

const payload = {
  lorem: "sit",
  ipsum: "amet",
  dolor: "..."
};

const redisTaskQueue = new RedisTaskQueue();
const jobId = await redisTaskQueue.add({ data: payload });

Worker

const RedisTaskQueue = require("redis-task-queue");

const redisTaskQueue = new RedisTaskQueue();
let currentJob = null;
while (true) {
  currentJob = await redisTaskQueue.get();
  if (!currentJob) continue;
  console.log("Fetched job", currentJob);
  // do some job
  currentJob = null;
}

Methods

These are generic methods, by default using the default queue set up

  • add({ queue?, data }) returns id
  • get(queue?) returns the payload
  • has(queue?) returns the amount of items in the defined queue
  • list(queue?) returns all the items and their payload in the defined queue

These are aliases for the standard failed queue

  • bury({ queue?, data })
  • getBuried(queue?)
  • hasBuried(queue?)
  • listBuried(queue?)

Generic methods

  • getStatus(jobId) returns the status, whether active, buried or completed.
  • disconnect() release your Redis connection

About

Simplest possible implementation to put, pop and bury jobs with Redis as backend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published