npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gitterhq/redis-sentinel-client

v0.4.0

Published

Transparent Redis Sentinel client

Downloads

9

Readme

Redis Sentinel Client for Node.js

Supplements node_redis with Redis Sentinel support.

From the Sentinel docs:

Redis Sentinel is a system designed to help managing Redis instances. It performs the following three tasks: Monitoring. Sentinel constantly check if your master and slave instances are working as expected. Notification. Sentinel can notify the system administrator, or another computer program, via an API, that something is wrong with one of the monitored Redis instances. Automatic failover. If a master is not working as expected, Sentinel can start a failover process where a slave is promoted to master, the other additional slaves are reconfigured to use the new master, and the applications using the Redis server informed about the new address to use when connecting.

Goals

  1. Transparent, drop-in replacement for RedisClient, handling connections to master, slave(s), and sentinel in the background.
  2. Handles all RedisClient operations (including pub/sub).
  3. Minimize data loss

This was originally part of a fork of node_redis, and has been subsequently split to its own module. (However, it still currently requires changes to node_redis to work, so it still depends on the fork.)

See related thread about different approaches to Sentinel support: https://github.com/mranney/node_redis/issues/302

Concepts

  • connects to a single or multiple sentinels, which is watching a master/slave(s) cluster
  • maintains a query and subscribe connection to the active sentinel connection (which rotates on failure), and a single redis client connection to the master of the cluster in the background, which automatically updates on switch master
  • behaves exactly like a single RedisClient (all methods are passthrough)

Usage

npm install redis-sentinel-client

var RedisSentinel = require('redis-sentinel-client');
var sentinelClient = RedisSentinel.createClient(options);
// or
var sentinelClient = RedisSentinel.createClient(PORT, HOST [, options]);

Now use sentinelClient as a regular client: set, get, hmset, etc.

Instantiation options

  • Sentinel Connection Options (1 required):
    • host and port: Connect to a single sentinel
    • sentinels: Keep a list of all sentinels in the cluster so that if one disconnects, we rotate to another (Alternative to port and host): sentinels: [[host1,port1],[host2,port2]]
  • masterName: Which master the sentinel is listening to. Defaults to 'mymaster'. (If a sentinel is listening to multiple masters, create multiple SentinelClients.)
  • masterOptions: The options object which will be passed on to the Redis master client connection. See the node_redis documentation for more details.
  • master_auth_pass: If your master and slave(s) need authentication (options.auth_pass in node_redis, as of 0.8.5), this is passed on. (Note, the sentinel itself does not take authentication.)
  • master_debug: Make the master connections be debug connections

Methods

  • getMaster(): returns a reference to the sentinel client's activeMasterClient (also available directly). The use of this method is not recommended as clients are thrown away after disconnection and a new one is instantiated.
  • getSentinel(): returns a refrence to the sentinel client itself
  • reconnect(): used on instantiation and on psub events, this checks if the master has changed and connects to the new master.
  • send_command() (and any other RedisClient command): command is passed to the master client.
  • sentinel() A redis command sent to the sentinel instance. (for instance cli.sentinel('masters', 'mymaster', callback))

Events

In addition to passing through all RedisClient events from the master connection, the following are emitted from the sentinel wrapper.

  • .emit('sentinel connect', [host,port]): Emitted when sentinel connection is starting
  • .emit('sentinel connected', [host,port]): Emitted when sentinel connection is established
  • .emit('sentinel disconnected'): Emitted when sentinel connection is lost
  • .emit('sentinel message', msg): Emitted from the subscription to all sentinel messages. Note, messages can be about other masters, does not differentiate.
  • .emit('failover start'): Emitted when a failover is beginning.
  • .emit('failover end'): Emitted when a failover has ended.
  • .emit('switch master'): Emitted when the master is switching (failover or not)
  • .emit('error', err): Emitted when an error occured. You should listen on this so that node does not trigger an uncaught exception

Tests

There is now one large test, run with Mocha. It starts up redis (you should have the redis-server executable with sentinel support built in installed) and tests the connection under a number of failure conditions.

npm install
npm test

Note: This module uses debug, so to see debug output, simply use: DEBUG=redis-sentinel-client,redis-processes npm test

Limitations

  • Unlike RedisClient, SentinelClient is not / does not need to be a stream
  • Sentinel docs don't specify a default host+port, so option-less implementations of createClient() won't be compatible.
  • Have not put any time into multi support, unknown status.

Possible roadmap

  • Multiple master/slave(s) clusters per sentinel
    • But thinking not: Just create multiple sentinel clients, one per cluster.

Credits

Created by the Node.js team at DocuSign (in particular Ben Buckman and Derek Bredensteiner).

Major modifications made by Jon Eisen at Rafflecopter.

License

MIT