Skip to content
/ deja-qu Public

Déjà qu is a FIFO message queue for storing ephemeral data

License

Notifications You must be signed in to change notification settings

shanev/deja-qu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Déjà qu

npm version Build Status codecov codebeat badge Dependencies

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.

NOTE

This library was mostly a science experiment and hasn't been battle-tested. For production use I'd look at Bull or Kue instead.

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

About

Déjà qu is a FIFO message queue for storing ephemeral data

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published