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

tweaks based on running test-suite on Windows on an older Redis

This commit is contained in:
Benjamin Coe
2015-09-12 17:53:49 -07:00
parent b4da975785
commit a0bf9e2314
11 changed files with 82 additions and 80 deletions

View File

@@ -17,12 +17,7 @@ describe("The 'client' method", function () {
client = redis.createClient.apply(redis.createClient, args);
client.once("error", done);
client.once("connect", function () {
client.flushdb(function (err) {
if (!helper.serverVersionAtLeast(client, [2, 4, 0])) {
err = Error('script not supported in redis <= 2.4.0');
}
return done(err);
});
client.flushdb(done)
});
});

View File

@@ -17,12 +17,7 @@ describe("The 'eval' method", function () {
client = redis.createClient.apply(redis.createClient, args);
client.once("error", done);
client.once("connect", function () {
client.flushdb(function (err) {
if (!helper.serverVersionAtLeast(client, [2, 5, 0])) {
err = Error('exec not supported in redis <= 2.5.0');
}
return done(err);
});
client.flushdb(done)
});
});
@@ -31,30 +26,37 @@ describe("The 'eval' method", function () {
});
it('converts a float to an integer when evaluated', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.eval("return 100.5", 0, helper.isNumber(100, done));
});
it('returns a string', function (done) {
client.EVAL("return 'hello world'", 0, helper.isString('hello world', done));
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.eval("return 'hello world'", 0, helper.isString('hello world', done));
});
it('converts boolean true to integer 1', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.eval("return true", 0, helper.isNumber(1, done));
});
it('converts boolean false to null', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.eval("return false", 0, helper.isNull(done));
});
it('converts lua status code to string representation', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.eval("return {ok='fine'}", 0, helper.isString('fine', done));
});
it('converts lua error to an error response', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.eval("return {err='this is an error'}", 0, helper.isError(done));
});
it('represents a lua table appropritely', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.eval("return {1,2,3,'ciao',{1,2}}", 0, function (err, res) {
assert.strictEqual(5, res.length);
assert.strictEqual(1, res[0]);
@@ -69,25 +71,27 @@ describe("The 'eval' method", function () {
});
it('populates keys and argv correctly', function (done) {
client.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d", function (err, res) {
assert.strictEqual(4, res.length);
assert.strictEqual("a", res[0]);
assert.strictEqual("b", res[1]);
assert.strictEqual("c", res[2]);
assert.strictEqual("d", res[3]);
return done();
});
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d", function (err, res) {
assert.strictEqual(4, res.length);
assert.strictEqual("a", res[0]);
assert.strictEqual("b", res[1]);
assert.strictEqual("c", res[2]);
assert.strictEqual("d", res[3]);
return done();
});
});
it('allows arguments to be provided in array rather than as multiple parameters', function (done) {
client.eval(["return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d"], function (err, res) {
assert.strictEqual(4, res.length);
assert.strictEqual("a", res[0]);
assert.strictEqual("b", res[1]);
assert.strictEqual("c", res[2]);
assert.strictEqual("d", res[3]);
return done();
});
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.eval(["return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d"], function (err, res) {
assert.strictEqual(4, res.length);
assert.strictEqual("a", res[0]);
assert.strictEqual("b", res[1]);
assert.strictEqual("c", res[2]);
assert.strictEqual("d", res[3]);
return done();
});
});
describe('evalsha', function () {
@@ -101,19 +105,23 @@ describe("The 'eval' method", function () {
});
it('allows a script to be executed that accesses the redis API', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.eval(source, 0, helper.isString('eval get sha test', done));
});
it('can execute a script if the SHA exists', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.evalsha(sha, 0, helper.isString('eval get sha test', done));
});
it('throws an error if SHA does not exist', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0, helper.isError(done));
});
});
it('allows a key to be incremented, and performs appropriate conversion from LUA type', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.set("incr key", 0, function (err, reply) {
if (err) return done(err);
client.eval("local foo = redis.call('incr','incr key')\n" + "return {type(foo),foo}", 0, function (err, res) {
@@ -126,6 +134,7 @@ describe("The 'eval' method", function () {
});
it('allows a bulk operation to be performed, and performs appropriate conversion from LUA type', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.set("bulk reply key", "bulk reply value", function (err, res) {
client.eval("local foo = redis.call('get','bulk reply key'); return {type(foo),foo}", 0, function (err, res) {
assert.strictEqual(2, res.length);
@@ -137,6 +146,7 @@ describe("The 'eval' method", function () {
});
it('allows a multi mulk operation to be performed, with the appropriate type conversion', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.multi()
.del("mylist")
.rpush("mylist", "a")
@@ -157,6 +167,7 @@ describe("The 'eval' method", function () {
});
it('returns an appropriate representation of Lua status reply', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.eval("local foo = redis.call('set','mykey','myval'); return {type(foo),foo['ok']}", 0, function (err, res) {
assert.strictEqual(2, res.length);
assert.strictEqual("table", res[0]);
@@ -166,6 +177,7 @@ describe("The 'eval' method", function () {
});
it('returns an appropriate representation of a Lua error reply', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.set("error reply key", "error reply value", function (err, res) {
if (err) return done(err);
client.eval("local foo = redis.pcall('incr','error reply key'); return {type(foo),foo['err']}", 0, function (err, res) {
@@ -178,6 +190,7 @@ describe("The 'eval' method", function () {
});
it('returns an appropriate representation of a Lua nil reply', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
client.del("nil reply key", function (err, res) {
if (err) return done(err);
client.eval("local foo = redis.call('get','nil reply key'); return {type(foo),foo == false}", 0, function (err, res) {

View File

@@ -24,7 +24,7 @@ describe("The 'expire' method", function () {
client.EXPIRE(["expiry key", "1"], helper.isNumber(1));
setTimeout(function () {
client.exists(["expiry key"], helper.isNumber(0, done));
}, 1100);
}, 2000);
});
afterEach(function () {

View File

@@ -64,9 +64,9 @@ describe("The 'multi' method", function () {
// Provoke an error at queue time
multi1 = client.MULTI();
multi1.mset("multifoo", "10", "multibar", "20", helper.isString("OK"));
multi1.set("foo2", helper.isError());
multi1.incr("multifoo", helper.isNumber(11));
multi1.incr("multibar", helper.isNumber(21));
multi1.set("foo2");
multi1.incr("multifoo");
multi1.incr("multibar");
multi1.exec(function () {
// Redis 2.6.5+ will abort transactions with errors
// see: http://redis.io/topics/transactions
@@ -89,6 +89,7 @@ describe("The 'multi' method", function () {
});
});
<<<<<<< HEAD
// I'm unclear as to the difference between this test in the test above,
// perhaps @mranney can clarify?
it('roles back a transaction when an error was provoked at queue time', function (done) {
@@ -137,8 +138,8 @@ describe("The 'multi' method", function () {
assert.equal(replies, undefined);
} else {
assert.strictEqual(2, replies[0].length);
assert.strictEqual("0", replies[0][0].toString());
assert.strictEqual("0", replies[0][1].toString());
assert.strictEqual(null, replies[0][0]);
assert.strictEqual(null, replies[0][1]);
assert.strictEqual("1", replies[1].toString());
assert.strictEqual("1", replies[2].toString());
@@ -226,7 +227,7 @@ describe("The 'multi' method", function () {
});
it('reports multiple exceptions when they occur', function (done) {
if (!helper.serverVersionAtLeast(client, [2, 6, 5])) return done();
helper.serverVersionAtLeast.bind(this)(client, [2, 6, 5])
client.multi().set("foo").exec(function (err, reply) {
assert(Array.isArray(err), "err should be an array");

View File

@@ -19,12 +19,7 @@ describe("The 'script' method", function () {
client = redis.createClient.apply(redis.createClient, args);
client.once("error", done);
client.once("connect", function () {
client.flushdb(function (err) {
if (!helper.serverVersionAtLeast(client, [2, 6, 0])) {
err = Error('script not supported in redis <= 2.6.0');
}
return done(err);
});
client.flushdb(done);
});
});
@@ -33,17 +28,20 @@ describe("The 'script' method", function () {
});
it("loads script with client.script('load')", function (done) {
client.SCRIPT("load", command, function(err, result) {
helper.serverVersionAtLeast.bind(this)(client, [2, 6, 0]);
client.script("load", command, function(err, result) {
assert.strictEqual(result, commandSha);
return done();
});
});
it('allows a loaded script to be evaluated', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 6, 0]);
client.evalsha(commandSha, 0, helper.isString('99', done));
});
it('allows a script to be loaded as part of a chained transaction', function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 6, 0]);
client.multi().script("load", command).exec(function(err, result) {
assert.strictEqual(result[0], commandSha);
return done();
@@ -51,6 +49,7 @@ describe("The 'script' method", function () {
});
it("allows a script to be loaded using a transaction's array syntax", function (done) {
helper.serverVersionAtLeast.bind(this)(client, [2, 6, 0]);
client.multi([['script', 'load', command]]).exec(function(err, result) {
assert.strictEqual(result[0], commandSha);
return done();

View File

@@ -18,12 +18,7 @@ describe("The 'watch' method", function () {
client = redis.createClient.apply(redis.createClient, args);
client.once("error", done);
client.once("connect", function () {
client.flushdb(function (err) {
if (!helper.serverVersionAtLeast(client, [2, 2, 0])) {
err = Error('some watch commands not supported in redis <= 2.2.0');
}
return done(err);
});
client.flushdb(done);
});
});