Skip to content

Commit

Permalink
Tweak style
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Oct 24, 2015
1 parent 6a3c4fb commit 2732497
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 102 deletions.
3 changes: 1 addition & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
"max-depth": [0, 3],
"max-len": [1, 121, 2],
"max-params": 0,
"max-statements": 0,
"no-bitwise": 1,
"max-statements": 0
}
}
52 changes: 26 additions & 26 deletions benchmarks/single_node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var nodeRedis = require('redis');
var ioRedis = require('../');
var IORedis = require('../');
var ndredis, ioredis;

console.log('==========================');
Expand All @@ -27,20 +27,20 @@ var waitReady = function (next) {
});
};

suite('simple set', function() {
suite('simple set', function () {
set('mintime', 5000);
set('concurrency', 300);
before(function (start) {
ndredis = nodeRedis.createClient();
ioredis = new ioRedis();
ioredis = new IORedis();
waitReady(start);
});

bench('ioredis', function(next) {
bench('ioredis', function (next) {
ioredis.set('foo', 'bar', next);
});

bench('node_redis', function(next) {
bench('node_redis', function (next) {
ndredis.set('foo', 'bar', next);
});

Expand All @@ -50,22 +50,22 @@ suite('simple set', function() {
});
});

suite('simple get', function() {
suite('simple get', function () {
set('mintime', 5000);
set('concurrency', 300);
before(function (start) {
ndredis = nodeRedis.createClient();
ioredis = new ioRedis();
ioredis = new IORedis();
waitReady(function () {
ndredis.set('foo', 'bar', start);
});
});

bench('ioredis', function(next) {
bench('ioredis', function (next) {
ioredis.get('foo', next);
});

bench('node_redis', function(next) {
bench('node_redis', function (next) {
ndredis.get('foo', next);
});

Expand All @@ -75,26 +75,26 @@ suite('simple get', function() {
});
});

suite('simple get with pipeline', function() {
suite('simple get with pipeline', function () {
set('mintime', 5000);
set('concurrency', 300);
before(function (start) {
ndredis = nodeRedis.createClient();
ioredis = new ioRedis();
ioredis = new IORedis();
waitReady(function () {
ndredis.set('foo', 'bar', start);
});
});

bench('ioredis', function(next) {
bench('ioredis', function (next) {
var pipeline = ioredis.pipeline();
for (var i = 0; i < 10; ++i) {
pipeline.get('foo');
}
pipeline.exec(next);
});

bench('node_redis', function(next) {
bench('node_redis', function (next) {
var pending = 0;
for (var i = 0; i < 10; ++i) {
pending += 1;
Expand All @@ -113,12 +113,12 @@ suite('simple get with pipeline', function() {
});
});

suite('lrange 100', function() {
suite('lrange 100', function () {
set('mintime', 5000);
set('concurrency', 300);
before(function (start) {
ndredis = nodeRedis.createClient();
ioredis = new ioRedis();
ioredis = new IORedis();
waitReady(function () {
var item = [];
for (var i = 0; i < 100; ++i) {
Expand All @@ -129,11 +129,11 @@ suite('lrange 100', function() {
});
});

bench('ioredis', function(next) {
bench('ioredis', function (next) {
ioredis.lrange('foo', 0, 99, next);
});

bench('node_redis', function(next) {
bench('node_redis', function (next) {
ndredis.lrange('foo', 0, 99, next);
});

Expand All @@ -143,23 +143,23 @@ suite('lrange 100', function() {
});
});

suite('publish', function() {
suite('publish', function () {
set('mintime', 5000);
set('concurrency', 300);

before(function (start) {
ndredis = nodeRedis.createClient();
ioredis = new ioRedis();
ioredis = new IORedis();
waitReady(function () {
start();
});
});

bench('ioredis', function(next) {
bench('ioredis', function (next) {
ioredis.publish('foo', 'bar', next);
});

bench('node_redis', function(next) {
bench('node_redis', function (next) {
ndredis.publish('foo', 'bar', next);
});

Expand All @@ -169,7 +169,7 @@ suite('publish', function() {
});
});

suite('subscribe', function() {
suite('subscribe', function () {
set('mintime', 5000);
set('concurrency', 300);

Expand All @@ -180,15 +180,15 @@ suite('subscribe', function() {

before(function (start) {
ndredis = nodeRedis.createClient();
ioredis = new ioRedis();
ioredis = new IORedis();
waitReady(function () {
ndsubscriber = ndredis;
ndsubscriber.subscribe('foo');
iosubscriber = ioredis;
iosubscriber.subscribe('foo');

ndredis = nodeRedis.createClient();
ioredis = new ioRedis();
ioredis = new IORedis();
waitReady(function () {
ndpublisher = ndredis;
iopublisher = ioredis;
Expand All @@ -197,14 +197,14 @@ suite('subscribe', function() {
});
});

bench('ioredis', function(next) {
bench('ioredis', function (next) {
iosubscriber.removeAllListeners('message');
ndsubscriber.removeAllListeners('message');
iosubscriber.on('message', next);
iopublisher.publish('foo', 'bar');
});

bench('node_redis', function(next) {
bench('node_redis', function (next) {
iosubscriber.removeAllListeners('message');
ndsubscriber.removeAllListeners('message');
ndsubscriber.on('message', next);
Expand Down
15 changes: 9 additions & 6 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ var Command = require('./command');
* @param {number} [options.maxRedirections=16] - When a MOVED or ASK error is received, client will redirect the
* command to another node. This option limits the max redirections allowed to send a command.
* @param {function} [options.clusterRetryStrategy] - See "Quick Start" section
* @param {number} [options.retryDelayOnFailover=2000] - When an error is received when sending a command(e.g. "Connection is closed." when the target Redis node is down),
* @param {number} [options.retryDelayOnClusterDown=1000] - When a CLUSTERDOWN error is received, client will retry if `retryDelayOnClusterDown` is valid delay time.
* @param {number} [options.retryDelayOnFailover=2000] - When an error is received when sending a command(e.g.
* "Connection is closed." when the target Redis node is down),
* @param {number} [options.retryDelayOnClusterDown=1000] - When a CLUSTERDOWN error is received, client will retry
* if `retryDelayOnClusterDown` is valid delay time.
* @extends [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)
* @extends Commander
*/
Expand Down Expand Up @@ -293,6 +295,8 @@ Cluster.prototype.refreshSlotsCache = function (callback) {
return;
}
this.isRefreshing = true;

var _this = this;
var wrapper = function () {
_this.isRefreshing = false;
if (typeof callback === 'function') {
Expand All @@ -302,7 +306,6 @@ Cluster.prototype.refreshSlotsCache = function (callback) {

var keys = _.shuffle(Object.keys(this.nodes));

var _this = this;
var lastNodeError = null;

function tryNode(index) {
Expand Down Expand Up @@ -392,7 +395,7 @@ Cluster.prototype.sendCommand = function (command, stream, node) {
}
tryConnection();

function tryConnection (random, asking) {
function tryConnection(random, asking) {
if (_this.status === 'end') {
command.reject(new Error('Cluster is ended.'));
return;
Expand Down Expand Up @@ -504,15 +507,15 @@ Cluster.prototype.getInfoFromNode = function (redis, callback) {
allNodes.push(masterNode);
delete oldNodes[masterNodeKey];
if (_this.options.readOnly) {
items.forEach(function(item) {
items.forEach(function (item) {
var host = item[0];
var port = item[1];
allNodes.push(_this.createNode(port, host));
delete oldNodes[host + ':' + port];
});
}
for (var slot = slotRangeStart; slot <= slotRangeEnd; ++slot) {
_this.slots[slot] = { masterNode : masterNode, allNodes: allNodes };
_this.slots[slot] = { masterNode: masterNode, allNodes: allNodes };
}
}

Expand Down
7 changes: 4 additions & 3 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ Command.prototype._convertValue = function (resolve) {

Command.FLAGS = {
// Commands that can be processed when Redis is loading data from disk
VALID_WHEN_LOADING: ['info', 'auth', 'select', 'subscribe', 'unsubscribe', 'psubscribe', 'pubsubscribe', 'publish', 'shutdown', 'replconf', 'role', 'pubsub', 'command', 'latency'],
VALID_WHEN_LOADING: ['info', 'auth', 'select', 'subscribe', 'unsubscribe', 'psubscribe',
'pubsubscribe', 'publish', 'shutdown', 'replconf', 'role', 'pubsub', 'command', 'latency'],
// Commands that can be processed when client is in the subscriber mode
VALID_IN_SUBSCRIBER_MODE: ['subscribe', 'psubscribe', 'unsubscribe', 'punsubscribe', 'ping', 'quit'],
// Commands that are valid in monitor mode
Expand Down Expand Up @@ -302,7 +303,7 @@ Command.setArgumentTransformer('mset', function (args) {
if (typeof Map !== 'undefined' && args[0] instanceof Map) {
return utils.convertMapToArray(args[0]);
}
if ( typeof args[0] === 'object' && args[0] !== null) {
if (typeof args[0] === 'object' && args[0] !== null) {
return utils.convertObjectToArray(args[0]);
}
}
Expand All @@ -314,7 +315,7 @@ Command.setArgumentTransformer('hmset', function (args) {
if (typeof Map !== 'undefined' && args[1] instanceof Map) {
return [args[0]].concat(utils.convertMapToArray(args[1]));
}
if ( typeof args[1] === 'object' && args[1] !== null) {
if (typeof args[1] === 'object' && args[1] !== null) {
return [args[0]].concat(utils.convertObjectToArray(args[1]));
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/parsers/hiredis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var util = require('util');
var hiredis = require('hiredis');
var ReplyError = require('../reply_error');

Expand Down
4 changes: 2 additions & 2 deletions lib/parsers/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
Originally developed by Matthew Ranney, http://ranney.com/
*/

var util = require('util');
var utils = require('../utils');
var ReplyError = require('../reply_error');

Expand Down Expand Up @@ -219,7 +218,8 @@ ReplyParser.prototype._packetEndOffset = function () {
offset++;

if (offset >= this._buffer.length) {
throw new IncompleteReadBuffer('didn\'t see LF after NL reading multi bulk count (' + offset + ' => ' + this._buffer.length + ', ' + this._offset + ')');
throw new IncompleteReadBuffer('didn\'t see LF after NL reading multi bulk count (' +
offset + ' => ' + this._buffer.length + ', ' + this._offset + ')');
}
}

Expand Down
9 changes: 5 additions & 4 deletions lib/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Pipeline.prototype.fillResult = function (value, position) {
this.leftRedirections = {};
}
this.redis.handleError(commonError, this.leftRedirections, {
moved: function (node, slot) {
moved: function (node) {
_this.preferNode = node;
_this.redis.slots[errv[1]] = node;
_this.redis.refreshSlotsCache();
Expand Down Expand Up @@ -201,7 +201,8 @@ Pipeline.prototype.exec = function (callback) {
pipelineSlot = slot;
}
if (pipelineSlot !== slot) {
this.reject(new Error('All keys in the pipeline should belong to the same slot(expect "' + keys[j] + '" belongs to slot ' + pipelineSlot + ').'));
this.reject(new Error('All keys in the pipeline should belong to the same slot(expect "' +
keys[j] + '" belongs to slot ' + pipelineSlot + ').'));
return this.promise;
}
}
Expand Down Expand Up @@ -241,9 +242,9 @@ Pipeline.prototype.exec = function (callback) {
}));
}).then(execPipeline);

function execPipeline () {
function execPipeline() {
var data = '';
var writePending = _this.replyPending = _this._queue.length;
var writePending = _this.replyPending = _this._queue.length;

var node = { slot: pipelineSlot, redis: _this.preferNode };
var bufferMode = false;
Expand Down

0 comments on commit 2732497

Please sign in to comment.