Redis as Queue - Node.js SDK
Note: This is A node.js package for regarding redis as a message queue, npm repo: https://www.npmjs.com/package/redis-message-queue
Installation
$ npm install redis-message-queue
Usage
There are two kinds of queue - normal queue and unique queue.
Each value in unique queue is unique. If a new value that equals any value in the queue, you may choose to update or not.
First you should require this package:
var rmq = ;
Normal Queue
Create
var normalQueue = QUEUE_NAME ...;
Note:
[...]
is the option(s) to connect redis server. Refer to node-redis document.Eg.
QUEUE_NAME 6379 '127.0.0.1' {};QUEUE_NAME unix_socket options;...
Select
To Select a db :
normalQueue;
Push
To push a message to your queue, you may use this function:
normalQueue;
Get
To get message(s) from your redis queue, you may use get
function.
Get earlist one message
normalQueue;
Get earlist N message(s)
// This call gets 10 earlist messagesnormalQueue;
Get all message(s)
normalQueue;
Remove
To remove message(s) from your redis queue, you may use removeAmount
function.
Remove earlist one message
normalQueue;
Remove earlist N message(s)
normalQueue;
Remove all the message(s)
normalQueue;
Length
Get the length of current queue.
normalQueuelength { console;};
Unique Queue
Each message in unique queue is unique.
Create
var uniqueQueue = QUEUE_NAME ...;
Note:
[...]
is the option(s) to connect redis server. Refer to node-redis document.Eg.
QUEUE_NAME 6379 '127.0.0.1' {};QUEUE_NAME unix_socket options;...
Select
To Select a db :
normalQueue;
Push
Push a message to the queue.
Need update
This call will check if your message is existing. If existing, it will move the previous message to the end of queue. Otherwise, your message will be pushed at the end of queue.
uniqueQueue;
Do not update
This call will check if your message is existing. If existing, it won't do anything. Otherwise, your message will be pushed at the end of queue.
uniqueQueue; // or you can do this uniqueQueue;
Get
Get first message
uniqueQueue;
Get first N message(s)
uniqueQueue;
Get all the message(s)
uniqueQueue;
Remove Amount
Refer to remove section in Normal Queue.
Remove Messages
Remove one or more certain message(s) in the queue.
uniqueQueue;
Length
Refer to length section in Normal Queue.
Common Functions
Delete Queue
Delete this queue key and values in redis.
uniqueQueue;normalQueue;
Destroy Queue Object
Let the queue object disconnect from redis server and let this instance can't do any other thing any more.
uniqueQueue;normalQueue;
Contribute
You're welcome to pull requests!