deja-qu
v0.8.0
Published
Emphemeral message queue for Node
Downloads
7
Readme
Déjà qu
Déjà qu is Redis-backed FIFO message queue for storing any kind of ephemeral data. It allows you to easily build ephemeral timelines/stories. Messages are automatically removed from the queue once they're expired, without the need for polling, cron jobs, or timers.
Installation
If using yarn:
yarn add deja-qu
or npm:
npm install deja-qu --save
Run Redis server:
redis-server
Check out Redis quickstart to install.
Usage
Step 1: Initialize and start Déjà qu
Require Déjà qu:
const DejaQu = require('deja-qu').DejaQu;
Initialize Déjà qu, connecting to a local Redis server running on the default port:
const dq = new DejaQu();
Optionally pass in a Redis configuration to connect to a remote server.
const dq = new DejaQu(REDIS_CLOUD_URL);
Start Déjà qu, ideally right after the server starts.
dq.start();
Step 2: Profit
Get a queue
const q = dq.getQueue('timeline', user1);
Create and add a message that expires in 24 hours
const Message = require('deja-qu').Message;
const msg = new Message('Have I seen this before?', 86400);
q.push(msg);
Get the first 5 messages
const messages = await q.get(0, 4);
Delete the oldest message
const message = await q.pop();
Delete specific message
await q.delete(messages[3]);
Debugging
Add DEBUG=deja-qu
to the node start script in package.json
to see debug output. i.e:
DEBUG=deja-qu node server.js
Tests
yarn install # or npm install
npm test
Author
Shane Vitarana :: http://shanev.me :: @shanev