Skip to content

nirf/print-scheduled-messages-using-redis-example

Repository files navigation

Description

A simple application server that prints a message at a given time in the future

Implementation notes:

  1. Setting notifications on the redis server: CONFIG SET notify-keyspace-events Ex
  2. Subscribing to expire events: PSUBSCRIBE 'keyevent@0:expired'
  3. For each echo message a unique uuid 'x' is generated as the key while the message is the value.
  4. Each uuid is backed by 'opaque:x' which is a reference to the same message without expiration.
  5. When an expire event is triggered, it receives as payload the key expired, to get the message an opaque key is generated to get the message, which is deleted after.
  6. In case the server was down when a message should have been printed, While the server is up again it checks to see if there exists and opaque:* message and echo them and delete them.
  7. The exp time is calculated by substracting the (future time - current time) in seconds

Installation

$ npm install

Running the app

# development
$ npm run start:development

# docker-compose
$ docker-compose build
$ docker-compose up

Echo a message

Open your browser and navigate to http://localhost:3000/redis-master/api/swagger

Input example

{
"time": 1572197700000,
"message": "Hello"
}

time in milliseconds

time to time in milliseconds converter: https://currentmillis.com

About

Extending Redis functionality

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published