You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
added windows badge, made changes based on @BrideAr's code-review
This commit is contained in:
@@ -3,6 +3,7 @@ redis - a node.js redis client
|
|||||||
|
|
||||||
[](https://travis-ci.org/NodeRedis/node_redis)
|
[](https://travis-ci.org/NodeRedis/node_redis)
|
||||||
[](https://coveralls.io/r/NodeRedis/node_redis?branch=)
|
[](https://coveralls.io/r/NodeRedis/node_redis?branch=)
|
||||||
|
[![Windows Tests][https://img.shields.io/appveyor/ci/bcoe/node-redis/master.svg?label=Windows%20Tests]][https://ci.appveyor.com/project/bcoe/node-redis]
|
||||||
|
|
||||||
This is a complete Redis client for node.js. It supports all Redis commands,
|
This is a complete Redis client for node.js. It supports all Redis commands,
|
||||||
including many recently added commands.
|
including many recently added commands.
|
||||||
|
@@ -10,7 +10,8 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
"coveralls": "nyc report --reporter=text-lcov | coveralls",
|
||||||
|
"coverage": "nyc report --reporter=html",
|
||||||
"test": "nyc ./node_modules/.bin/_mocha ./test/*.js ./test/commands/*.js ./test/parser/*.js --timeout=8000",
|
"test": "nyc ./node_modules/.bin/_mocha ./test/*.js ./test/commands/*.js ./test/parser/*.js --timeout=8000",
|
||||||
"pretest": "optional-dev-dependency hiredis",
|
"pretest": "optional-dev-dependency hiredis",
|
||||||
"posttest": "jshint ."
|
"posttest": "jshint ."
|
||||||
|
@@ -26,37 +26,37 @@ describe("The 'eval' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('converts a float to an integer when evaluated', function (done) {
|
it('converts a float to an integer when evaluated', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.eval("return 100.5", 0, helper.isNumber(100, done));
|
client.eval("return 100.5", 0, helper.isNumber(100, done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns a string', function (done) {
|
it('returns a string', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.eval("return 'hello world'", 0, helper.isString('hello world', done));
|
client.eval("return 'hello world'", 0, helper.isString('hello world', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('converts boolean true to integer 1', function (done) {
|
it('converts boolean true to integer 1', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.eval("return true", 0, helper.isNumber(1, done));
|
client.eval("return true", 0, helper.isNumber(1, done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('converts boolean false to null', function (done) {
|
it('converts boolean false to null', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.eval("return false", 0, helper.isNull(done));
|
client.eval("return false", 0, helper.isNull(done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('converts lua status code to string representation', function (done) {
|
it('converts lua status code to string representation', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.eval("return {ok='fine'}", 0, helper.isString('fine', done));
|
client.eval("return {ok='fine'}", 0, helper.isString('fine', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('converts lua error to an error response', function (done) {
|
it('converts lua error to an error response', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.eval("return {err='this is an error'}", 0, helper.isError(done));
|
client.eval("return {err='this is an error'}", 0, helper.isError(done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('represents a lua table appropritely', function (done) {
|
it('represents a lua table appropritely', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.eval("return {1,2,3,'ciao',{1,2}}", 0, function (err, res) {
|
client.eval("return {1,2,3,'ciao',{1,2}}", 0, function (err, res) {
|
||||||
assert.strictEqual(5, res.length);
|
assert.strictEqual(5, res.length);
|
||||||
assert.strictEqual(1, res[0]);
|
assert.strictEqual(1, res[0]);
|
||||||
@@ -71,7 +71,7 @@ describe("The 'eval' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('populates keys and argv correctly', function (done) {
|
it('populates keys and argv correctly', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d", function (err, res) {
|
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(4, res.length);
|
||||||
assert.strictEqual("a", res[0]);
|
assert.strictEqual("a", res[0]);
|
||||||
@@ -83,7 +83,7 @@ describe("The 'eval' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows arguments to be provided in array rather than as multiple parameters', function (done) {
|
it('allows arguments to be provided in array rather than as multiple parameters', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.eval(["return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d"], function (err, res) {
|
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(4, res.length);
|
||||||
assert.strictEqual("a", res[0]);
|
assert.strictEqual("a", res[0]);
|
||||||
@@ -105,23 +105,23 @@ describe("The 'eval' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows a script to be executed that accesses the redis API', function (done) {
|
it('allows a script to be executed that accesses the redis API', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.eval(source, 0, helper.isString('eval get sha test', done));
|
client.eval(source, 0, helper.isString('eval get sha test', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can execute a script if the SHA exists', function (done) {
|
it('can execute a script if the SHA exists', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.evalsha(sha, 0, helper.isString('eval get sha test', done));
|
client.evalsha(sha, 0, helper.isString('eval get sha test', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws an error if SHA does not exist', function (done) {
|
it('throws an error if SHA does not exist', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0, helper.isError(done));
|
client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0, helper.isError(done));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows a key to be incremented, and performs appropriate conversion from LUA type', function (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]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.set("incr key", 0, function (err, reply) {
|
client.set("incr key", 0, function (err, reply) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
client.eval("local foo = redis.call('incr','incr key')\n" + "return {type(foo),foo}", 0, function (err, res) {
|
client.eval("local foo = redis.call('incr','incr key')\n" + "return {type(foo),foo}", 0, function (err, res) {
|
||||||
@@ -134,7 +134,7 @@ describe("The 'eval' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows a bulk operation to be performed, and performs appropriate conversion from LUA type', function (done) {
|
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]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.set("bulk reply key", "bulk reply value", function (err, res) {
|
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) {
|
client.eval("local foo = redis.call('get','bulk reply key'); return {type(foo),foo}", 0, function (err, res) {
|
||||||
assert.strictEqual(2, res.length);
|
assert.strictEqual(2, res.length);
|
||||||
@@ -146,7 +146,7 @@ describe("The 'eval' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows a multi mulk operation to be performed, with the appropriate type conversion', function (done) {
|
it('allows a multi mulk operation to be performed, with the appropriate type conversion', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.multi()
|
client.multi()
|
||||||
.del("mylist")
|
.del("mylist")
|
||||||
.rpush("mylist", "a")
|
.rpush("mylist", "a")
|
||||||
@@ -167,7 +167,7 @@ describe("The 'eval' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns an appropriate representation of Lua status reply', function (done) {
|
it('returns an appropriate representation of Lua status reply', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.eval("local foo = redis.call('set','mykey','myval'); return {type(foo),foo['ok']}", 0, function (err, res) {
|
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(2, res.length);
|
||||||
assert.strictEqual("table", res[0]);
|
assert.strictEqual("table", res[0]);
|
||||||
@@ -177,7 +177,7 @@ describe("The 'eval' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns an appropriate representation of a Lua error reply', function (done) {
|
it('returns an appropriate representation of a Lua error reply', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.set("error reply key", "error reply value", function (err, res) {
|
client.set("error reply key", "error reply value", function (err, res) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
client.eval("local foo = redis.pcall('incr','error reply key'); return {type(foo),foo['err']}", 0, function (err, res) {
|
client.eval("local foo = redis.pcall('incr','error reply key'); return {type(foo),foo['err']}", 0, function (err, res) {
|
||||||
@@ -190,7 +190,7 @@ describe("The 'eval' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns an appropriate representation of a Lua nil reply', function (done) {
|
it('returns an appropriate representation of a Lua nil reply', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.del("nil reply key", function (err, res) {
|
client.del("nil reply key", function (err, res) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
client.eval("local foo = redis.call('get','nil reply key'); return {type(foo),foo == false}", 0, function (err, res) {
|
client.eval("local foo = redis.call('get','nil reply key'); return {type(foo),foo == false}", 0, function (err, res) {
|
||||||
|
@@ -195,7 +195,7 @@ describe("The 'multi' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports multiple exceptions when they occur', function (done) {
|
it('reports multiple exceptions when they occur', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 6, 5]);
|
helper.serverVersionAtLeast.call(this, client, [2, 6, 5]);
|
||||||
|
|
||||||
client.multi().set("foo").exec(function (err, reply) {
|
client.multi().set("foo").exec(function (err, reply) {
|
||||||
assert(Array.isArray(err), "err should be an array");
|
assert(Array.isArray(err), "err should be an array");
|
||||||
|
@@ -28,7 +28,7 @@ describe("The 'script' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("loads script with client.script('load')", function (done) {
|
it("loads script with client.script('load')", function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 6, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 6, 0]);
|
||||||
client.script("load", command, function(err, result) {
|
client.script("load", command, function(err, result) {
|
||||||
assert.strictEqual(result, commandSha);
|
assert.strictEqual(result, commandSha);
|
||||||
return done();
|
return done();
|
||||||
@@ -36,12 +36,12 @@ describe("The 'script' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows a loaded script to be evaluated', function (done) {
|
it('allows a loaded script to be evaluated', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 6, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 6, 0]);
|
||||||
client.evalsha(commandSha, 0, helper.isString('99', done));
|
client.evalsha(commandSha, 0, helper.isString('99', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows a script to be loaded as part of a chained transaction', function (done) {
|
it('allows a script to be loaded as part of a chained transaction', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 6, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 6, 0]);
|
||||||
client.multi().script("load", command).exec(function(err, result) {
|
client.multi().script("load", command).exec(function(err, result) {
|
||||||
assert.strictEqual(result[0], commandSha);
|
assert.strictEqual(result[0], commandSha);
|
||||||
return done();
|
return done();
|
||||||
@@ -49,7 +49,7 @@ describe("The 'script' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("allows a script to be loaded using a transaction's array syntax", function (done) {
|
it("allows a script to be loaded using a transaction's array syntax", function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 6, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 6, 0]);
|
||||||
client.multi([['script', 'load', command]]).exec(function(err, result) {
|
client.multi([['script', 'load', command]]).exec(function(err, result) {
|
||||||
assert.strictEqual(result[0], commandSha);
|
assert.strictEqual(result[0], commandSha);
|
||||||
return done();
|
return done();
|
||||||
|
@@ -219,7 +219,7 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
describe('monitor', function () {
|
describe('monitor', function () {
|
||||||
it('monitors commands on all other redis clients', function (done) {
|
it('monitors commands on all other redis clients', function (done) {
|
||||||
helper.serverVersionAtLeast.bind(this)(client, [2, 6, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 6, 0]);
|
||||||
|
|
||||||
var monitorClient = redis.createClient.apply(redis.createClient, args);
|
var monitorClient = redis.createClient.apply(redis.createClient, args);
|
||||||
var responses = [];
|
var responses = [];
|
||||||
|
Reference in New Issue
Block a user