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', () => {
|
describe('parseOptions', () => {
|
||||||
|
|||||||
@@ -496,8 +496,14 @@ export default class RedisClient<
|
|||||||
this._commandOptions = options.commandOptions;
|
this._commandOptions = options.commandOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options) {
|
if (options?.url) {
|
||||||
return RedisClient.parseOptions(options);
|
const parsedOptions = RedisClient.parseOptions(options);
|
||||||
|
|
||||||
|
if (parsedOptions?.database) {
|
||||||
|
this._self.#selectedDB = parsedOptions.database;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsedOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
|
|||||||
Reference in New Issue
Block a user