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