1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

Upgrade node and dependencies (#1578)

* upgrade workflow actions

* fix setup-node version

* change redis-64 version to 3.0.503

* fix "no password is set" for redis6,
fix tests to work with redis6,
add redis6 to workflows

* do not use assert.match (was added only at v13.6.0 & v12.16.0)

* fix errors.subscribeUnsubscribeOnly regex

* fix invaliodPassword typo

* send --save "" to redis-server in tests

* upgrade dependencies, set node minimum version to 10, use current LTS versions in tests and benchmark workflows

* change windows tests too

* revert mocha back to ^4.1.0

* fix for f5528504a0 - revert mocha back to ^4.1.0

* fix some tests and upgrade mocha

* fix two more tests

* try to fix tests in windows

* upgrade denque and redis-commands
ref #1575

* replace `new Buffer` (deprecated) with `Buffer.from`

* Buffer.from(0) should be Buffer.alloc(0)
This commit is contained in:
Leibale Eidelman
2021-03-08 14:12:26 -05:00
committed by GitHub
parent 218874432e
commit fbca5cda0a
22 changed files with 129 additions and 98 deletions

View File

@@ -9,8 +9,8 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
node-version: [8.x, 10.x, 12.x] node-version: [10.x, 12.x, 14.x, 15.x]
redis-version: [5] redis-version: [5.x, 6.x]
steps: steps:
- uses: actions/checkout@v2.3.4 - uses: actions/checkout@v2.3.4

View File

@@ -9,8 +9,8 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
node-version: [6.x, 8.x, 10.x, 12.x] node-version: [10.x, 12.x, 14.x, 15.x]
redis-version: [4.x, 5.x] redis-version: [4.x, 5.x, 6.x]
steps: steps:
- uses: actions/checkout@v2.3.4 - uses: actions/checkout@v2.3.4

View File

@@ -9,7 +9,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
node-version: [6.x, 8.x, 10.x, 12.x] node-version: [10.x, 12.x, 14.x, 15.x]
steps: steps:
- uses: actions/checkout@v2.3.4 - uses: actions/checkout@v2.3.4
with: with:

View File

@@ -4,7 +4,7 @@ var utils = require('./utils');
var debug = require('./debug'); var debug = require('./debug');
var Multi = require('./multi'); var Multi = require('./multi');
var Command = require('./command'); var Command = require('./command');
var no_password_is_set = /no password is set/; var no_password_is_set = /no password is set|called without any password configured/;
var loading = /LOADING/; var loading = /LOADING/;
var RedisClient = require('../').RedisClient; var RedisClient = require('../').RedisClient;

View File

@@ -30,33 +30,33 @@
"coveralls": "nyc report --reporter=text-lcov | coveralls", "coveralls": "nyc report --reporter=text-lcov | coveralls",
"coverage": "nyc report --reporter=html", "coverage": "nyc report --reporter=html",
"benchmark": "node benchmarks/multi_bench.js", "benchmark": "node benchmarks/multi_bench.js",
"test": "nyc --cache mocha ./test/*.js ./test/commands/*.js --timeout=8000 && npm run coverage", "test": "nyc --cache mocha ./test/*.spec.js ./test/commands/*.spec.js --timeout=8000 && npm run coverage",
"lint": "eslint .", "lint": "eslint .",
"lint:fix": "eslint . --fix", "lint:fix": "eslint . --fix",
"lint:report": "eslint --output-file=eslint-report.json --format=json .", "lint:report": "eslint --output-file=eslint-report.json --format=json .",
"compare": "node benchmarks/diff_multi_bench_output.js beforeBench.txt afterBench.txt" "compare": "node benchmarks/diff_multi_bench_output.js beforeBench.txt afterBench.txt"
}, },
"dependencies": { "dependencies": {
"denque": "^1.4.1", "denque": "^1.5.0",
"redis-commands": "^1.5.0", "redis-commands": "^1.7.0",
"redis-errors": "^1.2.0", "redis-errors": "^1.2.0",
"redis-parser": "^3.0.0" "redis-parser": "^3.0.0"
}, },
"engines": { "engines": {
"node": ">=6" "node": ">=10"
}, },
"devDependencies": { "devDependencies": {
"prettier": "^1.19.1",
"bluebird": "^3.7.2", "bluebird": "^3.7.2",
"coveralls": "^2.11.2", "coveralls": "^3.1.0",
"eslint": "^6.8.0", "cross-spawn": "^7.0.3",
"eslint": "^7.21.0",
"intercept-stdout": "~0.1.2", "intercept-stdout": "~0.1.2",
"metrics": "^0.1.21", "metrics": "^0.1.21",
"mocha": "^4.1.0", "mocha": "^8.3.0",
"nyc": "^14.1.1", "nyc": "^15.1.0",
"prettier": "^2.2.1",
"tcp-port-used": "^1.0.1", "tcp-port-used": "^1.0.1",
"uuid": "^3.4.0", "uuid": "^8.3.2"
"cross-spawn": "^6.0.5"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -3,6 +3,7 @@
var assert = require('assert'); var assert = require('assert');
var config = require('./lib/config'); var config = require('./lib/config');
var helper = require('./helper'); var helper = require('./helper');
var errors = require('./errors');
var redis = config.redis; var redis = config.redis;
if (process.platform === 'win32') { if (process.platform === 'win32') {
@@ -70,11 +71,13 @@ describe('client authentication', function () {
it('emits error when auth is bad without callback', function (done) { it('emits error when auth is bad without callback', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip(); if (helper.redisProcess().spawnFailed()) this.skip();
client = redis.createClient.apply(null, args); client = redis.createClient.apply(null, config.configureClient(ip, {
no_ready_check: true
}));
client.once('error', function (err) { client.once('error', function (err) {
assert.strictEqual(err.command, 'AUTH'); assert.strictEqual(err.command, 'AUTH');
assert.ok(/ERR invalid password/.test(err.message)); assert.ok(errors.invalidPassword.test(err.message));
return done(); return done();
}); });
@@ -84,11 +87,13 @@ describe('client authentication', function () {
it('returns an error when auth is bad (empty string) with a callback', function (done) { it('returns an error when auth is bad (empty string) with a callback', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip(); if (helper.redisProcess().spawnFailed()) this.skip();
client = redis.createClient.apply(null, args); client = redis.createClient.apply(null, config.configureClient(ip, {
no_ready_check: true
}));
client.auth('', function (err, res) { client.auth('', function (err, res) {
assert.strictEqual(err.command, 'AUTH'); assert.strictEqual(err.command, 'AUTH');
assert.ok(/ERR invalid password/.test(err.message)); assert.ok(errors.invalidPassword.test(err.message));
done(); done();
}); });
}); });
@@ -190,10 +195,12 @@ describe('client authentication', function () {
it('should return an error if the password is not correct and a callback has been provided', function (done) { it('should return an error if the password is not correct and a callback has been provided', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip(); if (helper.redisProcess().spawnFailed()) this.skip();
client = redis.createClient.apply(null, args); client = redis.createClient.apply(null, config.configureClient(ip, {
no_ready_check: true
}));
var async = true; var async = true;
client.auth('undefined', function (err, res) { client.auth('undefined', function (err, res) {
assert.strictEqual(err.message, 'ERR invalid password'); assert.ok(errors.invalidPassword.test(err.message));
assert.strictEqual(err.command, 'AUTH'); assert.strictEqual(err.command, 'AUTH');
assert.strictEqual(res, undefined); assert.strictEqual(res, undefined);
async = false; async = false;
@@ -205,9 +212,11 @@ describe('client authentication', function () {
it('should emit an error if the password is not correct and no callback has been provided', function (done) { it('should emit an error if the password is not correct and no callback has been provided', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip(); if (helper.redisProcess().spawnFailed()) this.skip();
client = redis.createClient.apply(null, args); client = redis.createClient.apply(null, config.configureClient(ip, {
no_ready_check: true
}));
client.on('error', function (err) { client.on('error', function (err) {
assert.strictEqual(err.message, 'ERR invalid password'); assert.ok(errors.invalidPassword.test(err.message));
assert.strictEqual(err.command, 'AUTH'); assert.strictEqual(err.command, 'AUTH');
done(); done();
}); });
@@ -235,7 +244,7 @@ describe('client authentication', function () {
client = redis.createClient.apply(null, args); client = redis.createClient.apply(null, args);
client.on('ready', function () { client.on('ready', function () {
client.set('foo', 'bar', function (err, res) { client.set('foo', 'bar', function (err, res) {
assert.equal(err.message, 'NOAUTH Authentication required.'); assert.ok(/^NOAUTH Authentication required\.(\r\n)?$/.test(err.message));
assert.equal(err.code, 'NOAUTH'); assert.equal(err.code, 'NOAUTH');
assert.equal(err.command, 'SET'); assert.equal(err.command, 'SET');
done(); done();
@@ -248,7 +257,7 @@ describe('client authentication', function () {
client = redis.createClient.apply(null, args); client = redis.createClient.apply(null, args);
client.on('error', function (err) { client.on('error', function (err) {
assert.equal(err.code, 'NOAUTH'); assert.equal(err.code, 'NOAUTH');
assert.equal(err.message, 'Ready check failed: NOAUTH Authentication required.'); assert.ok(/^Ready check failed: NOAUTH Authentication required\.(\r\n)?$/.test(err.message));
assert.equal(err.command, 'INFO'); assert.equal(err.command, 'INFO');
done(); done();
}); });
@@ -258,9 +267,10 @@ describe('client authentication', function () {
if (helper.redisProcess().spawnFailed()) this.skip(); if (helper.redisProcess().spawnFailed()) this.skip();
client = redis.createClient({ client = redis.createClient({
password: 'wrong_password', password: 'wrong_password',
no_ready_check: true
}); });
client.once('error', function (err) { client.once('error', function (err) {
assert.strictEqual(err.message, 'ERR invalid password'); assert.ok(errors.invalidPassword.test(err.message));
done(); done();
}); });
}); });
@@ -277,7 +287,7 @@ describe('client authentication', function () {
client.once('ready', function () { client.once('ready', function () {
assert.strictEqual(client.pub_sub_mode, 1); assert.strictEqual(client.pub_sub_mode, 1);
client.get('foo', function (err, res) { client.get('foo', function (err, res) {
assert(/ERR only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/.test(err.message)); assert.ok(errors.subscribeUnsubscribeOnly.test(err.message));
done(); done();
}); });
}); });

View File

@@ -57,7 +57,7 @@ describe("The 'client' method", function () {
it('off', function (done) { it('off', function (done) {
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]); helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
assert.strictEqual(client.reply, 'ON'); assert.strictEqual(client.reply, 'ON');
client.client(new Buffer('REPLY'), 'OFF', helper.isUndefined()); client.client(Buffer.from('REPLY'), 'OFF', helper.isUndefined());
assert.strictEqual(client.reply, 'OFF'); assert.strictEqual(client.reply, 'OFF');
client.set('foo', 'bar', helper.isUndefined(done)); client.set('foo', 'bar', helper.isUndefined(done));
}); });
@@ -65,7 +65,7 @@ describe("The 'client' method", function () {
it('skip', function (done) { it('skip', function (done) {
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]); helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
assert.strictEqual(client.reply, 'ON'); assert.strictEqual(client.reply, 'ON');
client.client('REPLY', new Buffer('SKIP'), helper.isUndefined()); client.client('REPLY', Buffer.from('SKIP'), helper.isUndefined());
assert.strictEqual(client.reply, 'SKIP_ONE_MORE'); assert.strictEqual(client.reply, 'SKIP_ONE_MORE');
client.set('foo', 'bar', helper.isUndefined()); client.set('foo', 'bar', helper.isUndefined());
client.get('foo', helper.isString('bar', done)); client.get('foo', helper.isString('bar', done));
@@ -91,7 +91,7 @@ describe("The 'client' method", function () {
var batch = client.batch(); var batch = client.batch();
assert.strictEqual(client.reply, 'ON'); assert.strictEqual(client.reply, 'ON');
batch.set('hello', 'world'); batch.set('hello', 'world');
batch.client(new Buffer('REPLY'), new Buffer('OFF'), helper.isUndefined()); batch.client(Buffer.from('REPLY'), Buffer.from('OFF'), helper.isUndefined());
batch.set('foo', 'bar', helper.isUndefined()); batch.set('foo', 'bar', helper.isUndefined());
batch.exec(function (err, res) { batch.exec(function (err, res) {
assert.strictEqual(client.reply, 'OFF'); assert.strictEqual(client.reply, 'OFF');

View File

@@ -50,7 +50,6 @@ describe("The 'hgetall' method", function () {
}); });
describe('binary client', function () { describe('binary client', function () {
var client;
var args = config.configureClient(ip, { var args = config.configureClient(ip, {
return_buffers: true return_buffers: true
}); });
@@ -63,14 +62,14 @@ describe("The 'hgetall' method", function () {
}); });
it('returns binary results', function (done) { it('returns binary results', function (done) {
client.hmset(['bhosts', 'mjr', '1', 'another', '23', 'home', '1234', new Buffer([0xAA, 0xBB, 0x00, 0xF0]), new Buffer([0xCC, 0xDD, 0x00, 0xF0])], helper.isString('OK')); client.hmset(['bhosts', 'mjr', '1', 'another', '23', 'home', '1234', Buffer.from([0xAA, 0xBB, 0x00, 0xF0]), Buffer.from([0xCC, 0xDD, 0x00, 0xF0])], helper.isString('OK'));
client.HGETALL('bhosts', function (err, obj) { client.HGETALL('bhosts', function (err, obj) {
assert.strictEqual(4, Object.keys(obj).length); assert.strictEqual(4, Object.keys(obj).length);
assert.strictEqual('1', obj.mjr.toString()); assert.strictEqual('1', obj.mjr.toString());
assert.strictEqual('23', obj.another.toString()); assert.strictEqual('23', obj.another.toString());
assert.strictEqual('1234', obj.home.toString()); assert.strictEqual('1234', obj.home.toString());
assert.strictEqual((new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary'), Object.keys(obj)[3]); assert.strictEqual((Buffer.from([0xAA, 0xBB, 0x00, 0xF0])).toString('binary'), Object.keys(obj)[3]);
assert.strictEqual((new Buffer([0xCC, 0xDD, 0x00, 0xF0])).toString('binary'), obj[(new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary')].toString('binary')); assert.strictEqual((Buffer.from([0xCC, 0xDD, 0x00, 0xF0])).toString('binary'), obj[(Buffer.from([0xAA, 0xBB, 0x00, 0xF0])).toString('binary')].toString('binary'));
return done(err); return done(err);
}); });
}); });

View File

@@ -20,10 +20,10 @@ describe("The 'hlen' method", function () {
it('reports the count of keys', function (done) { it('reports the count of keys', function (done) {
var hash = 'test hash'; var hash = 'test hash';
var field1 = new Buffer('0123456789'); var field1 = Buffer.from('0123456789');
var value1 = new Buffer('abcdefghij'); var value1 = Buffer.from('abcdefghij');
var field2 = new Buffer(0); var field2 = Buffer.alloc(0);
var value2 = new Buffer(0); var value2 = Buffer.alloc(0);
client.HSET(hash, field1, value1, helper.isNumber(1)); client.HSET(hash, field1, value1, helper.isNumber(1));
client.HSET(hash, field2, value2, helper.isNumber(1)); client.HSET(hash, field2, value2, helper.isNumber(1));

View File

@@ -21,24 +21,24 @@ describe("The 'hset' method", function () {
}); });
it('allows a value to be set in a hash', function (done) { it('allows a value to be set in a hash', function (done) {
var field = new Buffer('0123456789'); var field = Buffer.from('0123456789');
var value = new Buffer('abcdefghij'); var value = Buffer.from('abcdefghij');
client.hset(hash, field, value, helper.isNumber(1)); client.hset(hash, field, value, helper.isNumber(1));
client.HGET(hash, field, helper.isString(value.toString(), done)); client.HGET(hash, field, helper.isString(value.toString(), done));
}); });
it('handles an empty value', function (done) { it('handles an empty value', function (done) {
var field = new Buffer('0123456789'); var field = Buffer.from('0123456789');
var value = new Buffer(0); var value = Buffer.alloc(0);
client.HSET(hash, field, value, helper.isNumber(1)); client.HSET(hash, field, value, helper.isNumber(1));
client.HGET([hash, field], helper.isString('', done)); client.HGET([hash, field], helper.isString('', done));
}); });
it('handles empty key and value', function (done) { it('handles empty key and value', function (done) {
var field = new Buffer(0); var field = Buffer.alloc(0);
var value = new Buffer(0); var value = Buffer.alloc(0);
client.HSET([hash, field, value], function (err, res) { client.HSET([hash, field, value], function (err, res) {
assert.strictEqual(res, 1); assert.strictEqual(res, 1);
client.HSET(hash, field, value, helper.isNumber(0, done)); client.HSET(hash, field, value, helper.isNumber(0, done));
@@ -60,7 +60,7 @@ describe("The 'hset' method", function () {
it('does not error when a buffer and date are set as values on the same hash', function (done) { it('does not error when a buffer and date are set as values on the same hash', function (done) {
var hash = 'test hash'; var hash = 'test hash';
var field1 = 'buffer'; var field1 = 'buffer';
var value1 = new Buffer('abcdefghij'); var value1 = Buffer.from('abcdefghij');
var field2 = 'date'; var field2 = 'date';
var value2 = new Date(); var value2 = new Date();
@@ -70,7 +70,7 @@ describe("The 'hset' method", function () {
it('does not error when a buffer and date are set as fields on the same hash', function (done) { it('does not error when a buffer and date are set as fields on the same hash', function (done) {
var hash = 'test hash'; var hash = 'test hash';
var value1 = 'buffer'; var value1 = 'buffer';
var field1 = new Buffer('abcdefghij'); var field1 = Buffer.from('abcdefghij');
var value2 = 'date'; var value2 = 'date';
var field2 = new Date(); var field2 = new Date();

View File

@@ -90,8 +90,8 @@ describe("The 'monitor' method", function () {
monitorClient.MONITOR(function (err, res) { monitorClient.MONITOR(function (err, res) {
assert.strictEqual(monitorClient.monitoring, true); assert.strictEqual(monitorClient.monitoring, true);
assert.strictEqual(res.inspect(), new Buffer('OK').inspect()); assert.strictEqual(res.inspect(), Buffer.from('OK').inspect());
monitorClient.mget('hello', new Buffer('world')); monitorClient.mget('hello', Buffer.from('world'));
}); });
monitorClient.on('monitor', function (time, args, rawOutput) { monitorClient.on('monitor', function (time, args, rawOutput) {

View File

@@ -3,3 +3,4 @@ port 6379
bind ::1 127.0.0.1 bind ::1 127.0.0.1
unixsocket /tmp/redis.sock unixsocket /tmp/redis.sock
unixsocketperm 700 unixsocketperm 700
save ""

View File

@@ -2,3 +2,4 @@ port 6379
bind ::1 127.0.0.1 bind ::1 127.0.0.1
unixsocket /tmp/redis.sock unixsocket /tmp/redis.sock
unixsocketperm 700 unixsocketperm 700
save ""

View File

@@ -2,6 +2,7 @@ port 6379
bind ::1 127.0.0.1 bind ::1 127.0.0.1
unixsocket /tmp/redis.sock unixsocket /tmp/redis.sock
unixsocketperm 700 unixsocketperm 700
save ""
rename-command SET 807081f5afa96845a02816a28b7258c3 rename-command SET 807081f5afa96845a02816a28b7258c3
rename-command GET f397808a43ceca3963e22b4e13deb672 rename-command GET f397808a43ceca3963e22b4e13deb672
rename-command GETRANGE 9e3102b15cf231c4e9e940f284744fe0 rename-command GETRANGE 9e3102b15cf231c4e9e940f284744fe0

View File

@@ -4,3 +4,4 @@ unixsocket /tmp/redis6381.sock
unixsocketperm 700 unixsocketperm 700
slaveof localhost 6379 slaveof localhost 6379
masterauth porkchopsandwiches masterauth porkchopsandwiches
save ""

View File

@@ -14,6 +14,8 @@ describe('connection tests', function () {
client = null; client = null;
}); });
afterEach(function () { afterEach(function () {
if (!client) return;
client.end(true); client.end(true);
}); });
@@ -238,7 +240,8 @@ describe('connection tests', function () {
client = redis.createClient({ client = redis.createClient({
retryStrategy: function (options) { retryStrategy: function (options) {
if (options.totalRetryTime > 150) { if (options.totalRetryTime > 150) {
client.set('foo', 'bar', function (err, res) { client.set('foo', 'bar');
client.once('error', function (err) {
assert.strictEqual(err.message, 'Redis connection in broken state: retry aborted.'); assert.strictEqual(err.message, 'Redis connection in broken state: retry aborted.');
assert.strictEqual(err.origin.message, 'Connection timeout'); assert.strictEqual(err.origin.message, 'Connection timeout');
done(); done();
@@ -256,7 +259,8 @@ describe('connection tests', function () {
client = redis.createClient({ client = redis.createClient({
retry_strategy: function (options) { retry_strategy: function (options) {
if (options.total_retry_time > 150) { if (options.total_retry_time > 150) {
client.set('foo', 'bar', function (err, res) { client.set('foo', 'bar');
client.once('error', function (err) {
assert.strictEqual(err.message, 'Redis connection in broken state: retry aborted.'); assert.strictEqual(err.message, 'Redis connection in broken state: retry aborted.');
assert.strictEqual(err.code, 'CONNECTION_BROKEN'); assert.strictEqual(err.code, 'CONNECTION_BROKEN');
assert.strictEqual(err.origin.code, 'ECONNREFUSED'); assert.strictEqual(err.origin.code, 'ECONNREFUSED');
@@ -334,9 +338,10 @@ describe('connection tests', function () {
it('use the system socket timeout if the connect_timeout has not been provided', function (done) { it('use the system socket timeout if the connect_timeout has not been provided', function (done) {
client = redis.createClient({ client = redis.createClient({
host: '2001:db8::ff00:42:8329' // auto detect ip v6 host: '0:0:0:0:0:0:0:1', // auto detect ip v6
no_ready_check: true
}); });
assert.strictEqual(client.address, '2001:db8::ff00:42:8329:6379'); assert.strictEqual(client.address, '0:0:0:0:0:0:0:1:6379');
assert.strictEqual(client.connection_options.family, 6); assert.strictEqual(client.connection_options.family, 6);
process.nextTick(function () { process.nextTick(function () {
assert.strictEqual(client.stream.listeners('timeout').length, 0); assert.strictEqual(client.stream.listeners('timeout').length, 0);

View File

@@ -43,7 +43,7 @@ describe('detect_buffers', function () {
describe('first argument is a buffer', function () { describe('first argument is a buffer', function () {
it('returns a buffer', function (done) { it('returns a buffer', function (done) {
client.get(new Buffer('string key 1'), function (err, reply) { client.get(Buffer.from('string key 1'), function (err, reply) {
assert.strictEqual(true, Buffer.isBuffer(reply)); assert.strictEqual(true, Buffer.isBuffer(reply));
assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply.inspect()); assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply.inspect());
return done(err); return done(err);
@@ -51,7 +51,7 @@ describe('detect_buffers', function () {
}); });
it('returns a bufffer when executed as part of transaction', function (done) { it('returns a bufffer when executed as part of transaction', function (done) {
client.multi().get(new Buffer('string key 1')).exec(function (err, reply) { client.multi().get(Buffer.from('string key 1')).exec(function (err, reply) {
assert.strictEqual(1, reply.length); assert.strictEqual(1, reply.length);
assert.strictEqual(true, Buffer.isBuffer(reply[0])); assert.strictEqual(true, Buffer.isBuffer(reply[0]));
assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply[0].inspect()); assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply[0].inspect());
@@ -65,8 +65,8 @@ describe('detect_buffers', function () {
it('can interleave string and buffer results', function (done) { it('can interleave string and buffer results', function (done) {
client.multi() client.multi()
.hget('hash key 2', 'key 1') .hget('hash key 2', 'key 1')
.hget(new Buffer('hash key 2'), 'key 1') .hget(Buffer.from('hash key 2'), 'key 1')
.hget('hash key 2', new Buffer('key 2')) .hget('hash key 2', Buffer.from('key 2'))
.hget('hash key 2', 'key 2') .hget('hash key 2', 'key 2')
.exec(function (err, reply) { .exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(true, Array.isArray(reply));
@@ -86,8 +86,8 @@ describe('detect_buffers', function () {
it('can interleave string and buffer results', function (done) { it('can interleave string and buffer results', function (done) {
client.batch() client.batch()
.hget('hash key 2', 'key 1') .hget('hash key 2', 'key 1')
.hget(new Buffer('hash key 2'), 'key 1') .hget(Buffer.from('hash key 2'), 'key 1')
.hget('hash key 2', new Buffer('key 2')) .hget('hash key 2', Buffer.from('key 2'))
.hget('hash key 2', 'key 2') .hget('hash key 2', 'key 2')
.exec(function (err, reply) { .exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(true, Array.isArray(reply));
@@ -150,7 +150,7 @@ describe('detect_buffers', function () {
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(Buffer.from('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]));
@@ -162,7 +162,7 @@ describe('detect_buffers', function () {
}); });
it('returns buffers for keys requested in transaction', function (done) { 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) { client.multi().hmget(Buffer.from('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(1, reply.length); assert.strictEqual(1, reply.length);
assert.strictEqual(2, reply[0].length); assert.strictEqual(2, reply[0].length);
@@ -175,7 +175,7 @@ describe('detect_buffers', function () {
}); });
it('returns buffers for keys requested in .batch', function (done) { 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) { client.batch().hmget(Buffer.from('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(1, reply.length); assert.strictEqual(1, reply.length);
assert.strictEqual(2, reply[0].length); assert.strictEqual(2, reply[0].length);
@@ -226,7 +226,7 @@ describe('detect_buffers', function () {
describe('first argument is a buffer', function () { describe('first argument is a buffer', function () {
it('returns buffer values', function (done) { it('returns buffer values', function (done) {
client.hgetall(new Buffer('hash key 2'), function (err, reply) { client.hgetall(Buffer.from('hash key 2'), function (err, reply) {
assert.strictEqual(null, err); assert.strictEqual(null, err);
assert.strictEqual('object', typeof reply); assert.strictEqual('object', typeof reply);
assert.strictEqual(2, Object.keys(reply).length); assert.strictEqual(2, Object.keys(reply).length);
@@ -239,7 +239,7 @@ describe('detect_buffers', function () {
}); });
it('returns buffer values when executed in transaction', function (done) { it('returns buffer values when executed in transaction', function (done) {
client.multi().hgetall(new Buffer('hash key 2')).exec(function (err, reply) { client.multi().hgetall(Buffer.from('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);
@@ -252,7 +252,7 @@ describe('detect_buffers', function () {
}); });
it('returns buffer values when executed in .batch', function (done) { it('returns buffer values when executed in .batch', function (done) {
client.batch().hgetall(new Buffer('hash key 2')).exec(function (err, reply) { client.batch().hgetall(Buffer.from('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);

6
test/errors.js Normal file
View File

@@ -0,0 +1,6 @@
'use strict';
module.exports = {
invalidPassword: /^(ERR invalid password|WRONGPASS invalid username-password pair)/,
subscribeUnsubscribeOnly: /^ERR( Can't execute 'get':)? only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/
};

View File

@@ -46,7 +46,7 @@ describe("The 'multi' method", function () {
} }
var json = JSON.stringify(test_arr); var json = JSON.stringify(test_arr);
zlib.deflate(new Buffer(json), function (err, buffer) { zlib.deflate(Buffer.from(json), function (err, buffer) {
if (err) { if (err) {
done(err); done(err);
return; return;

View File

@@ -83,10 +83,11 @@ describe('The node_redis client', function () {
client.once('reconnecting', function () { client.once('reconnecting', function () {
process.nextTick(function () { process.nextTick(function () {
assert.strictEqual(client.reply_parser.buffer, null); assert.strictEqual(client.reply_parser.buffer, null);
client.end(true);
done(); done();
}); });
}); });
var partialInput = new Buffer('$100\r\nabcdef'); var partialInput = Buffer.from('$100\r\nabcdef');
client.reply_parser.execute(partialInput); client.reply_parser.execute(partialInput);
assert.strictEqual(client.reply_parser.buffer.inspect(), partialInput.inspect()); assert.strictEqual(client.reply_parser.buffer.inspect(), partialInput.inspect());
client.stream.destroy(); client.stream.destroy();
@@ -531,11 +532,11 @@ describe('The node_redis client', function () {
// TODO: Investigate why this test is failing hard and killing mocha if using '/tmp/redis.sock'. // TODO: Investigate why this test is failing hard and killing mocha if using '/tmp/redis.sock'.
// Seems like something is wrong with nyc while passing a socket connection to create client! // Seems like something is wrong with nyc while passing a socket connection to create client!
client = redis.createClient(); var client2 = redis.createClient();
client.quit(function () { client2.quit(function () {
client.get('foo', function (err, res) { client2.get('foo', function (err, res) {
assert.strictEqual(err.message, 'Stream connection ended and command aborted. It might have been processed.'); assert.strictEqual(err.message, 'Stream connection ended and command aborted. It might have been processed.');
assert.strictEqual(client.offline_queue.length, 0); assert.strictEqual(client2.offline_queue.length, 0);
done(); done();
}); });
}); });
@@ -702,6 +703,7 @@ describe('The node_redis client', function () {
// Recreate client in domain so error handlers run this domain // Recreate client in domain so error handlers run this domain
// Changed in: "error handler runs outside of its domain" // Changed in: "error handler runs outside of its domain"
// https://github.com/nodejs/node/pull/26211 // https://github.com/nodejs/node/pull/26211
client.end(true); // make sure to close current client
client = redis.createClient(); client = redis.createClient();
} }
client.end(true); client.end(true);
@@ -811,7 +813,7 @@ describe('The node_redis client', function () {
// ready is called in a reply // ready is called in a reply
process.nextTick(function () { process.nextTick(function () {
// Fail the set answer. Has no corresponding command obj and will therefore land in the error handler and set // Fail the set answer. Has no corresponding command obj and will therefore land in the error handler and set
client.reply_parser.execute(new Buffer('a*1\r*1\r$1`zasd\r\na')); client.reply_parser.execute(Buffer.from('a*1\r*1\r$1`zasd\r\na'));
}); });
}); });
}); });

View File

@@ -3,6 +3,7 @@
var assert = require('assert'); var assert = require('assert');
var config = require('./lib/config'); var config = require('./lib/config');
var helper = require('./helper'); var helper = require('./helper');
var errors = require('./errors');
var redis = config.redis; var redis = config.redis;
describe('publish/subscribe', function () { describe('publish/subscribe', function () {
@@ -124,7 +125,7 @@ describe('publish/subscribe', function () {
detect_buffers: true detect_buffers: true
}); });
sub.on('subscribe', function (chnl, count) { sub.on('subscribe', function (chnl, count) {
if (chnl.inspect() === new Buffer([0xAA, 0xBB, 0x00, 0xF0]).inspect()) { if (chnl.inspect() === Buffer.from([0xAA, 0xBB, 0x00, 0xF0]).inspect()) {
assert.equal(1, count); assert.equal(1, count);
if (a) { if (a) {
return done(); return done();
@@ -137,7 +138,7 @@ describe('publish/subscribe', function () {
a = true; a = true;
}); });
sub.subscribe(new Buffer([0xAA, 0xBB, 0x00, 0xF0]), channel2); sub.subscribe(Buffer.from([0xAA, 0xBB, 0x00, 0xF0]), channel2);
}); });
it('receives messages on subscribed channel', function (done) { it('receives messages on subscribed channel', function (done) {
@@ -262,13 +263,13 @@ describe('publish/subscribe', function () {
}); });
it('handles multiple channels with the same channel name properly, even with buffers', function (done) { it('handles multiple channels with the same channel name properly, even with buffers', function (done) {
var channels = ['a', 'b', 'a', new Buffer('a'), 'c', 'b']; var channels = ['a', 'b', 'a', Buffer.from('a'), 'c', 'b'];
var subscribed_channels = [1, 2, 2, 2, 3, 3]; var subscribed_channels = [1, 2, 2, 2, 3, 3];
var i = 0; var i = 0;
sub.subscribe(channels); sub.subscribe(channels);
sub.on('subscribe', function (channel, count) { sub.on('subscribe', function (channel, count) {
if (Buffer.isBuffer(channel)) { if (Buffer.isBuffer(channel)) {
assert.strictEqual(channel.inspect(), new Buffer(channels[i]).inspect()); assert.strictEqual(channel.inspect(), Buffer.from(channels[i]).inspect());
} else { } else {
assert.strictEqual(channel, channels[i].toString()); assert.strictEqual(channel, channels[i].toString());
} }
@@ -420,7 +421,7 @@ describe('publish/subscribe', function () {
}); });
subscribe(['prefix:*', 'prefix:3'], function () { subscribe(['prefix:*', 'prefix:3'], function () {
pub.publish('prefix:1', new Buffer('test'), function () { pub.publish('prefix:1', Buffer.from('test'), function () {
subscribe(['prefix:2']); subscribe(['prefix:2']);
subscribe(['5', 'test:a', 'bla'], function () { subscribe(['5', 'test:a', 'bla'], function () {
assert(all); assert(all);
@@ -494,9 +495,9 @@ describe('publish/subscribe', function () {
sub2.batch().psubscribe('*', helper.isString('*')).exec(); sub2.batch().psubscribe('*', helper.isString('*')).exec();
sub2.subscribe('/foo'); sub2.subscribe('/foo');
sub2.on('pmessage', function (pattern, channel, message) { sub2.on('pmessage', function (pattern, channel, message) {
assert.strictEqual(pattern.inspect(), new Buffer('*').inspect()); assert.strictEqual(pattern.inspect(), Buffer.from('*').inspect());
assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect()); assert.strictEqual(channel.inspect(), Buffer.from('/foo').inspect());
assert.strictEqual(message.inspect(), new Buffer('hello world').inspect()); assert.strictEqual(message.inspect(), Buffer.from('hello world').inspect());
sub2.quit(done); sub2.quit(done);
}); });
pub.pubsub('numsub', '/foo', function (err, res) { pub.pubsub('numsub', '/foo', function (err, res) {
@@ -517,11 +518,11 @@ describe('publish/subscribe', function () {
assert.strictEqual(sub.shouldBuffer, false); assert.strictEqual(sub.shouldBuffer, false);
sub.on('pmessageBuffer', function (pattern, channel) { sub.on('pmessageBuffer', function (pattern, channel) {
if (typeof pattern === 'string') { if (typeof pattern === 'string') {
pattern = new Buffer(pattern); pattern = Buffer.from(pattern);
channel = new Buffer(channel); channel = Buffer.from(channel);
} }
assert.strictEqual(pattern.inspect(), new Buffer('*').inspect()); assert.strictEqual(pattern.inspect(), Buffer.from('*').inspect());
assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect()); assert.strictEqual(channel.inspect(), Buffer.from('/foo').inspect());
sub.quit(end); sub.quit(end);
}); });
// Either message_buffers or buffers has to be true, but not both at the same time // Either message_buffers or buffers has to be true, but not both at the same time
@@ -587,7 +588,7 @@ describe('publish/subscribe', function () {
}); });
// Get is forbidden // Get is forbidden
sub.get('foo', function (err, res) { sub.get('foo', function (err, res) {
assert(/^ERR only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/.test(err.message)); assert.ok(errors.subscribeUnsubscribeOnly.test(err.message));
assert.strictEqual(err.command, 'GET'); assert.strictEqual(err.command, 'GET');
}); });
// Quit is allowed // Quit is allowed
@@ -597,7 +598,7 @@ describe('publish/subscribe', function () {
it('emit error if only pub sub commands are allowed without callback', function (done) { it('emit error if only pub sub commands are allowed without callback', function (done) {
sub.subscribe('channel'); sub.subscribe('channel');
sub.on('error', function (err) { sub.on('error', function (err) {
assert(/^ERR only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/.test(err.message)); assert.ok(errors.subscribeUnsubscribeOnly.test(err.message));
assert.strictEqual(err.command, 'GET'); assert.strictEqual(err.command, 'GET');
done(); done();
}); });

View File

@@ -40,6 +40,10 @@ describe('return_buffers', function () {
}); });
}); });
afterEach(function () {
client.end(true);
});
describe('get', function () { describe('get', function () {
describe('first argument is a string', function () { describe('first argument is a string', function () {
it('returns a buffer', function (done) { it('returns a buffer', function (done) {
@@ -65,8 +69,8 @@ describe('return_buffers', function () {
it('returns buffers', function (done) { it('returns buffers', function (done) {
client.multi() client.multi()
.hget('hash key 2', 'key 1') .hget('hash key 2', 'key 1')
.hget(new Buffer('hash key 2'), 'key 1') .hget(Buffer.from('hash key 2'), 'key 1')
.hget('hash key 2', new Buffer('key 2')) .hget('hash key 2', Buffer.from('key 2'))
.hget('hash key 2', 'key 2') .hget('hash key 2', 'key 2')
.exec(function (err, reply) { .exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(true, Array.isArray(reply));
@@ -87,8 +91,8 @@ describe('return_buffers', function () {
it('returns buffers', function (done) { it('returns buffers', function (done) {
client.batch() client.batch()
.hget('hash key 2', 'key 1') .hget('hash key 2', 'key 1')
.hget(new Buffer('hash key 2'), 'key 1') .hget(Buffer.from('hash key 2'), 'key 1')
.hget('hash key 2', new Buffer('key 2')) .hget('hash key 2', Buffer.from('key 2'))
.hget('hash key 2', 'key 2') .hget('hash key 2', 'key 2')
.exec(function (err, reply) { .exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(true, Array.isArray(reply));
@@ -121,7 +125,7 @@ describe('return_buffers', function () {
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(Buffer.from('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]));
@@ -133,7 +137,7 @@ describe('return_buffers', function () {
}); });
it('returns buffers for keys requested in transaction', function (done) { 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) { client.multi().hmget(Buffer.from('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(1, reply.length); assert.strictEqual(1, reply.length);
assert.strictEqual(2, reply[0].length); assert.strictEqual(2, reply[0].length);
@@ -146,7 +150,7 @@ describe('return_buffers', function () {
}); });
it('returns buffers for keys requested in .batch', function (done) { 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) { client.batch().hmget(Buffer.from('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(true, Array.isArray(reply));
assert.strictEqual(1, reply.length); assert.strictEqual(1, reply.length);
assert.strictEqual(2, reply[0].length); assert.strictEqual(2, reply[0].length);
@@ -197,7 +201,7 @@ describe('return_buffers', function () {
describe('first argument is a buffer', function () { describe('first argument is a buffer', function () {
it('returns buffer values', function (done) { it('returns buffer values', function (done) {
client.hgetall(new Buffer('hash key 2'), function (err, reply) { client.hgetall(Buffer.from('hash key 2'), function (err, reply) {
assert.strictEqual(null, err); assert.strictEqual(null, err);
assert.strictEqual('object', typeof reply); assert.strictEqual('object', typeof reply);
assert.strictEqual(2, Object.keys(reply).length); assert.strictEqual(2, Object.keys(reply).length);
@@ -210,7 +214,7 @@ describe('return_buffers', function () {
}); });
it('returns buffer values when executed in transaction', function (done) { it('returns buffer values when executed in transaction', function (done) {
client.multi().hgetall(new Buffer('hash key 2')).exec(function (err, reply) { client.multi().hgetall(Buffer.from('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);
@@ -223,7 +227,7 @@ describe('return_buffers', function () {
}); });
it('returns buffer values when executed in .batch', function (done) { it('returns buffer values when executed in .batch', function (done) {
client.batch().hgetall(new Buffer('hash key 2')).exec(function (err, reply) { client.batch().hgetall(Buffer.from('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);
@@ -241,7 +245,7 @@ describe('return_buffers', function () {
var pub; var pub;
var sub; var sub;
var channel = 'test channel'; var channel = 'test channel';
var message = new Buffer('test message'); var message = Buffer.from('test message');
var args = config.configureClient(ip, { var args = config.configureClient(ip, {
return_buffers: true return_buffers: true