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

push-ioredis

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

push-ioredis - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

lib/clientProxy.js

32

lib/redis-failover.js

@@ -7,3 +7,3 @@ var Redis = require('ioredis');

var RedisFailover= require('../lib/redis-failover');
var ClientProxy = require('../lib/clientProxy2');
var ClientProxy = require('../lib/clientProxy');
var RedisClusterMap = require('../lib/redisClusterMap');

@@ -14,8 +14,5 @@

//var RedisFailover = function(configFilePath, redisShardingPath, clusterMapPath) {
var RedisFailover = function(configObj, redisShardingObj, clusterMapObj) {
var RedisFailover = function(configObj, redisShardingObj) {
EventEmitter.call(this);
this.redisSharding = redisShardingObj;
this.clusterMapObj = clusterMapObj;
//console.log('redisSharding is ' + this.redisSharding);

@@ -50,9 +47,15 @@ var sentinels = configObj['sentinels'];

var redis = new Redis(opts);
if (!redis) {
console.log('err in new Redis(opts)');
}
var i = obj[key];
(function(i) {
// throw to upper layer application
// NEED TO UPDATE
redis.once('error', function(){
console.log('Error in redis-failover: ' + i + ' had connection error');
});
})(i);
dictionary[obj[key]] = redis;
}
}
//EventEmitter.call(redisProxy);
EventEmitter.call(this);
console.log('RedisFailover instance created');

@@ -65,7 +68,4 @@ };

var sharding = this.redisSharding;
//var redisFailover = new RedisFailover();
//redisFailover.createClient('../config/redisConfig.json');
var redisClusterMap = new RedisClusterMap(this.clusterMapObj);
//var redisProxy = new ClientProxy(redisFailover, sharding);
var redisClusterMap = new RedisClusterMap(this.redisSharding['map']);
redisProxy = new ClientProxy(this, sharding);

@@ -107,9 +107,3 @@

async.each(redisArray, function(redis, callback) {
//redis.info('Replication', function(err, result){
//console.log('cnt = ' + cnt + ', result = ' + result);
//console.log('result = ' + result);
//cnt++;
callback();
//console.log('xxxx');
//});
});

@@ -116,0 +110,0 @@ }

{
"name": "push-ioredis",
"version": "1.0.8",
"version": "1.0.9",
"description": "use sentinel + ioredis + sharding logic to replace push-redis-failover",

@@ -5,0 +5,0 @@ "main": "redisClient.js",

push-ioredis
===============
## push-ioredis:
Use redis sentinel(Redis officially) and [ioredis](https://github.com/luin/ioredis) to replace [redis-failover](https://git.hz.netease.com/bearcat/push-redis-failover), which would make our redis cluster high-available and easy to operate.
The push-ioredis aims to use redis sentinel(Redis officially) and [ioredis](https://github.com/luin/ioredis) to replace [redis-failover](https://git.hz.netease.com/bearcat/push-redis-failover), which would make our redis cluster high-available and easy to operate.
NOTE THAT THE LIBRARY IS NOT INDEPENDENT.
NOTE THAT THE LIBRARY IS **NOT INDEPENDENT**, which is a component of [push-server](https://git.hz.netease.com/pomelo/push-server). The push-ioredis library relys on:
* redis master-salves
* sentinels that watch on these master-salves
* encapsulated sharding object
---
### Example
``` javascript
node test/t
node test/caller
```
#### index.js
Entrance of this library.
#### lib/redis-failover.js
Implements the redisNodeName-ioredisClient-Dictionary, e.g. ["node_x":"related ioredis instance"].
Create the failover redis obj, which receives the sharding objects as params.
Acts as an API.
#### lib/redisClusterMap.js
According to specific "env" to load the redisClusterMap. Get the node name by the hash value. e.g. return node_1 when receives hash value 4~7.
Get the node name by the hash value. e.g. return node_1 when receives hash value 4~7.
#### lib/clientProxy2
#### lib/clientProxy
Implements the sharding logic.

@@ -19,0 +32,0 @@ * Generate the hash value of a key

var crypto = require('crypto');
var fs = require('fs');
var RedisFailover= require('../lib/redis-failover');
//var ClientProxy = require('../lib/clientProxy2');
//var ClientProxy = require('../lib/clientProxy');
//var RedisClusterMap = require('../lib/redisClusterMap');
//var redisSharding = require('../config/redisSharding')
//var drillSharding = redisSharding['drill'];
var redisConfigPath = '../config/redisConfig.json';
var redisShardingPath = '../config/redisSharding.json';
var clusterMapPath = '../config/drill/clusterMap.json';
//var redisFailover = new RedisFailover(redisConfigPath, redisShardingPath, env, clusterMapPath);
//var clusterMapPath = '../config/drill/clusterMap.json';
var configObj = require(redisConfigPath);
var redisShardingObj = require(redisShardingPath);
var clusterMapObj = require(clusterMapPath);
var redisFailover = new RedisFailover(configObj, redisShardingObj, clusterMapObj);
//var clusterMapObj = require(clusterMapPath);
//var redisFailover = new RedisFailover(configObj, redisShardingObj, clusterMapObj);
var redisFailover = new RedisFailover(configObj, redisShardingObj);
console.log('before ready ---------------------------------------');
redisFailover.on('ready', function(){
console.log('ready fired !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
});
redisFailover.on('myevent', function(){
console.log('myevent fired !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
});
console.log('end ready ---------------------------------------');
var failover = redisFailover.createClient();

@@ -30,6 +41,2 @@

//redisProxy.get('test.news.163.com:Android:android_l9haCH5w1hJyr3FGxXWxaijARqE=', function(err, result) {
// console.log('in caller, get result = ' + result);
//});
var redisList = [];

@@ -70,2 +77,3 @@ var key;

// sleep for 2 sencod
sleep(2);

@@ -72,0 +80,0 @@

var crypto = require('crypto');
var fs = require('fs');
var RedisFailover= require('../lib/redis-failover');
var ClientProxy = require('../lib/clientProxy2');
var RedisClusterMap = require('../lib/redisClusterMap');
var redisSharding = require('../config/redisSharding')
var drillSharding = redisSharding['drill'];
var redisFailover = new RedisFailover();
var redisConfigPath = '../config/redisConfig.json';
var redisShardingPath = '../config/redisSharding.json';
//var env = 'drill';
var clusterMapPath = '../config/drill/clusterMap.json';
var redisClusterMap = new RedisClusterMap();
var redisProxy = new ClientProxy(redisFailover, drillSharding);
var configObj = require(redisConfigPath);
var redisShardingObj = require(redisShardingPath);
console.log(drillSharding['num']);
var redisFailover = new RedisFailover(configObj, redisShardingObj);
var failover = redisFailover.createClient();
redisProxy.init();
redisProxy.setRedisClusterMap(redisClusterMap);
console.log('this is largeRandomSetGetTest');

@@ -30,3 +27,3 @@

//stream.write(key + ':' + value + '\n');
redisProxy.set(key, value, function(err, result) {
failover.set(key, value, function(err, result) {
//console.log('in largeRandomSetGetTest, set key resut = ' + result);

@@ -43,3 +40,3 @@ });

for (key in redisList) {
redisProxy.get(key, function(err, result){
failover.get(key, function(err, result){
if (!!err) {

@@ -46,0 +43,0 @@ console.log('sth wrong');

var RedisFailover = require('../lib/redis-failover');
var Redis = require('ioredis');
//var redisFailover = new RedisFailover();
//redisFailover.createClient('../config/redisConfig.json');
var redisConfigPath = '../config/redisConfig.json';
var redisShardingPath = '../config/redisSharding.json';
//var env = 'drill';
var clusterMapPath = '../config/drill/clusterMap.json';
var configObj = require(redisConfigPath);
var redisFailover = new RedisFailover(configObj, redisShardingPath, clusterMapPath);
var redisShardingObj = require(redisShardingPath);
var redisFailover = new RedisFailover(configObj, redisShardingObj);
var failover = redisFailover.createClient();

@@ -20,12 +17,2 @@

//failover.once('ready', function() {
// console.log('in once, ready');
//});
//redisFailover.once('ready', function() {
// console.log('redisFailover in once, ready');
//});
//redisFailover.emit('ready');
redis.dbsize(function(err, result) {

@@ -32,0 +19,0 @@ if (!!err) {

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