Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Quick README

  • Loading branch information...
commit cf00cbdd15574df70c3875aea15e51a9cb0d1661 1 parent d6699c2
Tim tim-smart authored

Showing 1 changed file with 54 additions and 0 deletions. Show diff stats Hide diff stats

  1. +54 0 README
54 README
... ... @@ -0,0 +1,54 @@
  1 +Description
  2 +-----------
  3 +
  4 +Node-redis-queue is a simple Redis based message queue for communicating between multiple platforms.
  5 +It uses a easy to implement message paradigm within Redis lists.
  6 +
  7 +An example message:
  8 +
  9 + {
  10 + id: 1,
  11 + payload: 'Some data',
  12 + errors: ['HTTP 404'],
  13 + error_count: 1
  14 + }
  15 +
  16 +Messages are put onto the list with `rpush`, then the client listens for messages with the `blpop` command.
  17 +
  18 +Usage
  19 +-----
  20 +
  21 +queue-server.js:
  22 +
  23 +// Require the node-redis-queue
  24 +var client = require('./node-redis-queue');
  25 +
  26 +// Create the Queue with a redis server listening on localhost:6379
  27 +var user_queue = new client.Queue('user', 'localhost', 6379);
  28 +
  29 +// Add a job to the queue.
  30 +user_queue.push('Any JSON.strinify-able data goes in this parameter', function (error, id) {
  31 + // Handle errors
  32 + if (error) throw error;
  33 + // Second parameter is the message/job id.
  34 +});
  35 +
  36 +queue-worker.js:
  37 +
  38 +// Require the node-redis-queue
  39 +var client = require('./node-redis-queue');
  40 +
  41 +// Create a worker.
  42 +var worker = client.createWorker('localhost', 6379);
  43 +
  44 +// Setup events for each queue you want to listen to.
  45 +worker.on('user', function (job) {
  46 + // Process message
  47 + process(job.payload);
  48 +});
  49 +
  50 +// Listen for all messages on worker.
  51 +worker.on('*', fn);
  52 +
  53 +// Start listening.
  54 +worker.listen('user');

0 comments on commit cf00cbd

Please sign in to comment.
Something went wrong with that request. Please try again.