Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,21 @@ function adapter(uri, opts){

this.uid = uid;
this.prefix = prefix;
this.channel = prefix + '#' + nsp.name + '#';
if (String.prototype.startsWith) {
this.channelMatches = function (messageChannel, subscribedChannel) {
return messageChannel.startsWith(subscribedChannel);
}
} else { // Fallback to slow indexOf impl for older Node.js
this.channelMatches = function (messageChannel, subscribedChannel) {
return messageChannel.indexOf(subscribedChannel) === 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just using substr ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rauchg Fixed! f2e7a4c

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rauchg I referred to https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith

I leant something from your suggestion, thank you!

}
this.pubClient = pub;
this.subClient = sub;

var self = this;
sub.subscribe(prefix + '#' + nsp.name + '#', function(err){
sub.subscribe(this.channel, function(err){
if (err) self.emit('error', err);
});
sub.on(subEvent, this.onmessage.bind(this));
Expand All @@ -91,6 +101,9 @@ function adapter(uri, opts){
*/

Redis.prototype.onmessage = function(channel, msg){
if (!this.channelMatches(channel.toString(), this.channel)) {
return debug('ignore different channel');
}
var args = msgpack.decode(msg);
var packet;

Expand Down