You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
fixup underscore
This commit is contained in:
2
index.js
2
index.js
@@ -170,7 +170,7 @@ RedisClient.prototype.createStream = function () {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Init parser
|
// Init parser
|
||||||
this.reply_parser = create_parser(this);
|
this.replyParser = createParser(this);
|
||||||
|
|
||||||
if (this.options.stream) {
|
if (this.options.stream) {
|
||||||
// Only add the listeners once in case of a reconnect try (that won't work)
|
// Only add the listeners once in case of a reconnect try (that won't work)
|
||||||
|
@@ -98,7 +98,7 @@ module.exports = {
|
|||||||
replyToStrings: replyToStrings,
|
replyToStrings: replyToStrings,
|
||||||
replyToObject: replyToObject,
|
replyToObject: replyToObject,
|
||||||
errCode: /^([A-Z]+)\s+(.+)$/,
|
errCode: /^([A-Z]+)\s+(.+)$/,
|
||||||
monitor_regex: /^[0-9]{10,11}\.[0-9]+ \[[0-9]+ .+\]( ".+?")+$/,
|
monitorRegex: /^[0-9]{10,11}\.[0-9]+ \[[0-9]+ .+\]( ".+?")+$/,
|
||||||
clone: convenienceClone,
|
clone: convenienceClone,
|
||||||
callbackOrEmit: callbackOrEmit,
|
callbackOrEmit: callbackOrEmit,
|
||||||
replyInOrder: replyInOrder
|
replyInOrder: replyInOrder
|
||||||
|
@@ -72,19 +72,19 @@ describe("The 'monitor' method", function () {
|
|||||||
monitorClient.on('monitor', function (time, args, rawOutput) {
|
monitorClient.on('monitor', function (time, args, rawOutput) {
|
||||||
assert.strictEqual(monitorClient.monitoring, true);
|
assert.strictEqual(monitorClient.monitoring, true);
|
||||||
assert.deepEqual(args, responses.shift());
|
assert.deepEqual(args, responses.shift());
|
||||||
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
||||||
if (responses.length === 0) {
|
if (responses.length === 0) {
|
||||||
monitorClient.quit(end);
|
monitorClient.quit(end);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('monitors returns strings in the rawOutput even with return_buffers activated', function (done) {
|
it('monitors returns strings in the rawOutput even with returnBuffers activated', function (done) {
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
this.skip();
|
this.skip();
|
||||||
}
|
}
|
||||||
var monitorClient = redis.createClient({
|
var monitorClient = redis.createClient({
|
||||||
return_buffers: true,
|
returnBuffers: true,
|
||||||
path: '/tmp/redis.sock'
|
path: '/tmp/redis.sock'
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ describe("The 'monitor' method", function () {
|
|||||||
|
|
||||||
monitorClient.on('monitor', function (time, args, rawOutput) {
|
monitorClient.on('monitor', function (time, args, rawOutput) {
|
||||||
assert.strictEqual(typeof rawOutput, 'string');
|
assert.strictEqual(typeof rawOutput, 'string');
|
||||||
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
||||||
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
||||||
// Quit immediatly ends monitoring mode and therefore does not stream back the quit command
|
// Quit immediatly ends monitoring mode and therefore does not stream back the quit command
|
||||||
monitorClient.quit(done);
|
monitorClient.quit(done);
|
||||||
@@ -109,7 +109,7 @@ describe("The 'monitor' method", function () {
|
|||||||
client.mget('hello', 'world');
|
client.mget('hello', 'world');
|
||||||
client.on('monitor', function (time, args, rawOutput) {
|
client.on('monitor', function (time, args, rawOutput) {
|
||||||
assert.strictEqual(client.monitoring, true);
|
assert.strictEqual(client.monitoring, true);
|
||||||
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
||||||
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
||||||
if (called) {
|
if (called) {
|
||||||
// End after a reconnect
|
// End after a reconnect
|
||||||
@@ -131,7 +131,7 @@ describe("The 'monitor' method", function () {
|
|||||||
});
|
});
|
||||||
client.on('monitor', function (time, args, rawOutput) {
|
client.on('monitor', function (time, args, rawOutput) {
|
||||||
assert.strictEqual(client.monitoring, true);
|
assert.strictEqual(client.monitoring, true);
|
||||||
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
||||||
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
||||||
if (called) {
|
if (called) {
|
||||||
// End after a reconnect
|
// End after a reconnect
|
||||||
@@ -193,7 +193,7 @@ describe("The 'monitor' method", function () {
|
|||||||
var called = false;
|
var called = false;
|
||||||
client.on('monitor', function (time, args, rawOutput) {
|
client.on('monitor', function (time, args, rawOutput) {
|
||||||
assert.deepEqual(args, responses.shift());
|
assert.deepEqual(args, responses.shift());
|
||||||
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
||||||
if (responses.length === 0) {
|
if (responses.length === 0) {
|
||||||
// The publish is called right after the reconnect and the monitor is called before the message is emitted.
|
// The publish is called right after the reconnect and the monitor is called before the message is emitted.
|
||||||
// Therefore we have to wait till the next tick
|
// Therefore we have to wait till the next tick
|
||||||
|
@@ -669,186 +669,6 @@ describe('The nodeRedis client', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('monitor', function () {
|
|
||||||
it('monitors commands on all redis clients and works in the correct order', function (done) {
|
|
||||||
var monitorClient = redis.createClient.apply(null, args);
|
|
||||||
var responses = [];
|
|
||||||
var end = helper.callFuncAfter(done, 5);
|
|
||||||
|
|
||||||
monitorClient.set('foo', 'bar');
|
|
||||||
monitorClient.flushdb();
|
|
||||||
monitorClient.monitor(function (err, res) {
|
|
||||||
assert.strictEqual(res, 'OK');
|
|
||||||
client.mget('some', 'keys', 'foo', 'bar');
|
|
||||||
client.set('json', JSON.stringify({
|
|
||||||
foo: '123',
|
|
||||||
bar: 'sdflkdfsjk',
|
|
||||||
another: false
|
|
||||||
}));
|
|
||||||
monitorClient.get('baz', function (err, res) {
|
|
||||||
assert.strictEqual(res, null);
|
|
||||||
end(err);
|
|
||||||
});
|
|
||||||
monitorClient.set('foo', 'bar" "s are " " good!"', function (err, res) {
|
|
||||||
assert.strictEqual(res, 'OK');
|
|
||||||
end(err);
|
|
||||||
});
|
|
||||||
monitorClient.mget('foo', 'baz', function (err, res) {
|
|
||||||
assert.strictEqual(res[0], 'bar" "s are " " good!"');
|
|
||||||
assert.strictEqual(res[1], null);
|
|
||||||
end(err);
|
|
||||||
});
|
|
||||||
monitorClient.subscribe('foo', 'baz', function (err, res) {
|
|
||||||
// The return value might change in v.3
|
|
||||||
// assert.strictEqual(res, 'baz');
|
|
||||||
// TODO: Fix the return value of subscribe calls
|
|
||||||
end(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
monitorClient.on('monitor', function (time, args, rawOutput) {
|
|
||||||
assert.strictEqual(monitorClient.monitoring, true);
|
|
||||||
responses.push(args);
|
|
||||||
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
|
||||||
if (responses.length === 6) {
|
|
||||||
assert.deepEqual(responses[0], ['mget', 'some', 'keys', 'foo', 'bar']);
|
|
||||||
assert.deepEqual(responses[1], ['set', 'json', '{"foo":"123","bar":"sdflkdfsjk","another":false}']);
|
|
||||||
assert.deepEqual(responses[2], ['get', 'baz']);
|
|
||||||
assert.deepEqual(responses[3], ['set', 'foo', 'bar" "s are " " good!"']);
|
|
||||||
assert.deepEqual(responses[4], ['mget', 'foo', 'baz']);
|
|
||||||
assert.deepEqual(responses[5], ['subscribe', 'foo', 'baz']);
|
|
||||||
monitorClient.quit(end);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('monitors returns strings in the rawOutput even with returnBuffers activated', function (done) {
|
|
||||||
var monitorClient = redis.createClient({
|
|
||||||
returnBuffers: true
|
|
||||||
});
|
|
||||||
|
|
||||||
monitorClient.MONITOR(function (err, res) {
|
|
||||||
assert.strictEqual(monitorClient.monitoring, true);
|
|
||||||
assert.strictEqual(res.inspect(), new Buffer('OK').inspect());
|
|
||||||
client.mget('hello', new Buffer('world'));
|
|
||||||
});
|
|
||||||
|
|
||||||
monitorClient.on('monitor', function (time, args, rawOutput) {
|
|
||||||
assert.strictEqual(typeof rawOutput, 'string');
|
|
||||||
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
|
||||||
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
|
||||||
// Quit immediatly ends monitoring mode and therefore does not stream back the quit command
|
|
||||||
monitorClient.quit(done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('monitors reconnects properly and works with the offline queue', function (done) {
|
|
||||||
var i = 0;
|
|
||||||
client.MONITOR(helper.isString('OK'));
|
|
||||||
client.mget('hello', 'world');
|
|
||||||
client.on('monitor', function (time, args, rawOutput) {
|
|
||||||
assert.strictEqual(client.monitoring, true);
|
|
||||||
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
|
||||||
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
|
||||||
if (i++ === 2) {
|
|
||||||
// End after two reconnects
|
|
||||||
return done();
|
|
||||||
}
|
|
||||||
client.stream.destroy();
|
|
||||||
client.mget('hello', 'world');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('monitors reconnects properly and works with the offline queue in a batch statement', function (done) {
|
|
||||||
var i = 0;
|
|
||||||
var multi = client.batch();
|
|
||||||
multi.MONITOR(helper.isString('OK'));
|
|
||||||
multi.mget('hello', 'world');
|
|
||||||
multi.exec(function (err, res) {
|
|
||||||
assert.deepEqual(res, ['OK', [null, null]]);
|
|
||||||
});
|
|
||||||
client.on('monitor', function (time, args, rawOutput) {
|
|
||||||
assert.strictEqual(client.monitoring, true);
|
|
||||||
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
|
||||||
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
|
||||||
if (i++ === 2) {
|
|
||||||
// End after two reconnects
|
|
||||||
return done();
|
|
||||||
}
|
|
||||||
client.stream.destroy();
|
|
||||||
client.mget('hello', 'world');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('monitor activates even if the command could not be processed properly after a reconnect', function (done) {
|
|
||||||
client.MONITOR(function (err, res) {
|
|
||||||
assert.strictEqual(err.code, 'UNCERTAIN_STATE');
|
|
||||||
});
|
|
||||||
client.on('error', function (err) {}); // Ignore error here
|
|
||||||
client.stream.destroy();
|
|
||||||
var end = helper.callFuncAfter(done, 2);
|
|
||||||
client.on('monitor', function (time, args, rawOutput) {
|
|
||||||
assert.strictEqual(client.monitoring, true);
|
|
||||||
end();
|
|
||||||
});
|
|
||||||
client.on('reconnecting', function () {
|
|
||||||
client.get('foo', function (err, res) {
|
|
||||||
assert(!err);
|
|
||||||
assert.strictEqual(client.monitoring, true);
|
|
||||||
end();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('monitors works in combination with the pub sub mode and the offline queue', function (done) {
|
|
||||||
var responses = [];
|
|
||||||
var pub = redis.createClient();
|
|
||||||
pub.on('ready', function () {
|
|
||||||
client.MONITOR(function (err, res) {
|
|
||||||
assert.strictEqual(res, 'OK');
|
|
||||||
pub.get('foo', helper.isNull());
|
|
||||||
});
|
|
||||||
client.subscribe('/foo', '/bar');
|
|
||||||
client.unsubscribe('/bar');
|
|
||||||
setTimeout(function () {
|
|
||||||
client.stream.destroy();
|
|
||||||
client.once('ready', function () {
|
|
||||||
pub.publish('/foo', 'hello world');
|
|
||||||
});
|
|
||||||
client.set('foo', 'bar', helper.isError());
|
|
||||||
client.subscribe('baz');
|
|
||||||
client.unsubscribe('baz');
|
|
||||||
}, 150);
|
|
||||||
var called = false;
|
|
||||||
client.on('monitor', function (time, args, rawOutput) {
|
|
||||||
responses.push(args);
|
|
||||||
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
|
||||||
if (responses.length === 7) {
|
|
||||||
assert.deepEqual(responses[0], ['subscribe', '/foo', '/bar']);
|
|
||||||
assert.deepEqual(responses[1], ['unsubscribe', '/bar']);
|
|
||||||
assert.deepEqual(responses[2], ['get', 'foo']);
|
|
||||||
assert.deepEqual(responses[3], ['subscribe', '/foo']);
|
|
||||||
assert.deepEqual(responses[4], ['subscribe', 'baz']);
|
|
||||||
assert.deepEqual(responses[5], ['unsubscribe', 'baz']);
|
|
||||||
assert.deepEqual(responses[6], ['publish', '/foo', 'hello world']);
|
|
||||||
// The publish is called right after the reconnect and the monitor is called before the message is emitted.
|
|
||||||
// Therefore we have to wait till the next tick
|
|
||||||
process.nextTick(function () {
|
|
||||||
assert(called);
|
|
||||||
client.quit(done);
|
|
||||||
pub.end(false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
client.on('message', function (channel, msg) {
|
|
||||||
assert.strictEqual(channel, '/foo');
|
|
||||||
assert.strictEqual(msg, 'hello world');
|
|
||||||
called = true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('utf8', function () {
|
describe('utf8', function () {
|
||||||
it('handles utf-8 keys', function (done) {
|
it('handles utf-8 keys', function (done) {
|
||||||
var utf8Sample = 'ಠ_ಠ';
|
var utf8Sample = 'ಠ_ಠ';
|
||||||
|
Reference in New Issue
Block a user