From 2455ab2089fc7e7d005e5e49d63fa9c36f0719bf Mon Sep 17 00:00:00 2001 From: Leibale Date: Mon, 19 Jun 2023 18:40:08 -0400 Subject: [PATCH] wip --- packages/client/lib/client/socket.ts | 12 +--- packages/client/lib/cluster/index.spec.ts | 6 +- packages/client/lib/test-utils.ts | 78 +++++++++++------------ packages/client/lib/utils.ts | 3 - packages/client/package.json | 3 +- packages/redis/README.md | 20 +++--- 6 files changed, 56 insertions(+), 66 deletions(-) delete mode 100644 packages/client/lib/utils.ts diff --git a/packages/client/lib/client/socket.ts b/packages/client/lib/client/socket.ts index e179613062..a841828c3a 100644 --- a/packages/client/lib/client/socket.ts +++ b/packages/client/lib/client/socket.ts @@ -2,7 +2,7 @@ import { EventEmitter } from 'events'; import * as net from 'net'; import * as tls from 'tls'; import { ConnectionTimeoutError, ClientClosedError, SocketClosedUnexpectedlyError, ReconnectStrategyError } from '../errors'; -import { promiseTimeout } from '../utils'; +import { setTimeout } from 'timers/promises'; import { RedisArgument } from '../RESP/types'; export interface RedisSocketCommonOptions { @@ -159,7 +159,7 @@ export default class RedisSocket extends EventEmitter { } this.emit('error', err); - await promiseTimeout(retryIn); + await setTimeout(retryIn); this.emit('reconnecting'); } } while (this._isOpen && !this._isReady); @@ -283,14 +283,6 @@ export default class RedisSocket extends EventEmitter { this.emit('end'); } - cork(): void { - this._socket?.cork(); - } - - uncork(): void { - this._socket?.uncork(); - } - ref(): void { this._isSocketUnrefed = false; this._socket?.ref(); diff --git a/packages/client/lib/cluster/index.spec.ts b/packages/client/lib/cluster/index.spec.ts index 4c06dc8c91..2b283a18b5 100644 --- a/packages/client/lib/cluster/index.spec.ts +++ b/packages/client/lib/cluster/index.spec.ts @@ -6,7 +6,7 @@ // import { SQUARE_SCRIPT } from '../client/index.spec'; // import { RootNodesUnavailableError } from '../errors'; // import { spy } from 'sinon'; -// import { promiseTimeout } from '../utils'; +// import { setTimeout } from 'timers/promises'; // import RedisClient from '../client'; // describe('Cluster', () => { @@ -284,7 +284,7 @@ // // wait for migrating node to be notified about the new topology // while ((await migratingClient.clusterInfo()).state !== 'ok') { -// await promiseTimeout(50); +// await setTimeout(50); // } // // make sure to cause `MOVED` error @@ -340,7 +340,7 @@ // // wait for migrating node to be notified about the new topology // while ((await migratingClient.clusterInfo()).state !== 'ok') { -// await promiseTimeout(50); +// await setTimeout(50); // } // const listener = spy(); diff --git a/packages/client/lib/test-utils.ts b/packages/client/lib/test-utils.ts index 65d526f601..fa40d0a548 100644 --- a/packages/client/lib/test-utils.ts +++ b/packages/client/lib/test-utils.ts @@ -1,6 +1,6 @@ import TestUtils from '@redis/test-utils'; import { SinonSpy } from 'sinon'; -import { promiseTimeout } from './utils'; +import { setTimeout } from 'timers/promises'; const utils = new TestUtils({ dockerImageName: 'redis', @@ -14,49 +14,49 @@ const DEBUG_MODE_ARGS = utils.isVersionGreaterThan([7]) ? []; export const GLOBAL = { - SERVERS: { - OPEN: { - serverArguments: [...DEBUG_MODE_ARGS] - }, - PASSWORD: { - serverArguments: ['--requirepass', 'password', ...DEBUG_MODE_ARGS], - clientOptions: { - password: 'password' - } - } + SERVERS: { + OPEN: { + serverArguments: [...DEBUG_MODE_ARGS] }, - CLUSTERS: { - OPEN: { - serverArguments: [...DEBUG_MODE_ARGS] - }, - PASSWORD: { - serverArguments: ['--requirepass', 'password', ...DEBUG_MODE_ARGS], - clusterConfiguration: { - defaults: { - password: 'password' - } - } - }, - WITH_REPLICAS: { - serverArguments: [...DEBUG_MODE_ARGS], - numberOfMasters: 2, - numberOfReplicas: 1, - clusterConfiguration: { - useReplicas: true - } - } + PASSWORD: { + serverArguments: ['--requirepass', 'password', ...DEBUG_MODE_ARGS], + clientOptions: { + password: 'password' + } } + }, + CLUSTERS: { + OPEN: { + serverArguments: [...DEBUG_MODE_ARGS] + }, + PASSWORD: { + serverArguments: ['--requirepass', 'password', ...DEBUG_MODE_ARGS], + clusterConfiguration: { + defaults: { + password: 'password' + } + } + }, + WITH_REPLICAS: { + serverArguments: [...DEBUG_MODE_ARGS], + numberOfMasters: 2, + numberOfReplicas: 1, + clusterConfiguration: { + useReplicas: true + } + } + } }; export async function waitTillBeenCalled(spy: SinonSpy): Promise { - const start = process.hrtime.bigint(), - calls = spy.callCount; + const start = process.hrtime.bigint(), + calls = spy.callCount; - do { - if (process.hrtime.bigint() - start > 1_000_000_000) { - throw new Error('Waiting for more than 1 second'); - } + do { + if (process.hrtime.bigint() - start > 1_000_000_000) { + throw new Error('Waiting for more than 1 second'); + } - await promiseTimeout(50); - } while (spy.callCount === calls); + await setTimeout(50); + } while (spy.callCount === calls); } diff --git a/packages/client/lib/utils.ts b/packages/client/lib/utils.ts deleted file mode 100644 index 55bed41981..0000000000 --- a/packages/client/lib/utils.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function promiseTimeout(ms: number): Promise { - return new Promise(resolve => setTimeout(resolve, ms)); -} diff --git a/packages/client/package.json b/packages/client/package.json index d0bc06792d..374cbcae98 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -5,7 +5,8 @@ "main": "./dist/index.js", "types": "./dist/index.d.ts", "files": [ - "dist/" + "dist/", + "!dist/tsconfig.tsbuildinfo" ], "scripts": { "test": "nyc -r text-summary -r lcov mocha -r source-map-support/register -r ts-node/register './lib/**/*.spec.ts'" diff --git a/packages/redis/README.md b/packages/redis/README.md index 3a790cdd4b..3f05d8dc5a 100644 --- a/packages/redis/README.md +++ b/packages/redis/README.md @@ -167,6 +167,16 @@ The Node Redis client class is an Nodejs EventEmitter and it emits an event each > The client will not emit [any other events](../../docs/v3-to-v4.md#all-the-removed-events) beyond those listed above. +### Links + +- [Multi](../../docs/multi.md). +- [Pub/Sub](../../docs/pub-sub.md). +- [Scan Iterators](../../docs/scan-iterators.md). +- [Programmability](../../docs/programmability.md). +- [Command Options](../../docs/command-options.md). +- [Blocking Commands](../../docs/blocking-commands.md). +- [Clustering](../../docs/clustering.md). + ## Supported Redis versions Node Redis is supported with the following versions of Redis: @@ -192,13 +202,3 @@ Thank you to all the people who already contributed to Node Redis! ## License This repository is licensed under the "MIT" license. See [LICENSE](../../LICENSE). - -### Links - -- [Multi](../../docs/multi.md). -- [Pub/Sub](../../docs/pub-sub.md). -- [Scan Iterators](../../docs/scan-iterators.md). -- [Programmability](../../docs/programmability.md). -- [Command Options](../../docs/command-options.md). -- [Blocking Commands](../../docs/blocking-commands.md). -- [Clustering](../../docs/clustering.md).