1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00
This commit is contained in:
Leibale
2023-06-19 18:40:08 -04:00
parent 9d049c31a7
commit 2455ab2089
6 changed files with 56 additions and 66 deletions

View File

@@ -2,7 +2,7 @@ import { EventEmitter } from 'events';
import * as net from 'net'; import * as net from 'net';
import * as tls from 'tls'; import * as tls from 'tls';
import { ConnectionTimeoutError, ClientClosedError, SocketClosedUnexpectedlyError, ReconnectStrategyError } from '../errors'; import { ConnectionTimeoutError, ClientClosedError, SocketClosedUnexpectedlyError, ReconnectStrategyError } from '../errors';
import { promiseTimeout } from '../utils'; import { setTimeout } from 'timers/promises';
import { RedisArgument } from '../RESP/types'; import { RedisArgument } from '../RESP/types';
export interface RedisSocketCommonOptions { export interface RedisSocketCommonOptions {
@@ -159,7 +159,7 @@ export default class RedisSocket extends EventEmitter {
} }
this.emit('error', err); this.emit('error', err);
await promiseTimeout(retryIn); await setTimeout(retryIn);
this.emit('reconnecting'); this.emit('reconnecting');
} }
} while (this._isOpen && !this._isReady); } while (this._isOpen && !this._isReady);
@@ -283,14 +283,6 @@ export default class RedisSocket extends EventEmitter {
this.emit('end'); this.emit('end');
} }
cork(): void {
this._socket?.cork();
}
uncork(): void {
this._socket?.uncork();
}
ref(): void { ref(): void {
this._isSocketUnrefed = false; this._isSocketUnrefed = false;
this._socket?.ref(); this._socket?.ref();

View File

@@ -6,7 +6,7 @@
// import { SQUARE_SCRIPT } from '../client/index.spec'; // import { SQUARE_SCRIPT } from '../client/index.spec';
// import { RootNodesUnavailableError } from '../errors'; // import { RootNodesUnavailableError } from '../errors';
// import { spy } from 'sinon'; // import { spy } from 'sinon';
// import { promiseTimeout } from '../utils'; // import { setTimeout } from 'timers/promises';
// import RedisClient from '../client'; // import RedisClient from '../client';
// describe('Cluster', () => { // describe('Cluster', () => {
@@ -284,7 +284,7 @@
// // wait for migrating node to be notified about the new topology // // wait for migrating node to be notified about the new topology
// while ((await migratingClient.clusterInfo()).state !== 'ok') { // while ((await migratingClient.clusterInfo()).state !== 'ok') {
// await promiseTimeout(50); // await setTimeout(50);
// } // }
// // make sure to cause `MOVED` error // // make sure to cause `MOVED` error
@@ -340,7 +340,7 @@
// // wait for migrating node to be notified about the new topology // // wait for migrating node to be notified about the new topology
// while ((await migratingClient.clusterInfo()).state !== 'ok') { // while ((await migratingClient.clusterInfo()).state !== 'ok') {
// await promiseTimeout(50); // await setTimeout(50);
// } // }
// const listener = spy(); // const listener = spy();

View File

@@ -1,6 +1,6 @@
import TestUtils from '@redis/test-utils'; import TestUtils from '@redis/test-utils';
import { SinonSpy } from 'sinon'; import { SinonSpy } from 'sinon';
import { promiseTimeout } from './utils'; import { setTimeout } from 'timers/promises';
const utils = new TestUtils({ const utils = new TestUtils({
dockerImageName: 'redis', dockerImageName: 'redis',
@@ -14,49 +14,49 @@ const DEBUG_MODE_ARGS = utils.isVersionGreaterThan([7]) ?
[]; [];
export const GLOBAL = { export const GLOBAL = {
SERVERS: { SERVERS: {
OPEN: { OPEN: {
serverArguments: [...DEBUG_MODE_ARGS] serverArguments: [...DEBUG_MODE_ARGS]
},
PASSWORD: {
serverArguments: ['--requirepass', 'password', ...DEBUG_MODE_ARGS],
clientOptions: {
password: 'password'
}
}
}, },
CLUSTERS: { PASSWORD: {
OPEN: { serverArguments: ['--requirepass', 'password', ...DEBUG_MODE_ARGS],
serverArguments: [...DEBUG_MODE_ARGS] clientOptions: {
}, password: 'password'
PASSWORD: { }
serverArguments: ['--requirepass', 'password', ...DEBUG_MODE_ARGS],
clusterConfiguration: {
defaults: {
password: 'password'
}
}
},
WITH_REPLICAS: {
serverArguments: [...DEBUG_MODE_ARGS],
numberOfMasters: 2,
numberOfReplicas: 1,
clusterConfiguration: {
useReplicas: true
}
}
} }
},
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<void> { export async function waitTillBeenCalled(spy: SinonSpy): Promise<void> {
const start = process.hrtime.bigint(), const start = process.hrtime.bigint(),
calls = spy.callCount; calls = spy.callCount;
do { do {
if (process.hrtime.bigint() - start > 1_000_000_000) { if (process.hrtime.bigint() - start > 1_000_000_000) {
throw new Error('Waiting for more than 1 second'); throw new Error('Waiting for more than 1 second');
} }
await promiseTimeout(50); await setTimeout(50);
} while (spy.callCount === calls); } while (spy.callCount === calls);
} }

View File

@@ -1,3 +0,0 @@
export function promiseTimeout(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}

View File

@@ -5,7 +5,8 @@
"main": "./dist/index.js", "main": "./dist/index.js",
"types": "./dist/index.d.ts", "types": "./dist/index.d.ts",
"files": [ "files": [
"dist/" "dist/",
"!dist/tsconfig.tsbuildinfo"
], ],
"scripts": { "scripts": {
"test": "nyc -r text-summary -r lcov mocha -r source-map-support/register -r ts-node/register './lib/**/*.spec.ts'" "test": "nyc -r text-summary -r lcov mocha -r source-map-support/register -r ts-node/register './lib/**/*.spec.ts'"

View File

@@ -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. > 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 ## Supported Redis versions
Node Redis is supported with the following versions of Redis: 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 ## License
This repository is licensed under the "MIT" license. See [LICENSE](../../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).