You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
fix #1659 - add support for db-number in client options url
This commit is contained in:
@@ -6,8 +6,6 @@ import { ConnectionTimeoutError, ClientClosedError } from './errors';
|
||||
import { promiseTimeout } from './utils';
|
||||
|
||||
export interface RedisSocketCommonOptions {
|
||||
username?: string;
|
||||
password?: string;
|
||||
connectTimeout?: number;
|
||||
noDelay?: boolean;
|
||||
keepAlive?: number | false;
|
||||
@@ -19,10 +17,6 @@ export interface RedisNetSocketOptions extends RedisSocketCommonOptions {
|
||||
host?: string;
|
||||
}
|
||||
|
||||
export interface RedisUrlSocketOptions extends RedisSocketCommonOptions {
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface RedisUnixSocketOptions extends RedisSocketCommonOptions {
|
||||
path: string;
|
||||
}
|
||||
@@ -31,7 +25,7 @@ export interface RedisTlsSocketOptions extends RedisNetSocketOptions, tls.Secure
|
||||
tls: true;
|
||||
}
|
||||
|
||||
export type RedisSocketOptions = RedisNetSocketOptions | RedisUrlSocketOptions | RedisUnixSocketOptions | RedisTlsSocketOptions;
|
||||
export type RedisSocketOptions = RedisNetSocketOptions | RedisUnixSocketOptions | RedisTlsSocketOptions;
|
||||
|
||||
interface CreateSocketReturn<T> {
|
||||
connectEvent: string;
|
||||
@@ -44,14 +38,6 @@ export default class RedisSocket extends EventEmitter {
|
||||
static #initiateOptions(options?: RedisSocketOptions): RedisSocketOptions {
|
||||
options ??= {};
|
||||
if (!RedisSocket.#isUnixSocket(options)) {
|
||||
if (RedisSocket.#isUrlSocket(options)) {
|
||||
const url = new URL(options.url);
|
||||
(options as RedisNetSocketOptions).port = Number(url.port);
|
||||
(options as RedisNetSocketOptions).host = url.hostname;
|
||||
options.username = url.username;
|
||||
options.password = url.password;
|
||||
}
|
||||
|
||||
(options as RedisNetSocketOptions).port ??= 6379;
|
||||
(options as RedisNetSocketOptions).host ??= '127.0.0.1';
|
||||
}
|
||||
@@ -67,10 +53,6 @@ export default class RedisSocket extends EventEmitter {
|
||||
return Math.min(retries * 50, 500);
|
||||
}
|
||||
|
||||
static #isUrlSocket(options: RedisSocketOptions): options is RedisUrlSocketOptions {
|
||||
return Object.prototype.hasOwnProperty.call(options, 'url');
|
||||
}
|
||||
|
||||
static #isUnixSocket(options: RedisSocketOptions): options is RedisUnixSocketOptions {
|
||||
return Object.prototype.hasOwnProperty.call(options, 'path');
|
||||
}
|
||||
|
Reference in New Issue
Block a user