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

feat: consolidate pubsub emitters

This commit is contained in:
Ruben Bridgewater
2017-05-28 09:00:32 +02:00
parent 5d6f072e56
commit 4e593587cb
4 changed files with 29 additions and 27 deletions

View File

@@ -58,9 +58,6 @@ 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 (typeof reply[1] !== 'string') {
client.emit('message', reply[1].toString(), reply[2].toString())
@@ -68,12 +65,12 @@ function returnPubSub (client, reply) {
} else {
client.emit('message', reply[1], reply[2])
}
} else if (type === 'pmessage') { // Pattern, channel, message
} else if (type === 'pmessage') { // Channel, message, pattern
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])
client.emit('message', reply[2].toString(), reply[3].toString(), reply[1].toString())
client.emit('messageBuffer', reply[2], reply[3], reply[1])
} else {
client.emit('pmessage', reply[1], reply[2], reply[3])
client.emit('message', reply[2], reply[3], reply[1])
}
} else {
subscribeUnsubscribe(client, reply, type)