Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redis-clustr

Package Overview
Dependencies
Maintainers
4
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-clustr - npm Package Compare versions

Comparing version 1.6.0 to 1.7.0

2

package.json
{
"name": "redis-clustr",
"version": "1.6.0",
"version": "1.7.0",
"description": "Redis cluster client",

@@ -5,0 +5,0 @@ "main": "src/RedisClustr.js",

@@ -79,6 +79,7 @@ 'use strict';

err.code === 'UNCERTAIN_STATE' ||
err.code === 'NR_CLOSED' ||
/Redis connection to .* failed.*/.test(err.message)
) {
// broken connection so force a new client to be created (node_redis will reconnect other errors)
if (err.code === 'CONNECTION_BROKEN') self.connections[name] = null;
// broken/closed connection so force a new client to be created (node_redis should reconnect other errors)
if (err.code === 'CONNECTION_BROKEN' || err.code === 'NR_CLOSED') self.connections[name] = null;
self.emit('connectionError', err, cli);

@@ -108,2 +109,5 @@ self.getSlots();

// set connection to null so we create a new client if we want to reconnect
if (cli.closing) self.connections[name] = null;
// setImmediate as node_redis sets emitted_end after emitting end

@@ -127,10 +131,17 @@ setImmediate(function() {

* @date 2015-02-18
* @param {array} exclude List of addresses to exclude (falsy to ignore none)
* @return {Redis} A random, ready, Redis connection.
* @param {array} exclude List of addresses to exclude (falsy to ignore none)
* @param {boolean} forceSlaves Include slaves, regardless of configuration
* @return {Redis} A random, ready, Redis connection.
*/
RedisClustr.prototype.getRandomConnection = function(exclude) {
RedisClustr.prototype.getRandomConnection = function(exclude, forceSlaves) {
var self = this;
var masterOnly = !forceSlaves && self.config.slaves === 'never';
var available = Object.keys(self.connections).filter(function(f) {
return self.connections[f] && self.connections[f].ready && (!exclude || exclude.indexOf(f) === -1);
var con = self.connections[f];
return con &&
con.ready &&
(!exclude || exclude.indexOf(f) === -1) &&
(!masterOnly || con.master);
});

@@ -184,3 +195,3 @@

var client = self.getRandomConnection(exclude);
var client = self.getRandomConnection(exclude, true);
if (!client) {

@@ -276,3 +287,2 @@ var err = new Error('couldn\'t get slot allocation');

// this command doesnt have keys, return any connection
// NOTE: this means slaves may be used for no key commands regardless of slave config
if (conf.keyless) return self.getRandomConnection();

@@ -304,2 +314,9 @@

var cli = clients[index];
if (!cli.ready) {
self.getSlots();
// this could be improved to select another slave
return self.getRandomConnection();
}
if (index === 0 && cli.readOnly) {

@@ -444,3 +461,3 @@ cli.send_command('readwrite', []);

if (msg.substr(0, 8) === 'TRYAGAIN' || err.code === 'CLUSTERDOWN') {
if (err.code === 'CLUSTERDOWN' || msg.substr(0, 8) === 'TRYAGAIN') {
// TRYAGAIN response or cluster down, retry with backoff up to 1280ms

@@ -573,6 +590,6 @@ setTimeout(function() {

cli.on('error', function(err) {
console.log(err);
if (
err.code === 'CONNECTION_BROKEN' ||
err.code === 'UNCERTAIN_STATE' ||
err.code === 'NR_CLOSED' ||
/Redis connection to .* failed.*/.test(err.message)

@@ -625,5 +642,18 @@ ) {

*/
RedisClustr.prototype.batch = RedisClustr.prototype.multi = function() {
RedisClustr.prototype.batch = RedisClustr.prototype.multi = function(commands) {
var self = this;
return new RedisBatch(self);
var batch = new RedisBatch(self);
if (Array.isArray(commands) && commands.length > 0) {
commands.forEach(function (command) {
var args = [];
if (command.length > 1) {
args = command.slice(1);
}
batch[command[0]].apply(batch, args);
});
}
return batch;
};

@@ -630,0 +660,0 @@

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