You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-12-12 21:21:15 +03:00
fix: parse database from Redis URL (#3052)
This commit is contained in:
@@ -167,6 +167,14 @@ describe('Client', () => {
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('DB in URL should be parsed', async () => {
|
||||
const client = RedisClient.create({
|
||||
url: 'redis://user:secret@localhost:6379/5'
|
||||
});
|
||||
|
||||
assert.equal(client?.options?.database, 5);
|
||||
})
|
||||
});
|
||||
|
||||
describe('parseOptions', () => {
|
||||
|
||||
@@ -496,8 +496,14 @@ export default class RedisClient<
|
||||
this._commandOptions = options.commandOptions;
|
||||
}
|
||||
|
||||
if (options) {
|
||||
return RedisClient.parseOptions(options);
|
||||
if (options?.url) {
|
||||
const parsedOptions = RedisClient.parseOptions(options);
|
||||
|
||||
if (parsedOptions?.database) {
|
||||
this._self.#selectedDB = parsedOptions.database;
|
||||
}
|
||||
|
||||
return parsedOptions;
|
||||
}
|
||||
|
||||
return options;
|
||||
|
||||
Reference in New Issue
Block a user