You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Add support for client.unref()
and client.ref()
(#2188)
* close #2185 - add support for client.unref() and client.ref() * allow sync tests
This commit is contained in:
@@ -844,4 +844,9 @@ describe('Client', () => {
|
|||||||
await client.disconnect();
|
await client.disconnect();
|
||||||
await client.connect();
|
await client.connect();
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
|
||||||
|
testUtils.testWithClient('should be able to use ref and unref', client => {
|
||||||
|
client.unref();
|
||||||
|
client.ref();
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -682,6 +682,14 @@ export default class RedisClient<
|
|||||||
await this.#isolationPool.drain();
|
await this.#isolationPool.drain();
|
||||||
await this.#isolationPool.clear();
|
await this.#isolationPool.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ref(): void {
|
||||||
|
this.#socket.ref();
|
||||||
|
}
|
||||||
|
|
||||||
|
unref(): void {
|
||||||
|
this.#socket.unref();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attachCommands({
|
attachCommands({
|
||||||
|
@@ -78,6 +78,8 @@ export default class RedisSocket extends EventEmitter {
|
|||||||
return this.#writableNeedDrain;
|
return this.#writableNeedDrain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#isSocketUnrefed = false;
|
||||||
|
|
||||||
constructor(initiator: RedisSocketInitiator, options?: RedisSocketOptions) {
|
constructor(initiator: RedisSocketInitiator, options?: RedisSocketOptions) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@@ -137,6 +139,10 @@ export default class RedisSocket extends EventEmitter {
|
|||||||
socket.setTimeout(this.#options.connectTimeout, () => socket.destroy(new ConnectionTimeoutError()));
|
socket.setTimeout(this.#options.connectTimeout, () => socket.destroy(new ConnectionTimeoutError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.#isSocketUnrefed) {
|
||||||
|
socket.unref();
|
||||||
|
}
|
||||||
|
|
||||||
socket
|
socket
|
||||||
.setNoDelay(this.#options.noDelay)
|
.setNoDelay(this.#options.noDelay)
|
||||||
.once('error', reject)
|
.once('error', reject)
|
||||||
@@ -233,4 +239,14 @@ export default class RedisSocket extends EventEmitter {
|
|||||||
this.#isCorked = false;
|
this.#isCorked = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ref(): void {
|
||||||
|
this.#isSocketUnrefed = false;
|
||||||
|
this.#socket?.ref();
|
||||||
|
}
|
||||||
|
|
||||||
|
unref(): void {
|
||||||
|
this.#isSocketUnrefed = true;
|
||||||
|
this.#socket?.unref();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -107,7 +107,7 @@ export default class TestUtils {
|
|||||||
S extends RedisScripts
|
S extends RedisScripts
|
||||||
>(
|
>(
|
||||||
title: string,
|
title: string,
|
||||||
fn: (client: RedisClientType<M, F, S>) => Promise<unknown>,
|
fn: (client: RedisClientType<M, F, S>) => unknown,
|
||||||
options: ClientTestOptions<M, F, S>
|
options: ClientTestOptions<M, F, S>
|
||||||
): void {
|
): void {
|
||||||
let dockerPromise: ReturnType<typeof spawnRedisServer>;
|
let dockerPromise: ReturnType<typeof spawnRedisServer>;
|
||||||
@@ -166,7 +166,7 @@ export default class TestUtils {
|
|||||||
S extends RedisScripts
|
S extends RedisScripts
|
||||||
>(
|
>(
|
||||||
title: string,
|
title: string,
|
||||||
fn: (cluster: RedisClusterType<M, F, S>) => Promise<void>,
|
fn: (cluster: RedisClusterType<M, F, S>) => unknown,
|
||||||
options: ClusterTestOptions<M, F, S>
|
options: ClusterTestOptions<M, F, S>
|
||||||
): void {
|
): void {
|
||||||
let dockersPromise: ReturnType<typeof spawnRedisCluster>;
|
let dockersPromise: ReturnType<typeof spawnRedisCluster>;
|
||||||
|
Reference in New Issue
Block a user