You've already forked node-redis
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:
@@ -58,6 +58,8 @@ Breaking Changes
|
||||
- `host:` is now `host`
|
||||
- Changed the `serverInfo` into a nested object and to parse numbers
|
||||
- Changed the `serverInfo.versions` to `serverInfo.version`
|
||||
- Changed the `message` and `pmessage` listener to always return a string
|
||||
If you want to receive a buffer, please listen to the `messageBuffer` or `pmessageBuffer`
|
||||
- Using `.end` without the flush parameter is now going to throw an TypeError
|
||||
- Only emit ready when all commands were truly send to Redis
|
||||
|
||||
|
@@ -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 {
|
||||
|
@@ -444,7 +444,7 @@ describe('publish/subscribe', () => {
|
||||
// sub2 is counted twice as it subscribed with psubscribe and subscribe
|
||||
pub.publish('/foo', 'hello world').then(helper.isNumber(3))
|
||||
})
|
||||
sub2.on('pmessage', (pattern, channel, message) => {
|
||||
sub2.on('pmessageBuffer', (pattern, channel, message) => {
|
||||
assert.strictEqual(pattern.inspect(), Buffer.from('*').inspect())
|
||||
assert.strictEqual(channel.inspect(), Buffer.from('/foo').inspect())
|
||||
assert.strictEqual(message.inspect(), Buffer.from('hello world').inspect())
|
||||
|
Reference in New Issue
Block a user