-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Update patterns with fix for v4 #2208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Ensure opts are always passed into redis, allowing for enableReadyCheck and maxRetriesPerRequest to be updated correctly for v4
bfd9a0c
to
e0c55d8
Compare
Hmm, but with your change there is no re-use of the redis instances since you are creating new ones all the time. |
Not sure what you mean, there is still re-use. The redis instances are still cached, they are only created once and only if they have not been created yet. You can try it yourself, it works as expected:
|
Reuse in this context means reuse between different Queues, within the same Queue you do not need to do anything special... |
Redis is indeed reused between different Queues in this case. This can be verified with some simple logging:
Or by spying on redis:
|
And what is your explanation for this? |
Didn't really think such simple debugging required an explanation, allow me: There are many things a developer might do to determine whether a piece of code is being run or called. Temporarily adding in a few Another approach to debugging code and determining what has been run is to use a spy. In this case I am using the spy from If there is further explanation you require I am more than happy to oblige. However, I would encourage you to run this code yourself. That way, you can determine for yourself how this code and other bull code works and if it does the things you expect. |
Thanks for the long explanation, but it did not answer my question, which was, "what is your explanation for this (behaviour)? As in, how is it possible that the redis instances are cached in the "opts" object that you are passing to the queue. Anyway, it seems that the culprit is the memoization that is working on a shallow copy of redis options: return function(type) {
return function() {
// Memoized connection
if (connections[type] != null) {
return connections[type];
}
const clientOptions = _.assign({}, options.redis);
clientOptions.connectionName = this.clientName();
const client = (connections[type] = createClient(type, clientOptions)); So when instantiating another queue with the same opts object, results in that it returns the same redis instance. This is a bug that should be resolved by deep cloning the options before memoizing... The documentation text is therefore correct, and it is the proper way to reuse connections, whereas current behaviour is a bug. |
The scope that the "opts" object is created in has 2 variables declared as
The existing code in the patterns docs does not work and produces an error when run. The caching setup I added here exists only to delay creating the Redis object until the redisOpts object is avaible from the createClient. This opts object contains the
Neither the existing code in the docs, nor my updates handle memoizing different opts correctly. Again I encourage you to run the code and see what happens. The code provided in the docs does not work. If this is a bug somewhere else, I would be more than happy to have a fix setup. But they way I see it, the only way this check will pass is if the |
Ok, sorry you are right, I did not read your changes correctly. |
🎉 This PR is included in version 4.1.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Ensure opts are passed into redis in the example code for reusing redis connections.