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

feat: always return strings from "message" listener

Listening to "messageBuffer" returns Buffers
This commit is contained in:
Ruben Bridgewater
2017-05-28 08:41:01 +02:00
parent 6796f8806a
commit 5d6f072e56
3 changed files with 5 additions and 3 deletions

View File

@@ -62,14 +62,14 @@ function returnPubSub (client, reply) {
// 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
if (typeof reply[1] !== 'string') {
client.emit('message', reply[1].toString(), reply[2].toString())
client.emit('messageBuffer', reply[1], reply[2])
} else {
client.emit('message', reply[1], reply[2])
}
} else if (type === 'pmessage') { // Pattern, 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 (typeof reply[1] !== 'string') {
client.emit('pmessage', reply[1].toString(), reply[2].toString(), reply[3].toString())
client.emit('pmessageBuffer', reply[1], reply[2], reply[3])
} else {