Skip to content
This repository has been archived by the owner on Aug 8, 2020. It is now read-only.

Sends PING commands to Redis using redis to check if the connection is alive by receiving a PONG within a certain timespan

License

Notifications You must be signed in to change notification settings

michaelwittig/node-redis-pingpong

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status NPM version

cinovo-redis-pingpong

cinovo-redis-pingpong sends PING commands to Redis using redis to check if the connection is alive by receiving a PONG within a certain time span.

Getting started

At first you must install and require the module.

npm install cinovo-redis-pingpong

Next you must require the module

var pingpong = require("cinovo-redis-pingpong");

Then you can watch a redis client

var client = require("redis").createClient(6379, "localhost");
...
pingpong.watch(client, {"interval": 5000, "maxTimespan": 2000, "maxMissesBeforeError": 5});
pingpong.on("error", function(err) {
	console.log("redis is not available");
});
...
pingpong.stop();

Done

Now your redis client is watched.

API

watch(client, cfg)

Watch a redis client.

  • client: Instance of redid.createClient()...
  • cfg: Object (optional)
    • interval: Number - Milli seconds between two PINGs (optional, default: 5000)
    • maxTimespan: Number - Milli seconds we wait for a PONG after the PING (optional, default: 2000)
    • maxMissesBeforeError: Number - If we counted $maxMissesBeforeError misses an error is emitted (optional, default: 5)

stop()

Stop the watcher.

Events

ping()

Is fired when the PING command is send.

pong(timespan)

Is fired when the PONG response arrived.

  • timespan: Number - Time between PING and PONG in milli seconds

miss(misses, error)

Is fired if redis was missed.

  • misses: Number . Number of misses so far
  • error: Error that caused the miss

error(err)

Is fired when redis is no longer available.

  • error: Error

stop()

If the watches was stopped.

About

Sends PING commands to Redis using redis to check if the connection is alive by receiving a PONG within a certain timespan

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published