Skip to content

Commit 68cebf7

Browse files
authored
fix: parse database from Redis URL (#3052)
1 parent 2f10632 commit 68cebf7

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/client/lib/client/index.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ describe('Client', () => {
167167
}
168168
);
169169
});
170+
171+
it('DB in URL should be parsed', async () => {
172+
const client = RedisClient.create({
173+
url: 'redis://user:secret@localhost:6379/5'
174+
});
175+
176+
assert.equal(client?.options?.database, 5);
177+
})
170178
});
171179

172180
describe('parseOptions', () => {

packages/client/lib/client/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,14 @@ export default class RedisClient<
496496
this._commandOptions = options.commandOptions;
497497
}
498498

499-
if (options) {
500-
return RedisClient.parseOptions(options);
499+
if (options?.url) {
500+
const parsedOptions = RedisClient.parseOptions(options);
501+
502+
if (parsedOptions?.database) {
503+
this._self.#selectedDB = parsedOptions.database;
504+
}
505+
506+
return parsedOptions;
501507
}
502508

503509
return options;

0 commit comments

Comments
 (0)