You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
Add .batch with better pipeline implementation
This commit is contained in:
@@ -79,6 +79,27 @@ describe("detect_buffers", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('batch.hget', function () {
|
||||
it('can interleave string and buffer results', function (done) {
|
||||
client.batch()
|
||||
.hget("hash key 2", "key 1")
|
||||
.hget(new Buffer("hash key 2"), "key 1")
|
||||
.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) {
|
||||
@@ -149,6 +170,19 @@ describe("detect_buffers", function () {
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -174,6 +208,17 @@ describe("detect_buffers", function () {
|
||||
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 () {
|
||||
@@ -193,7 +238,20 @@ describe("detect_buffers", function () {
|
||||
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);
|
||||
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"]));
|
||||
|
Reference in New Issue
Block a user