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 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();

View File

@@ -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();

View File

@@ -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<void> {
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);
}

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",
"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'"

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.
### 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).