Skip to content

Commit

Permalink
Merge pull request #785 from fintura/master
Browse files Browse the repository at this point in the history
Add "use strict", semicolons, whitespace & code cleanup, remove util.print.
  • Loading branch information
erinishimoticha committed Aug 6, 2015
2 parents b53ebb2 + 01a3773 commit 6cae0b8
Show file tree
Hide file tree
Showing 39 changed files with 130 additions and 62 deletions.
4 changes: 3 additions & 1 deletion benches/buffer_bench.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var source = new Buffer(100),
dest = new Buffer(100), i, j, k, tmp, count = 1000000, bytes = 100;

for (i = 99 ; i >= 0 ; i--) {
source[i] = 120;
}
Expand Down
2 changes: 2 additions & 0 deletions benches/hiredis_parser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var Parser = require('../lib/parser/hiredis').Parser;
var assert = require('assert');

Expand Down
2 changes: 2 additions & 0 deletions benches/re_sub_test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var client = require('../index').createClient()
, client2 = require('../index').createClient()
, assert = require('assert');
Expand Down
2 changes: 2 additions & 0 deletions benches/reconnect_test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var redis = require("../index").createClient(null, null, {
// max_attempts: 4
});
Expand Down
12 changes: 2 additions & 10 deletions benches/stress/codec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
'use strict';

var json = {
encode: JSON.stringify,
decode: JSON.parse
};

var MsgPack = require('node-msgpack');
msgpack = {
encode: MsgPack.pack,
decode: function(str) { return MsgPack.unpack(new Buffer(str)); }
};

bison = require('bison');

module.exports = json;
//module.exports = msgpack;
//module.exports = bison;
2 changes: 2 additions & 0 deletions benches/stress/speed/speed.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var msgpack = require('node-msgpack');
var bison = require('bison');
var codec = {
Expand Down
2 changes: 2 additions & 0 deletions benches/sub_quit_test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

Expand Down
2 changes: 2 additions & 0 deletions connection_breaker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var net = require('net');

var proxyPort = 6379;
Expand Down
10 changes: 6 additions & 4 deletions diff_multi_bench_output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

'use strict';

var colors = require('colors'),
fs = require('fs'),
_ = require('underscore'),
Expand Down Expand Up @@ -35,8 +37,8 @@ before_lines.forEach(function(b, i) {
return;
}

b_words = b.split(' ').filter(is_whitespace);
a_words = a.split(' ').filter(is_whitespace);
var b_words = b.split(' ').filter(is_whitespace);
var a_words = a.split(' ').filter(is_whitespace);

var ops =
[b_words, a_words]
Expand All @@ -47,7 +49,7 @@ before_lines.forEach(function(b, i) {
var isNaN = !num && num !== 0;
return !isNaN;
});
if (ops.length != 2) return
if (ops.length !== 2) return;

var delta = ops[1] - ops[0];
var pct = ((delta / ops[0]) * 100).toPrecision(3);
Expand All @@ -58,7 +60,7 @@ before_lines.forEach(function(b, i) {
pct = humanize_diff(pct, '%');
console.log(
// name of test
command_name(a_words) == command_name(b_words)
command_name(a_words) === command_name(b_words)
? command_name(a_words) + ':'
: '404:',
// results of test
Expand Down
2 changes: 2 additions & 0 deletions examples/auth.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

Expand Down
2 changes: 2 additions & 0 deletions examples/backpressure_drain.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var redis = require("../index"),
client = redis.createClient(null, null, {
command_queue_high_water: 5,
Expand Down
2 changes: 2 additions & 0 deletions examples/eval.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

Expand Down
4 changes: 3 additions & 1 deletion examples/extend.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

Expand All @@ -14,7 +16,7 @@ redis.RedisClient.prototype.parse_info = function (callback) {
obj[parts[0]] = parts[1];
}
});
callback(obj)
callback(obj);
});
};

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

// Read a file from disk, store it in Redis, then read it back from Redis.

var redis = require("redis"),
Expand All @@ -11,17 +13,17 @@ var redis = require("redis"),

// Read a file from fs, store it in Redis, get it back from Redis, write it back to fs.
fs.readFile(filename, function (err, data) {
if (err) throw err
if (err) throw err;
console.log("Read " + data.length + " bytes from filesystem.");

client.set(filename, data, redis.print); // set entire file
client.get(filename, function (err, reply) { // get entire file
if (err) {
console.log("Get error: " + err);
} else {
fs.writeFile("duplicate_" + filename, reply, function (err) {
if (err) {
console.log("Error on write: " + err)
console.log("Error on write: " + err);
} else {
console.log("File written.");
}
Expand Down
2 changes: 2 additions & 0 deletions examples/mget.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

client.mget(["sessions started", "sessions started", "foo"], function (err, res) {
Expand Down
2 changes: 2 additions & 0 deletions examples/monitor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

Expand Down
2 changes: 2 additions & 0 deletions examples/multi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

Expand Down
2 changes: 2 additions & 0 deletions examples/multi2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

Expand Down
2 changes: 2 additions & 0 deletions examples/psubscribe.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var redis = require("redis"),
client1 = redis.createClient(),
client2 = redis.createClient(),
Expand Down
2 changes: 2 additions & 0 deletions examples/pub_sub.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var redis = require("redis"),
client1 = redis.createClient(), msg_count = 0,
client2 = redis.createClient();
Expand Down
2 changes: 2 additions & 0 deletions examples/scan.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

Expand Down
2 changes: 2 additions & 0 deletions examples/simple.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

Expand Down
2 changes: 2 additions & 0 deletions examples/sort.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

Expand Down
2 changes: 2 additions & 0 deletions examples/subqueries.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

// Sending commands in response to other commands.
// This example runs "type" against every key in the database
//
Expand Down
4 changes: 3 additions & 1 deletion examples/subquery.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

function print_results(obj) {
Expand All @@ -7,7 +9,7 @@ function print_results(obj) {
// build a map of all keys and their types
client.keys("*", function (err, all_keys) {
var key_types = {};

all_keys.forEach(function (key, pos) { // use second arg of forEach to get pos
client.type(key, function (err, type) {
key_types[key] = type;
Expand Down
4 changes: 3 additions & 1 deletion examples/unix_socket.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict';

var redis = require("redis"),
client = redis.createClient("/tmp/redis.sock"),
profiler = require("v8-profiler");

client.on("connect", function () {
console.log("Got Unix socket connection.")
console.log("Got Unix socket connection.");
});

client.on("error", function (err) {
Expand Down
6 changes: 4 additions & 2 deletions examples/web_server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

// A simple web server that generates dyanmic content based on responses from Redis

var http = require("http"), server,
Expand All @@ -7,9 +9,9 @@ server = http.createServer(function (request, response) {
response.writeHead(200, {
"Content-Type": "text/plain"
});

var redis_info, total_requests;

redis_client.info(function (err, reply) {
redis_info = reply; // stash response in outer scope
});
Expand Down
2 changes: 2 additions & 0 deletions generate_commands.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var http = require("http"),
fs = require("fs");

Expand Down
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/*global Buffer require exports console setTimeout */

var net = require("net"),
Expand All @@ -15,10 +17,10 @@ var net = require("net"),
// can set this to true to enable for all connections
exports.debug_mode = false;

var arraySlice = Array.prototype.slice
var arraySlice = Array.prototype.slice;
function trace() {
if (!exports.debug_mode) return;
console.log.apply(null, arraySlice.call(arguments))
console.log.apply(null, arraySlice.call(arguments));
}

// hiredis might not be installed
Expand Down Expand Up @@ -139,7 +141,7 @@ RedisClient.prototype.unref = function () {
trace("Not connected yet, will unref later");
this.once("connect", function () {
this.unref();
})
});
}
};

Expand Down Expand Up @@ -217,7 +219,7 @@ RedisClient.prototype.do_auth = function () {
}, 2000); // TODO - magic number alert
return;
} else if (err.toString().match("no password is set")) {
console.log("Warning: Redis server does not require a password, but a password was supplied.")
console.log("Warning: Redis server does not require a password, but a password was supplied.");
err = null;
res = "OK";
} else {
Expand Down Expand Up @@ -1263,7 +1265,7 @@ var createClient_unix = function(path, options){
redis_client.address = path;

return redis_client;
}
};

var createClient_tcp = function (port_arg, host_arg, options) {
var cnxOptions = {
Expand Down
2 changes: 2 additions & 0 deletions lib/commands.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

// This file was generated by ./generate_commands.js on Wed Apr 23 2014 14:51:21 GMT-0700 (PDT)
module.exports = [
"append",
Expand Down
2 changes: 2 additions & 0 deletions lib/parser/hiredis.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var events = require("events"),
util = require("../util"),
hiredis = require("hiredis");
Expand Down
2 changes: 2 additions & 0 deletions lib/parser/javascript.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

var events = require("events"),
util = require("../util");

Expand Down
2 changes: 2 additions & 0 deletions lib/queue.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

// Queue class adapted from Tim Caswell's pattern library
// http://github.com/creationix/pattern/blob/master/lib/pattern/queue.js

Expand Down
2 changes: 2 additions & 0 deletions lib/to_array.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

function to_array(args) {
var len = args.length,
arr = new Array(len), i;
Expand Down
2 changes: 2 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

// Support for very old versions of node where the module was called "sys". At some point, we should abandon this.

var util;
Expand Down
Loading

0 comments on commit 6cae0b8

Please sign in to comment.