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

fix: messageBuffers is now handled properly again

This commit is contained in:
Ruben Bridgewater
2017-05-28 08:32:38 +02:00
parent b2e18344d9
commit 6796f8806a
3 changed files with 5 additions and 3 deletions

View File

@@ -58,6 +58,9 @@ function subscribeUnsubscribe (client, reply, type) {
function returnPubSub (client, reply) { function returnPubSub (client, reply) {
const type = reply[0].toString() 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 (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 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()) client.emit('message', reply[1].toString(), reply[2].toString())

View File

@@ -139,7 +139,7 @@ function warn (client, msg) {
* @returns {string|number|null|Buffer|any[]|object} * @returns {string|number|null|Buffer|any[]|object}
*/ */
function handleReply (client, reply, command) { 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) reply = replyToStrings(reply)
} }

View File

@@ -458,9 +458,8 @@ describe('publish/subscribe', () => {
const end = helper.callFuncAfter(done, 3) const end = helper.callFuncAfter(done, 3)
const data = Array(10000).join('äüs^öéÉÉ`e') const data = Array(10000).join('äüs^öéÉÉ`e')
sub.set('foo', data).then(() => { sub.set('foo', data).then(() => {
sub.get('foo') sub.get('foo').then((res) => assert.strictEqual(typeof res, 'string'))
sub._stream.once('data', () => { 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.messageBuffers, false)
assert.strictEqual(sub.shouldBuffer, false) assert.strictEqual(sub.shouldBuffer, false)
sub.on('pmessageBuffer', (pattern, channel, message) => { sub.on('pmessageBuffer', (pattern, channel, message) => {