diff --git a/benchmarks/multi_bench.js b/benchmarks/multi_bench.js index 4bee7789dc..8164db5dbf 100644 --- a/benchmarks/multi_bench.js +++ b/benchmarks/multi_bench.js @@ -1,6 +1,6 @@ 'use strict' -const Buffer = require('safe-buffer').Buffer +const Buffer = require('buffer').Buffer const path = require('path') const RedisProcess = require('../test/lib/redis-process') let rp diff --git a/changelog.md b/changelog.md index 4829b294c4..94c9b8e8e0 100644 --- a/changelog.md +++ b/changelog.md @@ -2,17 +2,20 @@ ## v.3.0.0-alpha1 - XX XXX, 2017 -Version three is mainly a release to remove a lot of old cruft and open the doors for new features again. -It became a hassle to implement new things while supporting all the old and deprecated features. +Version three is mainly a release to remove a lot of old cruft and open the +doors for new features again. It became a hassle to implement new things while +supporting all the old and deprecated features. -Therefore this is going to a big breaking change. For most of these there's likely not much to change, -but some of the changes are significant like dropping support for callbacks! To mitigate this breakage -there's a migration library you can include. It restores e.g. support for callbacks and some of the dropped -options and it will warn you in case you use any removed feature or option. +Therefore this is going to a big breaking change. For most of these there's +likely not much to change, but you might encounter some of these changes! +To mitigate this breakage there's a migration library you can include. It +restores e.g. support for some of the dropped options and it will warn you +in case you use any removed feature or option. -It will not restore the support for old Node.js versions, the return value of (p)(un)subscribe calls, -the backpressure indicator and the changed connectTimeout behavior. It will also only partially restore -snake_case support and maybe more. +It will not restore the support for old Node.js versions, the return value of +(p)(un)subscribe calls, the backpressure indicator and the changed +connectTimeout behavior. It will also only partially restore snake_case support +and maybe more. Breaking Changes @@ -31,13 +34,16 @@ Breaking Changes - Removed `Redis.print` helper function - Removed backpressure indicator from function return value - Changed return value of `(p)(un)subscribe` - - Return an array with the number of current subscribed channels and an array with all affected channels + - Return an array with the number of current subscribed channels and an array + with all affected channels - Changed `connectTimeout` (connect_timeout) option - This timeout does not limit the total retry time anymore - From now on this will only set the stream timeout to connect to the host - Changed return value for `multi` and `batch` in case of an error - - If an error occurs for one of the calls, the result is from now on always going to be an error - - The result of all queries can be inspected on the error through the `result` attribute + - If an error occurs for one of the calls, the result is from now on always + going to be an error + - The result of all queries can be inspected on the error through the `result` + attribute - Only emit ready when all commands were truly send to Redis ## v.2.7.2 - 14 Mar, 2017 diff --git a/index.js b/index.js index bd646e710f..0fead38e44 100644 --- a/index.js +++ b/index.js @@ -1,17 +1,22 @@ 'use strict' // TODO: Replace all for in loops! -const Buffer = require('safe-buffer').Buffer +// TODO: Replace all `Error` with `RedisError` and improve errors in general +// We have to replace the error codes and make them coherent. +// We also have to use InterruptError s instead of AbortError s. +// The Error messages might be improved as well. +// TODO: Rewrite this to classes +const Buffer = require('buffer').Buffer const net = require('net') const tls = require('tls') const util = require('util') const utils = require('./lib/utils') const Command = require('./lib/command') -const Queue = require('double-ended-queue') +const Queue = require('denque') const errorClasses = require('./lib/customErrors') const EventEmitter = require('events') const Parser = require('redis-parser') -const commands = require('redis-commands') +const Errors = require('redis-errors') const debug = require('./lib/debug') const unifyOptions = require('./lib/createClient') const SUBSCRIBE_COMMANDS = { @@ -913,9 +918,10 @@ exports.createClient = function () { exports.RedisClient = RedisClient exports.Multi = require('./lib/multi') exports.AbortError = errorClasses.AbortError -exports.RedisError = Parser.RedisError -exports.ParserError = Parser.ParserError -exports.ReplyError = Parser.ReplyError +exports.RedisError = Errors.RedisError +exports.ParserError = Errors.ParserError +exports.ReplyError = Errors.ReplyError +exports.InterruptError = Errors.InterruptError // Add all redis commands / nodeRedis api to the client require('./lib/individualCommands') diff --git a/lib/customErrors.js b/lib/customErrors.js index 29ec813255..43583fb867 100644 --- a/lib/customErrors.js +++ b/lib/customErrors.js @@ -1,30 +1,27 @@ 'use strict' -const util = require('util') const assert = require('assert') -const RedisError = require('redis-parser').RedisError -const ADD_STACKTRACE = false +const RedisError = require('redis-errors').RedisError -function AbortError (obj, stack) { - assert(obj, 'The options argument is required') - assert.strictEqual(typeof obj, 'object', 'The options argument has to be of type object') - - RedisError.call(this, obj.message, ADD_STACKTRACE) - Object.defineProperty(this, 'message', { - value: obj.message || '', - configurable: true, - writable: true - }) - if (stack || stack === undefined) { - Error.captureStackTrace(this, AbortError) - } - for (let keys = Object.keys(obj), key = keys.pop(); key; key = keys.pop()) { - this[key] = obj[key] +class AbortError extends RedisError { + constructor (obj, stack) { + assert(obj, 'The options argument is required') + assert.strictEqual(typeof obj, 'object', 'The options argument has to be of type object') + super(obj.message) + Object.defineProperty(this, 'message', { + value: obj.message || '', + configurable: true, + writable: true + }) + if (stack || stack === undefined) { + Error.captureStackTrace(this, AbortError) + } + for (let keys = Object.keys(obj), key = keys.pop(); key; key = keys.pop()) { + this[key] = obj[key] + } } } -util.inherits(AbortError, RedisError) - Object.defineProperty(AbortError.prototype, 'name', { value: 'AbortError', configurable: true, diff --git a/lib/multi.js b/lib/multi.js index 11f2e1f84a..86509763f8 100644 --- a/lib/multi.js +++ b/lib/multi.js @@ -1,6 +1,6 @@ 'use strict' -const Queue = require('double-ended-queue') +const Queue = require('denque') const utils = require('./utils') const Command = require('./command') diff --git a/package.json b/package.json index 369d41cfa7..568b8aa2d1 100644 --- a/package.json +++ b/package.json @@ -26,24 +26,24 @@ "lint": "eslint . --fix" }, "dependencies": { - "double-ended-queue": "^2.1.0-0", + "denque": "^1.1.1", "redis-commands": "^1.2.0", - "redis-parser": "^2.6.0", - "safe-buffer": "^5.0.1" + "redis-errors": "^1.0.0", + "redis-parser": "^3.0.0" }, "engines": { "node": ">=6" }, "devDependencies": { "coveralls": "^2.11.2", + "cross-spawn": "^5.1.0", "intercept-stdout": "~0.1.2", "metrics": "^0.1.9", "mocha": "^3.2.0", "nyc": "^8.3.0", "standard": "^10.0.2", "tcp-port-used": "^0.1.2", - "uuid": "^2.0.1", - "win-spawn": "^2.0.0" + "uuid": "^2.0.1" }, "repository": { "type": "git", diff --git a/test/commands/client.spec.js b/test/commands/client.spec.js index 995209d71b..0accb0155c 100644 --- a/test/commands/client.spec.js +++ b/test/commands/client.spec.js @@ -1,6 +1,6 @@ 'use strict' -const Buffer = require('safe-buffer').Buffer +const Buffer = require('buffer').Buffer const assert = require('assert') const config = require('../lib/config') const helper = require('../helper') diff --git a/test/commands/hgetall.spec.js b/test/commands/hgetall.spec.js index 2ae1af4212..bc280e081e 100644 --- a/test/commands/hgetall.spec.js +++ b/test/commands/hgetall.spec.js @@ -1,6 +1,6 @@ 'use strict' -const Buffer = require('safe-buffer').Buffer +const Buffer = require('buffer').Buffer const assert = require('assert') const config = require('../lib/config') const helper = require('../helper') diff --git a/test/commands/hlen.spec.js b/test/commands/hlen.spec.js index c5c7432427..a6443532ad 100644 --- a/test/commands/hlen.spec.js +++ b/test/commands/hlen.spec.js @@ -1,6 +1,6 @@ 'use strict' -const Buffer = require('safe-buffer').Buffer +const Buffer = require('buffer').Buffer const config = require('../lib/config') const helper = require('../helper') const redis = config.redis diff --git a/test/commands/hset.spec.js b/test/commands/hset.spec.js index 2927981e13..9a24b631a9 100644 --- a/test/commands/hset.spec.js +++ b/test/commands/hset.spec.js @@ -1,6 +1,6 @@ 'use strict' -const Buffer = require('safe-buffer').Buffer +const Buffer = require('buffer').Buffer const assert = require('assert') const config = require('../lib/config') const helper = require('../helper') diff --git a/test/commands/monitor.spec.js b/test/commands/monitor.spec.js index f550623915..6c71458a96 100644 --- a/test/commands/monitor.spec.js +++ b/test/commands/monitor.spec.js @@ -1,6 +1,6 @@ 'use strict' -const Buffer = require('safe-buffer').Buffer +const Buffer = require('buffer').Buffer const assert = require('assert') const config = require('../lib/config') const helper = require('../helper') diff --git a/test/detect_buffers.spec.js b/test/detect_buffers.spec.js index 425c5e0e58..64daa23ff7 100644 --- a/test/detect_buffers.spec.js +++ b/test/detect_buffers.spec.js @@ -1,6 +1,6 @@ 'use strict' -const Buffer = require('safe-buffer').Buffer +const Buffer = require('buffer').Buffer const assert = require('assert') const config = require('./lib/config') const helper = require('./helper') diff --git a/test/lib/redis-process.js b/test/lib/redis-process.js index 6bd5c6c6d8..bd24a52e5e 100644 --- a/test/lib/redis-process.js +++ b/test/lib/redis-process.js @@ -4,7 +4,7 @@ const config = require('./config') const fs = require('fs') const path = require('path') -const spawn = require('win-spawn') +const spawn = require('cross-spawn') const tcpPortUsed = require('tcp-port-used') // wait for redis to be listening in diff --git a/test/multi.spec.js b/test/multi.spec.js index cbeaebf1d3..6ae31deea9 100644 --- a/test/multi.spec.js +++ b/test/multi.spec.js @@ -1,6 +1,6 @@ 'use strict' -const Buffer = require('safe-buffer').Buffer +const Buffer = require('buffer').Buffer const assert = require('assert') const config = require('./lib/config') const helper = require('./helper') diff --git a/test/node_redis.spec.js b/test/node_redis.spec.js index 058c9cf354..bdd93987ac 100644 --- a/test/node_redis.spec.js +++ b/test/node_redis.spec.js @@ -1,10 +1,9 @@ 'use strict' -const Buffer = require('safe-buffer').Buffer +const Buffer = require('buffer').Buffer const assert = require('assert') const fs = require('fs') const path = require('path') -const intercept = require('intercept-stdout') const config = require('./lib/config') const helper = require('./helper') const fork = require('child_process').fork diff --git a/test/pubsub.spec.js b/test/pubsub.spec.js index 3a09f8a77b..3e18aaa69a 100644 --- a/test/pubsub.spec.js +++ b/test/pubsub.spec.js @@ -1,6 +1,6 @@ 'use strict' -const Buffer = require('safe-buffer').Buffer +const Buffer = require('buffer').Buffer const assert = require('assert') const config = require('./lib/config') const helper = require('./helper') diff --git a/test/return_buffers.spec.js b/test/return_buffers.spec.js index 8b0d18f5b3..5b140f32c0 100644 --- a/test/return_buffers.spec.js +++ b/test/return_buffers.spec.js @@ -1,6 +1,6 @@ 'use strict' -const Buffer = require('safe-buffer').Buffer +const Buffer = require('buffer').Buffer const assert = require('assert') const config = require('./lib/config') const helper = require('./helper') diff --git a/test/utils.spec.js b/test/utils.spec.js index a0e15f435d..eceece0fce 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -1,7 +1,7 @@ 'use strict' const assert = require('assert') -const Queue = require('double-ended-queue') +const Queue = require('denque') const utils = require('../lib/utils') describe('utils.js', () => { @@ -72,7 +72,8 @@ describe('utils.js', () => { }) it('elements in the offline queue. Reply after the offline queue is empty and respect the commandObj callback', (done) => { - clientMock.offlineQueue.push(createCommandObj(), createCommandObj()) + clientMock.offlineQueue.push(createCommandObj()) + clientMock.offlineQueue.push(createCommandObj()) utils.replyInOrder(clientMock, () => { assert.strictEqual(clientMock.offlineQueue.length, 0) assert.strictEqual(resCount, 2) @@ -82,7 +83,9 @@ describe('utils.js', () => { }) it('elements in the offline queue. Reply after the offline queue is empty and respect the commandObj error emit', (done) => { - clientMock.commandQueue.push(createCommandObj(), createCommandObj(), createCommandObj()) + clientMock.commandQueue.push(createCommandObj()) + clientMock.commandQueue.push(createCommandObj()) + clientMock.commandQueue.push(createCommandObj()) utils.replyInOrder(clientMock, () => { assert.strictEqual(clientMock.commandQueue.length, 0) assert.strictEqual(errCount, 3) @@ -98,8 +101,10 @@ describe('utils.js', () => { }) it('elements in the offline queue and the commandQueue. Reply all other commands got handled respect the commandObj', (done) => { - clientMock.commandQueue.push(createCommandObj(), createCommandObj()) - clientMock.offlineQueue.push(createCommandObj(), createCommandObj()) + clientMock.commandQueue.push(createCommandObj()) + clientMock.commandQueue.push(createCommandObj()) + clientMock.offlineQueue.push(createCommandObj()) + clientMock.offlineQueue.push(createCommandObj()) utils.replyInOrder(clientMock, (err, res) => { if (err) throw err assert.strictEqual(clientMock.commandQueue.length, 0)