You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
ref #1741 - fix socket options type
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import COMMANDS from './commands';
|
||||
import { RedisCommand, RedisCommandArguments, RedisCommandRawReply, RedisCommandReply, RedisModules, RedisPlugins, RedisScript, RedisScripts } from '../commands';
|
||||
import RedisSocket, { RedisSocketOptions, RedisNetSocketOptions, RedisTlsSocketOptions } from './socket';
|
||||
import RedisSocket, { RedisSocketOptions, RedisTlsSocketOptions } from './socket';
|
||||
import RedisCommandsQueue, { PubSubListener, PubSubSubscribeCommands, PubSubUnsubscribeCommands, QueueCommandOptions } from './commands-queue';
|
||||
import RedisClientMultiCommand, { RedisClientMultiCommandType } from './multi-command';
|
||||
import { RedisMultiQueuedCommand } from '../multi-command';
|
||||
@@ -13,6 +13,7 @@ import { extendWithCommands, extendWithModulesAndScripts, LegacyCommandArguments
|
||||
import { Pool, Options as PoolOptions, createPool } from 'generic-pool';
|
||||
import { ClientClosedError, DisconnectsClientError } from '../errors';
|
||||
import { URL } from 'url';
|
||||
import { TcpSocketConnectOpts } from 'net';
|
||||
|
||||
export interface RedisClientOptions<M extends RedisModules, S extends RedisScripts> extends RedisPlugins<M, S> {
|
||||
url?: string;
|
||||
@@ -97,7 +98,7 @@ export default class RedisClient<M extends RedisModules, S extends RedisScripts>
|
||||
}
|
||||
|
||||
if (port) {
|
||||
(parsed.socket as RedisNetSocketOptions).port = Number(port);
|
||||
(parsed.socket as TcpSocketConnectOpts).port = Number(port);
|
||||
}
|
||||
|
||||
if (username) {
|
||||
|
@@ -13,20 +13,13 @@ export interface RedisSocketCommonOptions {
|
||||
reconnectStrategy?(retries: number): number | Error;
|
||||
}
|
||||
|
||||
export interface RedisNetSocketOptions extends RedisSocketCommonOptions {
|
||||
port?: number;
|
||||
host?: string;
|
||||
}
|
||||
export type RedisNetSocketOptions = Partial<net.SocketConnectOpts>;
|
||||
|
||||
export interface RedisUnixSocketOptions extends RedisSocketCommonOptions {
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface RedisTlsSocketOptions extends RedisNetSocketOptions, tls.SecureContextOptions, tls.CommonConnectionOptions {
|
||||
export interface RedisTlsSocketOptions extends RedisSocketCommonOptions, tls.ConnectionOptions {
|
||||
tls: true;
|
||||
}
|
||||
|
||||
export type RedisSocketOptions = RedisNetSocketOptions | RedisUnixSocketOptions | RedisTlsSocketOptions;
|
||||
export type RedisSocketOptions = RedisSocketCommonOptions & (RedisNetSocketOptions | RedisTlsSocketOptions);
|
||||
|
||||
interface CreateSocketReturn<T> {
|
||||
connectEvent: string;
|
||||
@@ -38,9 +31,9 @@ export type RedisSocketInitiator = () => Promise<void>;
|
||||
export default class RedisSocket extends EventEmitter {
|
||||
static #initiateOptions(options?: RedisSocketOptions): RedisSocketOptions {
|
||||
options ??= {};
|
||||
if (!RedisSocket.#isUnixSocket(options)) {
|
||||
(options as RedisNetSocketOptions).port ??= 6379;
|
||||
(options as RedisNetSocketOptions).host ??= '127.0.0.1';
|
||||
if (!(options as net.IpcSocketConnectOpts).path) {
|
||||
(options as net.TcpSocketConnectOpts).port ??= 6379;
|
||||
(options as net.TcpSocketConnectOpts).host ??= '127.0.0.1';
|
||||
}
|
||||
|
||||
options.connectTimeout ??= 5000;
|
||||
@@ -54,10 +47,6 @@ export default class RedisSocket extends EventEmitter {
|
||||
return Math.min(retries * 50, 500);
|
||||
}
|
||||
|
||||
static #isUnixSocket(options: RedisSocketOptions): options is RedisUnixSocketOptions {
|
||||
return Object.prototype.hasOwnProperty.call(options, 'path');
|
||||
}
|
||||
|
||||
static #isTlsSocket(options: RedisSocketOptions): options is RedisTlsSocketOptions {
|
||||
return (options as RedisTlsSocketOptions).tls === true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user