Skip to content

Commit

Permalink
Small style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Bridgewater committed Oct 7, 2015
1 parent 2fc54ec commit 7922d4e
Show file tree
Hide file tree
Showing 28 changed files with 385 additions and 389 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ once the connection has been established. Setting `enable_offline_queue` to
with an error, or an error will be emitted if no callback is specified.
* `retry_max_delay`: *null*; By default every time the client tries to connect and fails the reconnection delay almost doubles.
This delay normally grows infinitely, but setting `retry_max_delay` limits it to the maximum value, provided in milliseconds.
* `connect_timeout` *86400000*; Setting `connect_timeout` limits total time for client to reconnect.
* `connect_timeout`: *86400000*; Setting `connect_timeout` limits total time for client to reconnect.
The value is provided in milliseconds and is counted once the disconnect occurred. The last retry is going to happen exactly at the timeout time.
That way the default is to try reconnecting until 24h passed.
* `max_attempts` *0*; By default client will try reconnecting until connected. Setting `max_attempts`
* `max_attempts`: *0*; By default client will try reconnecting until connected. Setting `max_attempts`
limits total amount of connection tries. Setting this to 1 will prevent any reconnect tries.
* `auth_pass` *null*; If set, client will run redis auth command on connect.
* `family` *IPv4*; You can force using IPv6 if you set the family to 'IPv6'. See Node.js [net](https://nodejs.org/api/net.html) or [dns](https://nodejs.org/api/dns.html) modules how to use the family type.
* `auth_pass`: *null*; If set, client will run redis auth command on connect.
* `family`: *IPv4*; You can force using IPv6 if you set the family to 'IPv6'. See Node.js [net](https://nodejs.org/api/net.html) or [dns](https://nodejs.org/api/dns.html) modules how to use the family type.
* `disable_resubscribing`: *false*; If set to `true`, a client won't resubscribe after disconnecting

```js
Expand Down
26 changes: 13 additions & 13 deletions benchmarks/buffer_bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,56 @@ for (i = 99 ; i >= 0 ; i--) {
source[i] = 120;
}

var str = "This is a nice String.",
buf = new Buffer("This is a lovely Buffer.");
var str = 'This is a nice String.',
buf = new Buffer('This is a lovely Buffer.');

var start = new Date();
for (i = count * 100; i > 0 ; i--) {
if (Buffer.isBuffer(str)) {}
}
var end = new Date();
console.log("Buffer.isBuffer(str) " + (end - start) + " ms");
console.log('Buffer.isBuffer(str) ' + (end - start) + ' ms');

var start = new Date();
for (i = count * 100; i > 0 ; i--) {
if (Buffer.isBuffer(buf)) {}
}
var end = new Date();
console.log("Buffer.isBuffer(buf) " + (end - start) + " ms");
console.log('Buffer.isBuffer(buf) ' + (end - start) + ' ms');

var start = new Date();
for (i = count * 100; i > 0 ; i--) {
if (str instanceof Buffer) {}
}
var end = new Date();
console.log("str instanceof Buffer " + (end - start) + " ms");
console.log('str instanceof Buffer ' + (end - start) + ' ms');

var start = new Date();
for (i = count * 100; i > 0 ; i--) {
if (buf instanceof Buffer) {}
}
var end = new Date();
console.log("buf instanceof Buffer " + (end - start) + " ms");
console.log('buf instanceof Buffer ' + (end - start) + ' ms');

for (i = bytes ; i > 0 ; i --) {
var start = new Date();
for (j = count ; j > 0; j--) {
tmp = source.toString("ascii", 0, bytes);
tmp = source.toString('ascii', 0, bytes);
}
var end = new Date();
console.log("toString() " + i + " bytes " + (end - start) + " ms");
console.log('toString() ' + i + ' bytes ' + (end - start) + ' ms');
}

for (i = bytes ; i > 0 ; i --) {
var start = new Date();
for (j = count ; j > 0; j--) {
tmp = "";
tmp = '';
for (k = 0; k <= i ; k++) {
tmp += String.fromCharCode(source[k]);
}
}
var end = new Date();
console.log("manual string " + i + " bytes " + (end - start) + " ms");
console.log('manual string ' + i + ' bytes ' + (end - start) + ' ms');
}

for (i = bytes ; i > 0 ; i--) {
Expand All @@ -67,7 +67,7 @@ for (i = bytes ; i > 0 ; i--) {
}
}
var end = new Date();
console.log("Manual copy " + i + " bytes " + (end - start) + " ms");
console.log('Manual copy ' + i + ' bytes ' + (end - start) + ' ms');
}

for (i = bytes ; i > 0 ; i--) {
Expand All @@ -78,7 +78,7 @@ for (i = bytes ; i > 0 ; i--) {
}
}
var end = new Date();
console.log("Direct assignment " + i + " bytes " + (end - start) + " ms");
console.log('Direct assignment ' + i + ' bytes ' + (end - start) + ' ms');
}

for (i = bytes ; i > 0 ; i--) {
Expand All @@ -87,5 +87,5 @@ for (i = bytes ; i > 0 ; i--) {
source.copy(dest, 0, 0, i);
}
var end = new Date();
console.log("Buffer.copy() " + i + " bytes " + (end - start) + " ms");
console.log('Buffer.copy() ' + i + ' bytes ' + (end - start) + ' ms');
}
2 changes: 1 addition & 1 deletion benchmarks/diff_multi_bench_output.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function parseInt10(s) {

// green if greater than 0, red otherwise
function humanize_diff(num, unit) {
unit = unit || "";
unit = unit || '';
if (num > 0) {
return ('+' + num + unit).green;
}
Expand Down
98 changes: 49 additions & 49 deletions benchmarks/multi_bench.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

var path = require('path');
var RedisProcess = require("../test/lib/redis-process");
var RedisProcess = require('../test/lib/redis-process');
var rp;
var redis = require("../index");
var redis = require('../index');
var totalTime = 0;
var metrics = require("metrics");
var metrics = require('metrics');
var num_clients = parseInt(process.argv[2], 10) || 5;
var num_requests = 50000;
var tests = [];
Expand All @@ -19,7 +19,7 @@ var small_str, large_str, small_buf, large_buf, very_large_str, very_large_buf;

function lpad(input, len, chr) {
var str = input.toString();
chr = chr || " ";
chr = chr || ' ';

while (str.length < len) {
str = chr + str;
Expand All @@ -30,7 +30,7 @@ function lpad(input, len, chr) {
metrics.Histogram.prototype.print_line = function () {
var obj = this.printObj();

return lpad(obj.min, 4) + "/" + lpad(obj.max, 4) + "/" + lpad(obj.mean.toFixed(2), 7) + "/" + lpad(obj.p95.toFixed(2), 7);
return lpad(obj.min, 4) + '/' + lpad(obj.max, 4) + '/' + lpad(obj.mean.toFixed(2), 7) + '/' + lpad(obj.p95.toFixed(2), 7);
};

function Test(args) {
Expand Down Expand Up @@ -66,14 +66,14 @@ Test.prototype.new_client = function (id) {
new_client = redis.createClient(this.client_options);
new_client.create_time = Date.now();

new_client.on("connect", function () {
new_client.on('connect', function () {
self.connect_latency.update(Date.now() - new_client.create_time);
});

new_client.on("ready", function () {
new_client.on('ready', function () {
if (! versions_logged) {
console.log("Client count: " + num_clients + ", node version: " + process.versions.node + ", server version: " +
new_client.server_info.redis_version + ", parser: " + new_client.reply_parser.name);
console.log('Client count: ' + num_clients + ', node version: ' + process.versions.node + ', server version: ' +
new_client.server_info.redis_version + ', parser: ' + new_client.reply_parser.name);
versions_logged = true;
}
self.ready_latency.update(Date.now() - new_client.create_time);
Expand All @@ -84,7 +84,7 @@ Test.prototype.new_client = function (id) {
});

// If no redis server is running, start one
new_client.on("error", function(err) {
new_client.on('error', function(err) {
if (err.code === 'CONNECTION_BROKEN') {
throw err;
}
Expand All @@ -105,7 +105,7 @@ Test.prototype.new_client = function (id) {
};

Test.prototype.on_clients_ready = function () {
process.stdout.write(lpad(this.args.descr, 13) + ", " + lpad(this.args.pipeline, 5) + "/" + this.clients_ready + " ");
process.stdout.write(lpad(this.args.descr, 13) + ', ' + lpad(this.args.pipeline, 5) + '/' + this.clients_ready + ' ');
this.test_start = Date.now();

this.fill_pipeline();
Expand Down Expand Up @@ -159,64 +159,64 @@ Test.prototype.print_stats = function () {
var duration = Date.now() - this.test_start;
totalTime += duration;

console.log("min/max/avg/p95: " + this.command_latency.print_line() + " " + lpad(duration, 6) + "ms total, " +
lpad((this.num_requests / (duration / 1000)).toFixed(2), 8) + " ops/sec");
console.log('min/max/avg/p95: ' + this.command_latency.print_line() + ' ' + lpad(duration, 6) + 'ms total, ' +
lpad((this.num_requests / (duration / 1000)).toFixed(2), 8) + ' ops/sec');
};

small_str = "1234";
small_str = '1234';
small_buf = new Buffer(small_str);
large_str = (new Array(4096 + 1).join("-"));
large_str = (new Array(4096 + 1).join('-'));
large_buf = new Buffer(large_str);
very_large_str = (new Array((4 * 1024 * 1024) + 1).join("-"));
very_large_str = (new Array((4 * 1024 * 1024) + 1).join('-'));
very_large_buf = new Buffer(very_large_str);

tests.push(new Test({descr: "PING", command: "ping", args: [], pipeline: 1}));
tests.push(new Test({descr: "PING", command: "ping", args: [], pipeline: 50}));
tests.push(new Test({descr: 'PING', command: 'ping', args: [], pipeline: 1}));
tests.push(new Test({descr: 'PING', command: 'ping', args: [], pipeline: 50}));

tests.push(new Test({descr: "SET 4B str", command: "set", args: ["foo_rand000000000000", small_str], pipeline: 1}));
tests.push(new Test({descr: "SET 4B str", command: "set", args: ["foo_rand000000000000", small_str], pipeline: 50}));
tests.push(new Test({descr: 'SET 4B str', command: 'set', args: ['foo_rand000000000000', small_str], pipeline: 1}));
tests.push(new Test({descr: 'SET 4B str', command: 'set', args: ['foo_rand000000000000', small_str], pipeline: 50}));

tests.push(new Test({descr: "SET 4B buf", command: "set", args: ["foo_rand000000000000", small_buf], pipeline: 1}));
tests.push(new Test({descr: "SET 4B buf", command: "set", args: ["foo_rand000000000000", small_buf], pipeline: 50}));
tests.push(new Test({descr: 'SET 4B buf', command: 'set', args: ['foo_rand000000000000', small_buf], pipeline: 1}));
tests.push(new Test({descr: 'SET 4B buf', command: 'set', args: ['foo_rand000000000000', small_buf], pipeline: 50}));

tests.push(new Test({descr: "GET 4B str", command: "get", args: ["foo_rand000000000000"], pipeline: 1}));
tests.push(new Test({descr: "GET 4B str", command: "get", args: ["foo_rand000000000000"], pipeline: 50}));
tests.push(new Test({descr: 'GET 4B str', command: 'get', args: ['foo_rand000000000000'], pipeline: 1}));
tests.push(new Test({descr: 'GET 4B str', command: 'get', args: ['foo_rand000000000000'], pipeline: 50}));

tests.push(new Test({descr: "GET 4B buf", command: "get", args: ["foo_rand000000000000"], pipeline: 1, client_opts: { return_buffers: true} }));
tests.push(new Test({descr: "GET 4B buf", command: "get", args: ["foo_rand000000000000"], pipeline: 50, client_opts: { return_buffers: true} }));
tests.push(new Test({descr: 'GET 4B buf', command: 'get', args: ['foo_rand000000000000'], pipeline: 1, client_opts: { return_buffers: true} }));
tests.push(new Test({descr: 'GET 4B buf', command: 'get', args: ['foo_rand000000000000'], pipeline: 50, client_opts: { return_buffers: true} }));

tests.push(new Test({descr: "SET 4KiB str", command: "set", args: ["foo_rand000000000001", large_str], pipeline: 1}));
tests.push(new Test({descr: "SET 4KiB str", command: "set", args: ["foo_rand000000000001", large_str], pipeline: 50}));
tests.push(new Test({descr: 'SET 4KiB str', command: 'set', args: ['foo_rand000000000001', large_str], pipeline: 1}));
tests.push(new Test({descr: 'SET 4KiB str', command: 'set', args: ['foo_rand000000000001', large_str], pipeline: 50}));

tests.push(new Test({descr: "SET 4KiB buf", command: "set", args: ["foo_rand000000000001", large_buf], pipeline: 1}));
tests.push(new Test({descr: "SET 4KiB buf", command: "set", args: ["foo_rand000000000001", large_buf], pipeline: 50}));
tests.push(new Test({descr: 'SET 4KiB buf', command: 'set', args: ['foo_rand000000000001', large_buf], pipeline: 1}));
tests.push(new Test({descr: 'SET 4KiB buf', command: 'set', args: ['foo_rand000000000001', large_buf], pipeline: 50}));

tests.push(new Test({descr: "GET 4KiB str", command: "get", args: ["foo_rand000000000001"], pipeline: 1}));
tests.push(new Test({descr: "GET 4KiB str", command: "get", args: ["foo_rand000000000001"], pipeline: 50}));
tests.push(new Test({descr: 'GET 4KiB str', command: 'get', args: ['foo_rand000000000001'], pipeline: 1}));
tests.push(new Test({descr: 'GET 4KiB str', command: 'get', args: ['foo_rand000000000001'], pipeline: 50}));

tests.push(new Test({descr: "GET 4KiB buf", command: "get", args: ["foo_rand000000000001"], pipeline: 1, client_opts: { return_buffers: true} }));
tests.push(new Test({descr: "GET 4KiB buf", command: "get", args: ["foo_rand000000000001"], pipeline: 50, client_opts: { return_buffers: true} }));
tests.push(new Test({descr: 'GET 4KiB buf', command: 'get', args: ['foo_rand000000000001'], pipeline: 1, client_opts: { return_buffers: true} }));
tests.push(new Test({descr: 'GET 4KiB buf', command: 'get', args: ['foo_rand000000000001'], pipeline: 50, client_opts: { return_buffers: true} }));

tests.push(new Test({descr: "INCR", command: "incr", args: ["counter_rand000000000000"], pipeline: 1}));
tests.push(new Test({descr: "INCR", command: "incr", args: ["counter_rand000000000000"], pipeline: 50}));
tests.push(new Test({descr: 'INCR', command: 'incr', args: ['counter_rand000000000000'], pipeline: 1}));
tests.push(new Test({descr: 'INCR', command: 'incr', args: ['counter_rand000000000000'], pipeline: 50}));

tests.push(new Test({descr: "LPUSH", command: "lpush", args: ["mylist", small_str], pipeline: 1}));
tests.push(new Test({descr: "LPUSH", command: "lpush", args: ["mylist", small_str], pipeline: 50}));
tests.push(new Test({descr: 'LPUSH', command: 'lpush', args: ['mylist', small_str], pipeline: 1}));
tests.push(new Test({descr: 'LPUSH', command: 'lpush', args: ['mylist', small_str], pipeline: 50}));

tests.push(new Test({descr: "LRANGE 10", command: "lrange", args: ["mylist", "0", "9"], pipeline: 1}));
tests.push(new Test({descr: "LRANGE 10", command: "lrange", args: ["mylist", "0", "9"], pipeline: 50}));
tests.push(new Test({descr: 'LRANGE 10', command: 'lrange', args: ['mylist', '0', '9'], pipeline: 1}));
tests.push(new Test({descr: 'LRANGE 10', command: 'lrange', args: ['mylist', '0', '9'], pipeline: 50}));

tests.push(new Test({descr: "LRANGE 100", command: "lrange", args: ["mylist", "0", "99"], pipeline: 1}));
tests.push(new Test({descr: "LRANGE 100", command: "lrange", args: ["mylist", "0", "99"], pipeline: 50}));
tests.push(new Test({descr: 'LRANGE 100', command: 'lrange', args: ['mylist', '0', '99'], pipeline: 1}));
tests.push(new Test({descr: 'LRANGE 100', command: 'lrange', args: ['mylist', '0', '99'], pipeline: 50}));

tests.push(new Test({descr: "SET 4MiB buf", command: "set", args: ["foo_rand000000000002", very_large_buf], pipeline: 1, reqs: 500}));
tests.push(new Test({descr: "SET 4MiB buf", command: "set", args: ["foo_rand000000000002", very_large_buf], pipeline: 50, reqs: 500}));
tests.push(new Test({descr: 'SET 4MiB buf', command: 'set', args: ['foo_rand000000000002', very_large_buf], pipeline: 1, reqs: 500}));
tests.push(new Test({descr: 'SET 4MiB buf', command: 'set', args: ['foo_rand000000000002', very_large_buf], pipeline: 50, reqs: 500}));

tests.push(new Test({descr: "GET 4MiB str", command: "get", args: ["foo_rand000000000002"], pipeline: 1, reqs: 100}));
tests.push(new Test({descr: "GET 4MiB str", command: "get", args: ["foo_rand000000000002"], pipeline: 50, reqs: 100}));
tests.push(new Test({descr: 'GET 4MiB str', command: 'get', args: ['foo_rand000000000002'], pipeline: 1, reqs: 100}));
tests.push(new Test({descr: 'GET 4MiB str', command: 'get', args: ['foo_rand000000000002'], pipeline: 50, reqs: 100}));

tests.push(new Test({descr: "GET 4MiB buf", command: "get", args: ["foo_rand000000000002"], pipeline: 1, reqs: 100, client_opts: { return_buffers: true} }));
tests.push(new Test({descr: "GET 4MiB buf", command: "get", args: ["foo_rand000000000002"], pipeline: 50, reqs: 100, client_opts: { return_buffers: true} }));
tests.push(new Test({descr: 'GET 4MiB buf', command: 'get', args: ['foo_rand000000000002'], pipeline: 1, reqs: 100, client_opts: { return_buffers: true} }));
tests.push(new Test({descr: 'GET 4MiB buf', command: 'get', args: ['foo_rand000000000002'], pipeline: 50, reqs: 100, client_opts: { return_buffers: true} }));

function next() {
var test = tests.shift();
Expand All @@ -231,7 +231,7 @@ function next() {
next();
});
} else {
console.log("End of tests. Total time elapsed:", totalTime, 'ms');
console.log('End of tests. Total time elapsed:', totalTime, 'ms');
process.exit(0);
}
}
Expand Down
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ This is the biggest release that node_redis had since it was released in 2010. A
- Fix commands being inconsistent and behaving wrong (@BridgeAR)
- Channel names with spaces are now properly resubscribed after a reconnection (@pbihler)
- Do not try to reconnect after the connection timeout has been exceeded (@BridgeAR)
- Removed bad .eval implementation (@BridgeAR)
- Ensure the execution order is observed if using .eval (@BridgeAR)
- Fix commands not being rejected after calling .quit (@BridgeAR)
- Fix .auth calling the callback twice if already connected (@BridgeAR)
- Fix detect_buffers not working in pub sub mode and while monitoring (@BridgeAR)
Expand Down
6 changes: 3 additions & 3 deletions examples/auth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var redis = require("redis"),
var redis = require('redis'),
client = redis.createClient();

// This command is magical. Client stashes the password and will issue on every connect.
client.auth("somepass");
// The client stashes the password and will reauthenticate on every connect.
client.auth('somepass');
14 changes: 7 additions & 7 deletions examples/backpressure_drain.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var redis = require("../index"),
var redis = require('../index'),
client = redis.createClient(null, null, {
command_queue_high_water: 5,
command_queue_low_water: 1
Expand All @@ -9,26 +9,26 @@ var redis = require("../index"),

function op() {
if (remaining_ops <= 0) {
console.error("Finished.");
console.error('Finished.');
process.exit(0);
}

remaining_ops--;
if (client.hset("test hash", "val " + remaining_ops, remaining_ops) === false) {
console.log("Pausing at " + remaining_ops);
if (client.hset('test hash', 'val ' + remaining_ops, remaining_ops) === false) {
console.log('Pausing at ' + remaining_ops);
paused = true;
} else {
process.nextTick(op);
}
}

client.on("drain", function () {
client.on('drain', function () {
if (paused) {
console.log("Resuming at " + remaining_ops);
console.log('Resuming at ' + remaining_ops);
paused = false;
process.nextTick(op);
} else {
console.log("Got drain while not paused at " + remaining_ops);
console.log('Got drain while not paused at ' + remaining_ops);
}
});

Expand Down
6 changes: 3 additions & 3 deletions examples/eval.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

var redis = require("../index"),
var redis = require('../index'),
client = redis.createClient();

client.eval("return 100.5", 0, function (err, res) {
client.eval('return 100.5', 0, function (err, res) {
console.dir(err);
console.dir(res);
});

client.eval([ "return 100.5", 0 ], function (err, res) {
client.eval([ 'return 100.5', 0 ], function (err, res) {
console.dir(err);
console.dir(res);
});
6 changes: 3 additions & 3 deletions examples/extend.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

var redis = require("redis"),
var redis = require('redis'),
client = redis.createClient();

// Extend the RedisClient prototype to add a custom method
// This one converts the results from "INFO" into a JavaScript Object
// This one converts the results from 'INFO' into a JavaScript Object

redis.RedisClient.prototype.parse_info = function (callback) {
this.info(function (err, res) {
var lines = res.toString().split("\r\n").sort();
var lines = res.toString().split('\r\n').sort();
var obj = {};
lines.forEach(function (line) {
var parts = line.split(':');
Expand Down
Loading

0 comments on commit 7922d4e

Please sign in to comment.