Skip to content

Commit

Permalink
fix(redis-connection): run the load command for reused redis client
Browse files Browse the repository at this point in the history
  • Loading branch information
jtfell authored and manast committed Jun 5, 2020
1 parent 5e808ad commit fab9bba
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/gitbook/guide/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const myQueue = new Queue('myqueue', { connection: {
port: 32856
}});

const myWorker = new Worker('myworker', { connection: {
const myWorker = new Worker('myworker', async (job)=>{}, { connection: {
host: myredis.taskforce.run,
port: 32856
}});
Expand Down
2 changes: 1 addition & 1 deletion src/classes/redis-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export class RedisConnection extends EventEmitter {
} else {
async function handleReady() {
client.removeListener('error', handleError);
await load(client);
resolve();
}

Expand All @@ -71,6 +70,7 @@ export class RedisConnection extends EventEmitter {
}

await RedisConnection.waitUntilReady(this._client);
await load(this._client);

if (opts && opts.skipVersionCheck !== true && !this.closing) {
const version = await this.getRedisVersion();
Expand Down
5 changes: 4 additions & 1 deletion src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export const load = async function(client: Redis) {
const scripts = await loadScripts(__dirname);

scripts.forEach((command: Command) => {
client.defineCommand(command.name, command.options);
// Only define the command if not already defined
if (!(client as any)[command.name]) {
client.defineCommand(command.name, command.options);
}
});
};

Expand Down

0 comments on commit fab9bba

Please sign in to comment.