You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
fix socket type issues
This commit is contained in:
@@ -5,6 +5,7 @@ import { EventEmitter } from 'node:stream';
|
||||
import { ChannelListeners, PUBSUB_TYPE, PubSubTypeListeners } from '../client/pub-sub';
|
||||
import { RedisArgument, RedisFunctions, RedisModules, RedisScripts, RespVersions, TypeMapping } from '../RESP/types';
|
||||
import calculateSlot from 'cluster-key-slot';
|
||||
import { RedisSocketOptions } from '../client/socket';
|
||||
|
||||
interface NodeAddress {
|
||||
host: string;
|
||||
@@ -102,8 +103,8 @@ export default class RedisClusterSlots<
|
||||
> {
|
||||
static #SLOTS = 16384;
|
||||
|
||||
readonly #options: RedisClusterOptions<M, F, S, RESP, TYPE_MAPPING>;
|
||||
readonly #clientFactory: ReturnType<typeof RedisClient.factory<M, F, S, RESP>>;
|
||||
readonly #options;
|
||||
readonly #clientFactory;
|
||||
readonly #emit: EventEmitter['emit'];
|
||||
slots = new Array<Shard<M, F, S, RESP, TYPE_MAPPING>>(RedisClusterSlots.#SLOTS);
|
||||
masters = new Array<MasterNode<M, F, S, RESP, TYPE_MAPPING>>();
|
||||
@@ -271,7 +272,7 @@ export default class RedisClusterSlots<
|
||||
return {
|
||||
...this.#options.defaults,
|
||||
...options,
|
||||
socket
|
||||
socket: socket as RedisSocketOptions
|
||||
};
|
||||
}
|
||||
|
||||
@@ -316,8 +317,7 @@ export default class RedisClusterSlots<
|
||||
host: node.host,
|
||||
port: node.port
|
||||
},
|
||||
readonly,
|
||||
RESP: this.#options.RESP
|
||||
readonly
|
||||
})
|
||||
).on('error', err => console.error(err));
|
||||
}
|
||||
|
@@ -649,19 +649,15 @@ class RedisSentinelInternal<
|
||||
}
|
||||
|
||||
#createClient(node: RedisNode, clientOptions: RedisClientOptions, reconnectStrategy?: undefined | false) {
|
||||
const options = { ...clientOptions } as RedisClientOptions;
|
||||
|
||||
if (clientOptions.socket) {
|
||||
options.socket = { ...clientOptions.socket };
|
||||
} else {
|
||||
options.socket = {};
|
||||
return RedisClient.create({
|
||||
...clientOptions,
|
||||
socket: {
|
||||
...clientOptions.socket,
|
||||
host: node.host,
|
||||
port: node.port,
|
||||
reconnectStrategy
|
||||
}
|
||||
|
||||
options.socket.host = node.host;
|
||||
options.socket.port = node.port;
|
||||
options.socket.reconnectStrategy = reconnectStrategy;
|
||||
|
||||
return RedisClient.create(options);
|
||||
});
|
||||
}
|
||||
|
||||
getClientLease(): ClientInfo | Promise<ClientInfo> {
|
||||
@@ -1332,16 +1328,16 @@ export class RedisSentinelFactory extends EventEmitter {
|
||||
|
||||
async updateSentinelRootNodes() {
|
||||
for (const node of this.#sentinelRootNodes) {
|
||||
const options: RedisClientOptions = { ...this.options.sentinelClientOptions };
|
||||
if (options.socket === undefined) {
|
||||
options.socket = {};
|
||||
}
|
||||
options.socket.host = node.host;
|
||||
options.socket.port = node.port;
|
||||
options.socket.reconnectStrategy = false;
|
||||
options.modules = RedisSentinelModule;
|
||||
|
||||
const client = RedisClient.create(options).on('error', (err) => this.emit(`updateSentinelRootNodes: ${err}`));
|
||||
const client = RedisClient.create({
|
||||
...this.options.sentinelClientOptions,
|
||||
socket: {
|
||||
...this.options.sentinelClientOptions?.socket,
|
||||
host: node.host,
|
||||
port: node.port,
|
||||
reconnectStrategy: false
|
||||
},
|
||||
modules: RedisSentinelModule
|
||||
}).on('error', (err) => this.emit(`updateSentinelRootNodes: ${err}`));
|
||||
try {
|
||||
await client.connect();
|
||||
} catch {
|
||||
@@ -1367,16 +1363,16 @@ export class RedisSentinelFactory extends EventEmitter {
|
||||
let connected = false;
|
||||
|
||||
for (const node of this.#sentinelRootNodes) {
|
||||
const options: RedisClientOptions = { ...this.options.sentinelClientOptions };
|
||||
if (options.socket === undefined) {
|
||||
options.socket = {};
|
||||
}
|
||||
options.socket.host = node.host;
|
||||
options.socket.port = node.port;
|
||||
options.socket.reconnectStrategy = false;
|
||||
options.modules = RedisSentinelModule;
|
||||
|
||||
const client = RedisClient.create(options).on('error', err => this.emit(`getMasterNode: ${err}`));
|
||||
const client = RedisClient.create({
|
||||
...this.options.sentinelClientOptions,
|
||||
socket: {
|
||||
...this.options.sentinelClientOptions?.socket,
|
||||
host: node.host,
|
||||
port: node.port,
|
||||
reconnectStrategy: false
|
||||
},
|
||||
modules: RedisSentinelModule
|
||||
}).on('error', err => this.emit(`getMasterNode: ${err}`));
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
@@ -1412,30 +1408,30 @@ export class RedisSentinelFactory extends EventEmitter {
|
||||
|
||||
async getMasterClient() {
|
||||
const master = await this.getMasterNode();
|
||||
const options: RedisClientOptions = { ...this.options.nodeClientOptions };
|
||||
if (options.socket === undefined) {
|
||||
options.socket = {};
|
||||
return RedisClient.create({
|
||||
...this.options.nodeClientOptions,
|
||||
socket: {
|
||||
...this.options.nodeClientOptions?.socket,
|
||||
host: master.host,
|
||||
port: master.port
|
||||
}
|
||||
options.socket.host = master.host;
|
||||
options.socket.port = master.port;
|
||||
|
||||
return RedisClient.create(options);;
|
||||
});
|
||||
}
|
||||
|
||||
async getReplicaNodes() {
|
||||
let connected = false;
|
||||
|
||||
for (const node of this.#sentinelRootNodes) {
|
||||
const options: RedisClientOptions = { ...this.options.sentinelClientOptions };
|
||||
if (options.socket === undefined) {
|
||||
options.socket = {};
|
||||
}
|
||||
options.socket.host = node.host;
|
||||
options.socket.port = node.port;
|
||||
options.socket.reconnectStrategy = false;
|
||||
options.modules = RedisSentinelModule;
|
||||
|
||||
const client = RedisClient.create(options).on('error', err => this.emit(`getReplicaNodes: ${err}`));
|
||||
const client = RedisClient.create({
|
||||
...this.options.sentinelClientOptions,
|
||||
socket: {
|
||||
...this.options.sentinelClientOptions?.socket,
|
||||
host: node.host,
|
||||
port: node.port,
|
||||
reconnectStrategy: false
|
||||
},
|
||||
modules: RedisSentinelModule
|
||||
}).on('error', err => this.emit(`getReplicaNodes: ${err}`));
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
@@ -1480,13 +1476,13 @@ export class RedisSentinelFactory extends EventEmitter {
|
||||
this.#replicaIdx = 0;
|
||||
}
|
||||
|
||||
const options: RedisClientOptions = { ...this.options.nodeClientOptions };
|
||||
if (options.socket === undefined) {
|
||||
options.socket = {};
|
||||
return RedisClient.create({
|
||||
...this.options.nodeClientOptions,
|
||||
socket: {
|
||||
...this.options.nodeClientOptions?.socket,
|
||||
host: replicas[this.#replicaIdx].host,
|
||||
port: replicas[this.#replicaIdx].port
|
||||
}
|
||||
options.socket.host = replicas[this.#replicaIdx].host;
|
||||
options.socket.port = replicas[this.#replicaIdx].port;
|
||||
|
||||
return RedisClient.create(options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -45,18 +45,14 @@ export class PubSubProxy extends EventEmitter {
|
||||
throw new Error("pubSubProxy: didn't define node to do pubsub against");
|
||||
}
|
||||
|
||||
const options = { ...this.#clientOptions };
|
||||
|
||||
if (this.#clientOptions.socket) {
|
||||
options.socket = { ...this.#clientOptions.socket };
|
||||
} else {
|
||||
options.socket = {};
|
||||
return new RedisClient({
|
||||
...this.#clientOptions,
|
||||
socket: {
|
||||
...this.#clientOptions.socket,
|
||||
host: this.#node.host,
|
||||
port: this.#node.port
|
||||
}
|
||||
|
||||
options.socket.host = this.#node.host;
|
||||
options.socket.port = this.#node.port;
|
||||
|
||||
return new RedisClient(options);
|
||||
});
|
||||
}
|
||||
|
||||
async #initiatePubSubClient(withSubscriptions = false) {
|
||||
|
Reference in New Issue
Block a user