1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Only run detect_buffers tests once

This commit is contained in:
Ruben Bridgewater
2016-05-27 16:35:09 +02:00
parent 8008fb5eb4
commit a90b791295

View File

@@ -7,265 +7,260 @@ var redis = config.redis;
describe('detect_buffers', function () { describe('detect_buffers', function () {
helper.allTests(function (parser, ip, args) { var client;
var args = config.configureClient('javascript', 'localhost', {
detect_buffers: true
});
describe('using ' + parser + ' and ' + ip, function () { beforeEach(function (done) {
var client; client = redis.createClient.apply(null, args);
var args = config.configureClient(parser, ip, { client.once('error', done);
detect_buffers: true client.once('connect', function () {
client.flushdb(function (err) {
client.hmset('hash key 2', 'key 1', 'val 1', 'key 2', 'val 2');
client.set('string key 1', 'string value');
return done(err);
});
});
});
afterEach(function () {
client.end(true);
});
describe('get', function () {
describe('first argument is a string', function () {
it('returns a string', function (done) {
client.get('string key 1', helper.isString('string value', done));
}); });
beforeEach(function (done) { it('returns a string when executed as part of transaction', function (done) {
client = redis.createClient.apply(null, args); client.multi().get('string key 1').exec(function (err, res) {
client.once('error', done); helper.isString('string value', done)(err, res[0]);
client.once('connect', function () { });
client.flushdb(function (err) { });
client.hmset('hash key 2', 'key 1', 'val 1', 'key 2', 'val 2'); });
client.set('string key 1', 'string value');
return done(err); describe('first argument is a buffer', function () {
}); it('returns a buffer', function (done) {
client.get(new Buffer('string key 1'), function (err, reply) {
assert.strictEqual(true, Buffer.isBuffer(reply));
assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply.inspect());
return done(err);
}); });
}); });
afterEach(function () { it('returns a bufffer when executed as part of transaction', function (done) {
client.end(true); client.multi().get(new Buffer('string key 1')).exec(function (err, reply) {
}); assert.strictEqual(1, reply.length);
assert.strictEqual(true, Buffer.isBuffer(reply[0]));
describe('get', function () { assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply[0].inspect());
describe('first argument is a string', function () { return done(err);
it('returns a string', function (done) {
client.get('string key 1', helper.isString('string value', done));
});
it('returns a string when executed as part of transaction', function (done) {
client.multi().get('string key 1').exec(function (err, res) {
helper.isString('string value', done)(err, res[0]);
});
});
}); });
});
});
});
describe('first argument is a buffer', function () { describe('multi.hget', function () {
it('returns a buffer', function (done) { it('can interleave string and buffer results', function (done) {
client.get(new Buffer('string key 1'), function (err, reply) { client.multi()
assert.strictEqual(true, Buffer.isBuffer(reply)); .hget('hash key 2', 'key 1')
assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply.inspect()); .hget(new Buffer('hash key 2'), 'key 1')
return done(err); .hget('hash key 2', new Buffer('key 2'))
}); .hget('hash key 2', 'key 2')
}); .exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(4, reply.length);
assert.strictEqual('val 1', reply[0]);
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[1].inspect());
assert.strictEqual(true, Buffer.isBuffer(reply[2]));
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[2].inspect());
assert.strictEqual('val 2', reply[3]);
return done(err);
});
});
});
it('returns a bufffer when executed as part of transaction', function (done) { describe('batch.hget', function () {
client.multi().get(new Buffer('string key 1')).exec(function (err, reply) { it('can interleave string and buffer results', function (done) {
assert.strictEqual(1, reply.length); client.batch()
assert.strictEqual(true, Buffer.isBuffer(reply[0])); .hget('hash key 2', 'key 1')
assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply[0].inspect()); .hget(new Buffer('hash key 2'), 'key 1')
return done(err); .hget('hash key 2', new Buffer('key 2'))
}); .hget('hash key 2', 'key 2')
}); .exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(4, reply.length);
assert.strictEqual('val 1', reply[0]);
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[1].inspect());
assert.strictEqual(true, Buffer.isBuffer(reply[2]));
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[2].inspect());
assert.strictEqual('val 2', reply[3]);
return done(err);
});
});
});
describe('hmget', function () {
describe('first argument is a string', function () {
it('returns strings for keys requested', function (done) {
client.hmget('hash key 2', 'key 1', 'key 2', function (err, reply) {
assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(2, reply.length);
assert.strictEqual('val 1', reply[0]);
assert.strictEqual('val 2', reply[1]);
return done(err);
}); });
}); });
describe('multi.hget', function () { it('returns strings for keys requested in transaction', function (done) {
it('can interleave string and buffer results', function (done) { client.multi().hmget('hash key 2', 'key 1', 'key 2').exec(function (err, reply) {
client.multi() assert.strictEqual(true, Array.isArray(reply));
.hget('hash key 2', 'key 1') assert.strictEqual(1, reply.length);
.hget(new Buffer('hash key 2'), 'key 1') assert.strictEqual(2, reply[0].length);
.hget('hash key 2', new Buffer('key 2')) assert.strictEqual('val 1', reply[0][0]);
.hget('hash key 2', 'key 2') assert.strictEqual('val 2', reply[0][1]);
.exec(function (err, reply) { return done(err);
assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(4, reply.length);
assert.strictEqual('val 1', reply[0]);
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[1].inspect());
assert.strictEqual(true, Buffer.isBuffer(reply[2]));
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[2].inspect());
assert.strictEqual('val 2', reply[3]);
return done(err);
});
}); });
}); });
describe('batch.hget', function () { it('handles array of strings with undefined values (repro #344)', function (done) {
it('can interleave string and buffer results', function (done) { client.hmget('hash key 2', 'key 3', 'key 4', function (err, reply) {
client.batch() assert.strictEqual(true, Array.isArray(reply));
.hget('hash key 2', 'key 1') assert.strictEqual(2, reply.length);
.hget(new Buffer('hash key 2'), 'key 1') assert.equal(null, reply[0]);
.hget('hash key 2', new Buffer('key 2')) assert.equal(null, reply[1]);
.hget('hash key 2', 'key 2') return done(err);
.exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(4, reply.length);
assert.strictEqual('val 1', reply[0]);
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[1].inspect());
assert.strictEqual(true, Buffer.isBuffer(reply[2]));
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[2].inspect());
assert.strictEqual('val 2', reply[3]);
return done(err);
});
}); });
}); });
describe('hmget', function () { it('handles array of strings with undefined values in transaction (repro #344)', function (done) {
describe('first argument is a string', function () { client.multi().hmget('hash key 2', 'key 3', 'key 4').exec(function (err, reply) {
it('returns strings for keys requested', function (done) { assert.strictEqual(true, Array.isArray(reply));
client.hmget('hash key 2', 'key 1', 'key 2', function (err, reply) { assert.strictEqual(1, reply.length);
assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(2, reply[0].length);
assert.strictEqual(2, reply.length); assert.equal(null, reply[0][0]);
assert.strictEqual('val 1', reply[0]); assert.equal(null, reply[0][1]);
assert.strictEqual('val 2', reply[1]); return done(err);
return done(err);
});
});
it('returns strings for keys requested in transaction', function (done) {
client.multi().hmget('hash key 2', 'key 1', 'key 2').exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(1, reply.length);
assert.strictEqual(2, reply[0].length);
assert.strictEqual('val 1', reply[0][0]);
assert.strictEqual('val 2', reply[0][1]);
return done(err);
});
});
it('handles array of strings with undefined values (repro #344)', function (done) {
client.hmget('hash key 2', 'key 3', 'key 4', function (err, reply) {
assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(2, reply.length);
assert.equal(null, reply[0]);
assert.equal(null, reply[1]);
return done(err);
});
});
it('handles array of strings with undefined values in transaction (repro #344)', function (done) {
client.multi().hmget('hash key 2', 'key 3', 'key 4').exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(1, reply.length);
assert.strictEqual(2, reply[0].length);
assert.equal(null, reply[0][0]);
assert.equal(null, reply[0][1]);
return done(err);
});
});
}); });
});
});
describe('first argument is a buffer', function () { describe('first argument is a buffer', function () {
it('returns buffers for keys requested', function (done) { it('returns buffers for keys requested', function (done) {
client.hmget(new Buffer('hash key 2'), 'key 1', 'key 2', function (err, reply) { client.hmget(new Buffer('hash key 2'), 'key 1', 'key 2', function (err, reply) {
assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(2, reply.length); assert.strictEqual(2, reply.length);
assert.strictEqual(true, Buffer.isBuffer(reply[0])); assert.strictEqual(true, Buffer.isBuffer(reply[0]));
assert.strictEqual(true, Buffer.isBuffer(reply[1])); assert.strictEqual(true, Buffer.isBuffer(reply[1]));
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0].inspect()); assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0].inspect());
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[1].inspect()); assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[1].inspect());
return done(err); return done(err);
});
});
it('returns buffers for keys requested in transaction', function (done) {
client.multi().hmget(new Buffer('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(1, reply.length);
assert.strictEqual(2, reply[0].length);
assert.strictEqual(true, Buffer.isBuffer(reply[0][0]));
assert.strictEqual(true, Buffer.isBuffer(reply[0][1]));
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0][0].inspect());
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0][1].inspect());
return done(err);
});
});
it('returns buffers for keys requested in .batch', function (done) {
client.batch().hmget(new Buffer('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(1, reply.length);
assert.strictEqual(2, reply[0].length);
assert.strictEqual(true, Buffer.isBuffer(reply[0][0]));
assert.strictEqual(true, Buffer.isBuffer(reply[0][1]));
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0][0].inspect());
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0][1].inspect());
return done(err);
});
});
}); });
}); });
describe('hgetall', function (done) { it('returns buffers for keys requested in transaction', function (done) {
describe('first argument is a string', function () { client.multi().hmget(new Buffer('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
it('returns string values', function (done) { assert.strictEqual(true, Array.isArray(reply));
client.hgetall('hash key 2', function (err, reply) { assert.strictEqual(1, reply.length);
assert.strictEqual('object', typeof reply); assert.strictEqual(2, reply[0].length);
assert.strictEqual(2, Object.keys(reply).length); assert.strictEqual(true, Buffer.isBuffer(reply[0][0]));
assert.strictEqual('val 1', reply['key 1']); assert.strictEqual(true, Buffer.isBuffer(reply[0][1]));
assert.strictEqual('val 2', reply['key 2']); assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0][0].inspect());
return done(err); assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0][1].inspect());
}); return done(err);
});
it('returns string values when executed in transaction', function (done) {
client.multi().hgetall('hash key 2').exec(function (err, reply) {
assert.strictEqual(1, reply.length);
assert.strictEqual('object', typeof reply[0]);
assert.strictEqual(2, Object.keys(reply[0]).length);
assert.strictEqual('val 1', reply[0]['key 1']);
assert.strictEqual('val 2', reply[0]['key 2']);
return done(err);
});
});
it('returns string values when executed in .batch', function (done) {
client.batch().hgetall('hash key 2').exec(function (err, reply) {
assert.strictEqual(1, reply.length);
assert.strictEqual('object', typeof reply[0]);
assert.strictEqual(2, Object.keys(reply[0]).length);
assert.strictEqual('val 1', reply[0]['key 1']);
assert.strictEqual('val 2', reply[0]['key 2']);
return done(err);
});
});
}); });
});
describe('first argument is a buffer', function () { it('returns buffers for keys requested in .batch', function (done) {
it('returns buffer values', function (done) { client.batch().hmget(new Buffer('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
client.hgetall(new Buffer('hash key 2'), function (err, reply) { assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(null, err); assert.strictEqual(1, reply.length);
assert.strictEqual('object', typeof reply); assert.strictEqual(2, reply[0].length);
assert.strictEqual(2, Object.keys(reply).length); assert.strictEqual(true, Buffer.isBuffer(reply[0][0]));
assert.strictEqual(true, Buffer.isBuffer(reply['key 1'])); assert.strictEqual(true, Buffer.isBuffer(reply[0][1]));
assert.strictEqual(true, Buffer.isBuffer(reply['key 2'])); assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0][0].inspect());
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply['key 1'].inspect()); assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0][1].inspect());
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply['key 2'].inspect()); return done(err);
return done(err); });
}); });
}); });
});
it('returns buffer values when executed in transaction', function (done) { describe('hgetall', function (done) {
client.multi().hgetall(new Buffer('hash key 2')).exec(function (err, reply) { describe('first argument is a string', function () {
assert.strictEqual(1, reply.length); it('returns string values', function (done) {
assert.strictEqual('object', typeof reply[0]); client.hgetall('hash key 2', function (err, reply) {
assert.strictEqual(2, Object.keys(reply[0]).length); assert.strictEqual('object', typeof reply);
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 1'])); assert.strictEqual(2, Object.keys(reply).length);
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 2'])); assert.strictEqual('val 1', reply['key 1']);
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0]['key 1'].inspect()); assert.strictEqual('val 2', reply['key 2']);
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0]['key 2'].inspect()); return done(err);
return done(err); });
}); });
});
it('returns buffer values when executed in .batch', function (done) { it('returns string values when executed in transaction', function (done) {
client.batch().hgetall(new Buffer('hash key 2')).exec(function (err, reply) { client.multi().hgetall('hash key 2').exec(function (err, reply) {
assert.strictEqual(1, reply.length); assert.strictEqual(1, reply.length);
assert.strictEqual('object', typeof reply[0]); assert.strictEqual('object', typeof reply[0]);
assert.strictEqual(2, Object.keys(reply[0]).length); assert.strictEqual(2, Object.keys(reply[0]).length);
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 1'])); assert.strictEqual('val 1', reply[0]['key 1']);
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 2'])); assert.strictEqual('val 2', reply[0]['key 2']);
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0]['key 1'].inspect()); return done(err);
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0]['key 2'].inspect()); });
return done(err); });
});
}); it('returns string values when executed in .batch', function (done) {
client.batch().hgetall('hash key 2').exec(function (err, reply) {
assert.strictEqual(1, reply.length);
assert.strictEqual('object', typeof reply[0]);
assert.strictEqual(2, Object.keys(reply[0]).length);
assert.strictEqual('val 1', reply[0]['key 1']);
assert.strictEqual('val 2', reply[0]['key 2']);
return done(err);
});
});
});
describe('first argument is a buffer', function () {
it('returns buffer values', function (done) {
client.hgetall(new Buffer('hash key 2'), function (err, reply) {
assert.strictEqual(null, err);
assert.strictEqual('object', typeof reply);
assert.strictEqual(2, Object.keys(reply).length);
assert.strictEqual(true, Buffer.isBuffer(reply['key 1']));
assert.strictEqual(true, Buffer.isBuffer(reply['key 2']));
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply['key 1'].inspect());
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply['key 2'].inspect());
return done(err);
});
});
it('returns buffer values when executed in transaction', function (done) {
client.multi().hgetall(new Buffer('hash key 2')).exec(function (err, reply) {
assert.strictEqual(1, reply.length);
assert.strictEqual('object', typeof reply[0]);
assert.strictEqual(2, Object.keys(reply[0]).length);
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 1']));
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 2']));
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0]['key 1'].inspect());
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0]['key 2'].inspect());
return done(err);
});
});
it('returns buffer values when executed in .batch', function (done) {
client.batch().hgetall(new Buffer('hash key 2')).exec(function (err, reply) {
assert.strictEqual(1, reply.length);
assert.strictEqual('object', typeof reply[0]);
assert.strictEqual(2, Object.keys(reply[0]).length);
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 1']));
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 2']));
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0]['key 1'].inspect());
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0]['key 2'].inspect());
return done(err);
}); });
}); });
}); });