diff --git a/lib/pubsub.js b/lib/pubsub.js index f4b593302d..7a9a455467 100644 --- a/lib/pubsub.js +++ b/lib/pubsub.js @@ -58,6 +58,9 @@ function subscribeUnsubscribe (client, reply, type) { function returnPubSub (client, reply) { const type = reply[0].toString() + // TODO: Consolidate `message` and `pmessage`. + // It would be more straight forward to only listen to a single "message" + // and in case of a "pmessage" a third argument would be passed (the pattern). if (type === 'message') { // Channel, message if (!client._options.returnBuffers || client.messageBuffers) { // Backwards compatible. Refactor this in v.3 to always return a string on the normal emitter client.emit('message', reply[1].toString(), reply[2].toString()) diff --git a/lib/utils.js b/lib/utils.js index 41d5ab55c0..1990ea43b2 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -139,7 +139,7 @@ function warn (client, msg) { * @returns {string|number|null|Buffer|any[]|object} */ function handleReply (client, reply, command) { - if (client._options.detectBuffers === true && command.bufferArgs === false) { // client.messageBuffers + if (client._options.detectBuffers === true && command.bufferArgs === false || client.messageBuffers === true) { reply = replyToStrings(reply) } diff --git a/test/pubsub.spec.js b/test/pubsub.spec.js index 40e99bed3e..6deb53b9a7 100644 --- a/test/pubsub.spec.js +++ b/test/pubsub.spec.js @@ -458,9 +458,8 @@ describe('publish/subscribe', () => { const end = helper.callFuncAfter(done, 3) const data = Array(10000).join('äüs^öéÉÉ`e') sub.set('foo', data).then(() => { - sub.get('foo') + sub.get('foo').then((res) => assert.strictEqual(typeof res, 'string')) sub._stream.once('data', () => { - // TODO: Improve this test to test if a buffer is returned for any call assert.strictEqual(sub.messageBuffers, false) assert.strictEqual(sub.shouldBuffer, false) sub.on('pmessageBuffer', (pattern, channel, message) => {