New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

multiple-redis

Package Overview
Dependencies
Maintainers
1
Versions
166
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multiple-redis

Run redis commands against multiple redis instances.

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
161
increased by34.17%
Maintainers
1
Weekly downloads
 
Created
Source

multiple-redis

NPM Version Build Status Coverage Status Code Climate bitHound Score Inline docs
License Dependencies devDependency Status
Retire Status

Run redis commands against multiple redis instances.

Overview

This library enables to submit redis commands to multiple redis instances.
The client interface is the same as the 'redis' node package at: https://github.com/NodeRedis/node_redis
However, every command actually invokes multiple redis backends.

When To Use

Generally in production you would like a failover capability for your redis server.
Working with only 1 redis instance can cause your entire production system to fail in case redis goes down for any reason.
For example, when using redis as an express session store and redis is down, users HTTP requests will be rejected.
Redis does come with a built in failover and clustering capabilities via master/slave solution and monitoring via redis sentinel.
However, those solutions sometimes might cause other issues, for example, express redis works with only 1 redis client.
If that redis client is not available, it will not failover to the slave redis.
There are other libraries to resolve the issue, but the basic library does not provide any solution.
Other issues might be if you failover to the slave redis but it is only readonly mode (by default slave redis is read only).

This does not mean that I do not support the Redis master/slave + sentinal solution but sometimes using multiple independent Redis servers for none critical data serves as a better solution which is much more simple to deploy and manage in production.

How This Library Works

This library basically does 2 main things.

  • Get commands - When a get (which does not modify data) command is called, the redis client will go redis by redis in a sequence until it finds a redis which provides data for the get command.
    Any error, or any redis which is unable to provide the data is ignored.
    Once a specific redis provides the data, the next redis servers are skipped and the command callback is invoked with that data.
  • Set/Other commands - When a non get command is called, all redis servers are invoked in parallel with the same command to ensure that all redis servers are updated.
    If any redis server was able to process the command, the original command callback will receive a valid response.

This means that at least once redis server needs to work good for the main client to notify the calling code that everything works ok.
A side affect of this solution is that every publish event would be received multiple times by the subscribers, so you need to code accordingly and prevent any possible issues.

Simple Scenario

Let us take the express redis session store as an example.
Since this library provides the same redis interface as the common redis client, you can provide this library to the redis session store.
When a new session is created, it will be created in all redis servers (in this example, lets assume we have 2).
In case the first redis server suddenly fails, the session store is still able to fetch and update the session data from the second redis server.
When the first redis server comes back up, the session is still available to the session store from the second redis server and any session modification (due to some HTTP request) will cause both redis servers to now hold the latest express session data.
It is by no means, not a perfect solution, but it does has its advantages.
First and foremost, its simple deployment requirements.

Usage

In order to use this library, you need to either create the redis clients or provide the redis connection data as follows:

//create multiple redis clients
var redis = require('redis');
var client1 = redis.createClient(...);
var client2 = redis.createClient(...);

//create the wrapper client
var MultipleRedis = require('multiple-redis');
var multiClient = MultipleRedis.createClient([client1, client2]);

//run any command on the multi client instead of the original clients
multiClient.set('string key', 'string val', callback);

Or

//create the wrapper client with connection info
var MultipleRedis = require('multiple-redis');
var multiClient = MultipleRedis.createClient([{
    host: 'host1',
    port: 6379
}, {
   host: 'host2',
   port: 6379
}], options);

//run any command on the multi client instead of the original clients
multiClient.set('string key', 'string val', callback);

The rest of the API is the same as defined in the redis node library.

Installation

In order to use this library, just run the following npm install command:

npm install --save multiple-redis

Limitations

Not all of the original redis client attributes are available (for example: redis.debug_mode).
Also Multi is currently not supported.

API Documentation

See full docs at: API Docs

Release History

DateVersionDescription
2015-09-03v0.0.4Maintenance
2015-09-03v0.0.3Added support for connected and server_info attributes.
2015-09-03v0.0.2Initial release.

License

Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.

Keywords

FAQs

Package last updated on 03 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc