Redis Priority Queue
This is a simple Promise based multi-channel priority queue implementation that leverages Redis sorted set.
Requirements
You will need Redis server running.
Installation
npm install redis-priority-queueyarn add redis-priority-queue
Test
The test script in package.json
preprocesses the .ts
file and then executes.
npm test
Usage
The source was written in Typescript, yet it compiles to Javascript (npm run build
). You can use in ES5 or later supported environments. The following code snippets are implemented in the __tests__
folder.
Quick start (Node)
const queue = ; const config = queue; const myQueue = config; myQueuelength"emptyQueue" ;
Optional with existing client
If you already have a program with a RedisClient
you can pass the client as an optional second parameter.
const myQueue = null client; myQueuelength"emptyQueue" ;
Typescript
Initialization
; ; ;
Insert element
Promise.all .then .catch;
Pull highest score element
myQueue.pullHighestPrioritytestKey .then .catch;
Peek highest score element
myQueue.peektestKey .then .catch;
Check if empty
myQueue.isEmptytestKey .then .catch;
Get queue length
myQueue.lengthtestKey .then .catch;
Contributing
I haven't thought that far ahead yet. I needed this for my project and wanted to give back. ;-)
License
MIT (if you enhance it, fork and PR so the community benefits)