Unexpected deletion of the keyPrefix option
Created by: nekocode
Description
In latest code, the instantiation of queue will deleted keyPrefix
property of the options object which we passed to the second function parameter:
if (_.isString(url)) {
// ...
} else {
opts = url || {};
}
// ...
delete opts.redis.keyPrefix;
It causes that we will loss the keyPrefix
if we use one options instance to initialize multiple queues.
I think we should use a deep cloned options object to make sure the passed one will not be changed.
Minimal, Working Test code to reproduce the issue.
I wrote a test to reproduce the issue: https://github.com/nekocode/bull/commit/06feb3176c85891b7180b72ea7c20d3a4514c089
it('should not change the options object', async () => {
const originalOptions = { redis: { keyPrefix: 'myQ' } };
const options = _.cloneDeep(originalOptions);
let queue = new Queue('q', 'redis://127.0.0.1', options);
expect(_.isEqual(options, originalOptions)).to.be.true;
await queue.close();
queue = new Queue('q', options);
expect(_.isEqual(options, originalOptions)).to.be.true;
await queue.close();
});
Bull version
3.22.9 (latest)