Skip to content

Latest commit

 

History

History
67 lines (52 loc) · 1.17 KB

readme.md

File metadata and controls

67 lines (52 loc) · 1.17 KB

Mimiqueue

Free, open source NodeJS group queueing library with redis. Currently being used in https://nerimity.com (My chat app)

Features

  • Cluster Support
  • Redis Required
  • Group Queuing
  • Throttle Support (minTime)

Installation

pnpm i redis @nerimity/mimiqueue

Usage

import { createQueue, createQueueProcessor } from "@nerimity/mimiqueue";
import { createClient } from "redis";
import { setTimeout } from "timers/promises";

const redisClient = createClient({
  socket: {
    host: "127.0.0.1",
    port: 6379,
  },
});

const main = async () => {
  await redisClient.connect();

  // NOTE:
  // When running in a cluster, this needs to be ran ONCE in the main thread.
  await createQueueProcessor({
    redisClient,
  });

  const queue = createQueue({
    name: "test-queue",
    redisClient,
    minTime: 1000,
  });

  queue.add(
    async () => {
      await setTimeout(5000);
      return "done";
    },
    { groupName: "someId eg ip address" }
  );

  const status = await queue.add(
    async () => {
      await setTimeout(5000);
      return "done";
    },
    { groupName: "someId eg ip address" }
  );

  console.log(status);
};

main();