Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
niteshsinha committed Feb 20, 2013
2 parents ac80cc1 + 0f5b43a commit 3cab8ec
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 24 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## v0.8.2 - November 11, 2012

Another version bump because 0.8.1 didn't get applied properly for some mysterious reason.
Sorry about that.

Changed name of "faster" parser to "javascript".

## v0.8.1 - September 11, 2012

Important bug fix for null responses (Jerry Sievert)
Expand Down
2 changes: 1 addition & 1 deletion examples/eval.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var redis = require("./index"),
var redis = require("../index"),
client = redis.createClient();

redis.debug_mode = true;
Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ RedisClient.prototype.connection_gone = function (why) {
this.retry_delay = Math.floor(this.retry_delay * this.retry_backoff);

if (exports.debug_mode) {
console.log("Retry connection in " + this.current_retry_delay + " ms");
console.log("Retry connection in " + this.retry_delay + " ms");
}

if (this.max_attempts && this.attempts >= this.max_attempts) {
Expand All @@ -453,7 +453,7 @@ RedisClient.prototype.connection_gone = function (why) {
console.log("Retrying connection...");
}

self.retry_totaltime += self.current_retry_delay;
self.retry_totaltime += self.retry_delay;

if (self.connect_timeout && self.retry_totaltime >= self.connect_timeout) {
self.retry_timer = null;
Expand Down Expand Up @@ -826,6 +826,7 @@ RedisClient.prototype.end = function () {
this.stream._events = {};
this.connected = false;
this.ready = false;
this.closing = true;
return this.stream.end();
};

Expand Down Expand Up @@ -883,9 +884,9 @@ commands.forEach(function (command) {

// store db in this.select_db to restore it on reconnect
RedisClient.prototype.select = function (db, callback) {
var self = this;
var self = this;

this.send_command('select', [db], function (err, res) {
this.send_command('select', [db], function (err, res) {
if (err === null) {
self.selected_db = db;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/commands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was generated by ./generate_commands.js on Mon Aug 06 2012 15:04:06 GMT-0700 (PDT)
// This file was generated by ./generate_commands.js on Sun Feb 17 2013 19:04:47 GMT-0500 (EST)
module.exports = [
"append",
"auth",
Expand All @@ -11,6 +11,8 @@ module.exports = [
"brpoplpush",
"client kill",
"client list",
"client getname",
"client setname",
"config get",
"config set",
"config resetstat",
Expand Down
14 changes: 9 additions & 5 deletions lib/parser/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Packet(type, size) {
this.size = +size;
}

exports.name = "faster";
exports.name = "javascript";
exports.debug_mode = false;

function ReplyParser(options) {
Expand Down Expand Up @@ -37,7 +37,7 @@ function small_toString(buf, start, end) {

ReplyParser.prototype._parseResult = function (type) {
var start, end, offset, packetHeader;

if (type === 43 || type === 45) { // + or -
// up to the delimiter
end = this._packetEndOffset() - 1;
Expand Down Expand Up @@ -73,6 +73,10 @@ ReplyParser.prototype._parseResult = function (type) {
throw new Error("too far");
}

if (this.options.return_buffers) {
return this._buffer.slice(start, end);
}

// return the coerced numeric value
return +small_toString(this._buffer, start, end);
} else if (type === 36) { // $
Expand Down Expand Up @@ -177,7 +181,7 @@ ReplyParser.prototype.execute = function (buffer) {
break;
}

this.send_reply(+ret);
this.send_reply(ret);
} else if (type === 36) { // $
ret = this._parseResult(type);

Expand All @@ -188,7 +192,7 @@ ReplyParser.prototype.execute = function (buffer) {
// check the state for what is the result of
// a -1, set it back up for a null reply
if (ret === undefined) {
ret = null;
ret = null;
}

this.send_reply(ret);
Expand Down Expand Up @@ -246,7 +250,7 @@ ReplyParser.prototype.append = function (newBuffer) {

this._buffer.copy(tmpBuffer, 0, this._offset);
newBuffer.copy(tmpBuffer, remaining, 0);

this._buffer = tmpBuffer;
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ "name" : "redis",
"version" : "0.8.1",
"description" : "Redis client library, battle-tested by Voxer",
"keywords" : [ "redis", "pub", "sub", "voxer", "database" ],
"version" : "0.8.2",
"description" : "Redis client library",
"keywords" : [ "redis", "database" ],
"author": "Matt Ranney <mjr@ranney.com>",
"main": "./index.js",
"scripts": {
Expand Down
44 changes: 34 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/*global require console setTimeout process Buffer */
var PORT = 6379;
var HOST = '127.0.0.1';

var redis = require("./index"),
client = redis.createClient(),
client2 = redis.createClient(),
client3 = redis.createClient(),
client = redis.createClient(PORT, HOST),
client2 = redis.createClient(PORT, HOST),
client3 = redis.createClient(PORT, HOST),
bclient = redis.createClient(PORT, HOST, { return_buffers: true }),
assert = require("assert"),
crypto = require("crypto"),
util = require("./lib/util"),
Expand Down Expand Up @@ -85,7 +89,7 @@ next = function next(name) {
run_next_test();
};

// Tests are run in the order they are defined. So FLUSHDB should be stay first.
// Tests are run in the order they are defined, so FLUSHDB should always be first.

tests.FLUSHDB = function () {
var name = "FLUSHDB";
Expand All @@ -97,6 +101,20 @@ tests.FLUSHDB = function () {
client.dbsize(last(name, require_number(0, name)));
};

tests.INCR = function () {
var name = "INCR";

// Test incr with the maximum JavaScript number value. Since we are
// returning buffers we should get back one more as a Buffer.
bclient.set("seq", "9007199254740992", function (err, result) {
assert.strictEqual(result.toString(), "OK");
bclient.incr("seq", function (err, result) {
assert.strictEqual("9007199254740993", result.toString());
next(name);
});
});
};

tests.MULTI_1 = function () {
var name = "MULTI_1", multi1, multi2;

Expand Down Expand Up @@ -976,16 +994,16 @@ tests.SADD2 = function () {
client.sadd("set0", ["member0", "member1", "member2"], require_number(3, name));
client.smembers("set0", function (err, res) {
assert.strictEqual(res.length, 3);
assert.strictEqual(res[0], "member0");
assert.strictEqual(res[1], "member1");
assert.strictEqual(res[2], "member2");
assert.ok(~res.indexOf("member0"));
assert.ok(~res.indexOf("member1"));
assert.ok(~res.indexOf("member2"));
});
client.SADD("set1", ["member0", "member1", "member2"], require_number(3, name));
client.smembers("set1", function (err, res) {
assert.strictEqual(res.length, 3);
assert.strictEqual(res[0], "member0");
assert.strictEqual(res[1], "member1");
assert.strictEqual(res[2], "member2");
assert.ok(~res.indexOf("member0"));
assert.ok(~res.indexOf("member1"));
assert.ok(~res.indexOf("member2"));
next(name);
});
};
Expand Down Expand Up @@ -1622,6 +1640,7 @@ run_next_test = function run_next_test() {
console.log('\n completed \x1b[32m%d\x1b[0m tests in \x1b[33m%d\x1b[0m ms\n', test_count, new Date() - all_start);
client.quit();
client2.quit();
bclient.quit();
}
};

Expand Down Expand Up @@ -1651,6 +1670,11 @@ client3.on("error", function (err) {
console.error("client3: " + err.stack);
process.exit();
});
bclient.on("error", function (err) {
console.error("bclient: " + err.stack);
process.exit();
});

client.on("reconnecting", function (params) {
console.log("reconnecting: " + util.inspect(params));
});
Expand Down

0 comments on commit 3cab8ec

Please sign in to comment.