Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

add redisChannelPrefix option #438

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ export class Cli {
when: function(options) {
return options.corsAllow == true;
}
}, {
name: 'redisChannelPrefix',
default: '',
message: 'Enter the redis database prefix. if laravel 5.8, use `laravel_database_`, else leave it empty.',
}, {
name: 'file',
default: defaultFile,
Expand Down
3 changes: 2 additions & 1 deletion src/echo-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export class EchoServer {
allowOrigin: '',
allowMethods: '',
allowHeaders: ''
}
},
redisChannelPrefix: ''
};

/**
Expand Down
4 changes: 3 additions & 1 deletion src/subscribers/redis-subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export class RedisSubscriber implements Subscriber {
Log.info("Event: " + message.event);
}

callback(channel, message);
const internalChannel = this.options.redisChannelPrefix ? channel.replace(new RegExp(`^${this.options.redisChannelPrefix}`), '') : channel;

Choose a reason for hiding this comment

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

I like that this is simple by not touching a lot of code, but is using regexp performant enough for potentially higher traffic sites?

Copy link
Author

Choose a reason for hiding this comment

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

I'm sorry. I have not yet consider the performance impact. In fact, I'm wondering how can I do a test about this. If you got some idea, let me know. I would like to do a test.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried doing a simple test with a loop for the line in question:

var start = Date.now();

var redisChannelPrefix = 'laravel_database_';
var channel = 'laravel_database_private-user.1234';
var i;

for (i = 0; i < 1000000; i++) {
  var result = redisChannelPrefix ? channel.replace(new RegExp(`^${redisChannelPrefix}`), '') : channel;
}

console.log(Date.now() - start);

It shows that it takes around 300 milliseconds (0.3 seconds) to run the RegExp line 1.000.000 times.

In my book that is fine.

Choose a reason for hiding this comment

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

Cool! I like this, but it's obviously up to the maintainer then


callback(internalChannel, message);
} catch (e) {
if (this.options.devMode) {
Log.info("No JSON message");
Expand Down