You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
More fixes for socket issue (#2710)
* more typing fixes * try to redo typing a bit and genericize to make better * use genericized cluster options for cluster as well
This commit is contained in:
@@ -14,6 +14,8 @@ import { setTimeout } from 'node:timers/promises';
|
||||
import RedisSentinelModule from './module'
|
||||
import { RedisVariadicArgument } from '../commands/generic-transformers';
|
||||
import { WaitQueue } from './wait-queue';
|
||||
import { TcpNetConnectOpts } from 'node:net';
|
||||
import { RedisTcpSocketOptions } from '../client/socket';
|
||||
|
||||
interface ClientInfo {
|
||||
id: number;
|
||||
@@ -578,8 +580,8 @@ class RedisSentinelInternal<
|
||||
}
|
||||
|
||||
readonly #name: string;
|
||||
readonly #nodeClientOptions: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>;
|
||||
readonly #sentinelClientOptions: RedisClientOptions<typeof RedisSentinelModule, F, S, RESP, TYPE_MAPPING>;
|
||||
readonly #nodeClientOptions: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING, RedisTcpSocketOptions>;
|
||||
readonly #sentinelClientOptions: RedisClientOptions<typeof RedisSentinelModule, F, S, RESP, TYPE_MAPPING, RedisTcpSocketOptions>;
|
||||
readonly #scanInterval: number;
|
||||
readonly #passthroughClientErrorEvents: boolean;
|
||||
|
||||
@@ -624,12 +626,12 @@ class RedisSentinelInternal<
|
||||
this.#scanInterval = options.scanInterval ?? 0;
|
||||
this.#passthroughClientErrorEvents = options.passthroughClientErrorEvents ?? false;
|
||||
|
||||
this.#nodeClientOptions = options.nodeClientOptions ? Object.assign({} as RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>, options.nodeClientOptions) : {};
|
||||
this.#nodeClientOptions = options.nodeClientOptions ? Object.assign({} as RedisClientOptions<M, F, S, RESP, TYPE_MAPPING, RedisTcpSocketOptions>, options.nodeClientOptions) : {};
|
||||
if (this.#nodeClientOptions.url !== undefined) {
|
||||
throw new Error("invalid nodeClientOptions for Sentinel");
|
||||
}
|
||||
|
||||
this.#sentinelClientOptions = options.sentinelClientOptions ? Object.assign({} as RedisClientOptions<typeof RedisSentinelModule, F, S, RESP, TYPE_MAPPING>, options.sentinelClientOptions) : {};
|
||||
this.#sentinelClientOptions = options.sentinelClientOptions ? Object.assign({} as RedisClientOptions<typeof RedisSentinelModule, F, S, RESP, TYPE_MAPPING, RedisTcpSocketOptions>, options.sentinelClientOptions) : {};
|
||||
this.#sentinelClientOptions.modules = RedisSentinelModule;
|
||||
|
||||
if (this.#sentinelClientOptions.url !== undefined) {
|
||||
@@ -754,7 +756,8 @@ class RedisSentinelInternal<
|
||||
await this.#reset();
|
||||
continue;
|
||||
}
|
||||
this.#trace("attemping to send command to " + client.options?.socket?.host + ":" + client.options?.socket?.port)
|
||||
const sockOpts = client.options?.socket as TcpNetConnectOpts | undefined;
|
||||
this.#trace("attemping to send command to " + sockOpts?.host + ":" + sockOpts?.port)
|
||||
|
||||
try {
|
||||
/*
|
||||
@@ -1198,7 +1201,8 @@ class RedisSentinelInternal<
|
||||
|
||||
if (replicaCloseSet.has(str) || !replica.isOpen) {
|
||||
if (replica.isOpen) {
|
||||
this.#trace(`destroying replica client to ${replica.options?.socket?.host}:${replica.options?.socket?.port}`);
|
||||
const sockOpts = replica.options?.socket as TcpNetConnectOpts | undefined;
|
||||
this.#trace(`destroying replica client to ${sockOpts?.host}:${sockOpts?.port}`);
|
||||
replica.destroy()
|
||||
}
|
||||
if (!removedSet.has(str)) {
|
||||
|
@@ -3,6 +3,7 @@ import { CommandOptions } from '../client/commands-queue';
|
||||
import { CommandSignature, CommanderConfig, RedisFunctions, RedisModules, RedisScripts, RespVersions, TypeMapping } from '../RESP/types';
|
||||
import COMMANDS from '../commands';
|
||||
import RedisSentinel, { RedisSentinelClient } from '.';
|
||||
import { RedisTcpSocketOptions } from '../client/socket';
|
||||
|
||||
export interface RedisNode {
|
||||
host: string;
|
||||
@@ -31,11 +32,11 @@ export interface RedisSentinelOptions<
|
||||
/**
|
||||
* The configuration values for every node in the cluster. Use this for example when specifying an ACL user to connect with
|
||||
*/
|
||||
nodeClientOptions?: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>;
|
||||
nodeClientOptions?: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING, RedisTcpSocketOptions>;
|
||||
/**
|
||||
* The configuration values for every sentinel in the cluster. Use this for example when specifying an ACL user to connect with
|
||||
*/
|
||||
sentinelClientOptions?: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>;
|
||||
sentinelClientOptions?: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING, RedisTcpSocketOptions>;
|
||||
/**
|
||||
* The number of clients connected to the master node
|
||||
*/
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { Command, RedisFunction, RedisScript, RespVersions } from '../RESP/types';
|
||||
import { RedisSocketOptions } from '../client/socket';
|
||||
import { RedisSocketOptions, RedisTcpSocketOptions } from '../client/socket';
|
||||
import { functionArgumentsPrefix, getTransformReply, scriptArgumentsPrefix } from '../commander';
|
||||
import { NamespaceProxySentinel, NamespaceProxySentinelClient, NodeInfo, ProxySentinel, ProxySentinelClient, RedisNode } from './types';
|
||||
|
||||
@@ -27,9 +27,11 @@ export function createNodeList(nodes: Array<NodeInfo>) {
|
||||
}
|
||||
|
||||
export function clientSocketToNode(socket: RedisSocketOptions): RedisNode {
|
||||
const s = socket as RedisTcpSocketOptions;
|
||||
|
||||
return {
|
||||
host: socket.host!,
|
||||
port: socket.port!
|
||||
host: s.host!,
|
||||
port: s.port!
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user