You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-17 19:41:06 +03:00
Do not use "timers/promises", fix "isRedisVersionGreaterThan"
This commit is contained in:
@@ -371,6 +371,9 @@ describe('Client', () => {
|
||||
(await client.clientInfo()).db,
|
||||
1
|
||||
);
|
||||
}, {
|
||||
// because of CLIENT INFO
|
||||
minimumRedisVersion: [6, 2]
|
||||
});
|
||||
|
||||
itWithClient(TestRedisServers.OPEN, 'scanIterator', async client => {
|
||||
|
@@ -1,8 +1,10 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { TestRedisServers, itWithClient } from '../test-utils';
|
||||
import { TestRedisServers, itWithClient, describeHandleMinimumRedisVersion } from '../test-utils';
|
||||
import { transformArguments } from './SMISMEMBER';
|
||||
|
||||
describe('SMISMEMBER', () => {
|
||||
describeHandleMinimumRedisVersion([6, 2]);
|
||||
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', ['1', '2']),
|
||||
|
@@ -78,12 +78,9 @@ describe('XCLAIM', () => {
|
||||
});
|
||||
|
||||
itWithClient(TestRedisServers.OPEN, 'client.xClaim', async client => {
|
||||
await Promise.all([
|
||||
client.xGroupCreate('key', 'group', '$', {
|
||||
await client.xGroupCreate('key', 'group', '$', {
|
||||
MKSTREAM: true
|
||||
}),
|
||||
client.xGroupCreateConsumer('key', 'group', 'consumer'),
|
||||
]);
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
await client.xClaim('key', 'group', 'consumer', 1, '0-0'),
|
||||
|
@@ -11,12 +11,9 @@ describe('XCLAIM JUSTID', () => {
|
||||
});
|
||||
|
||||
itWithClient(TestRedisServers.OPEN, 'client.xClaimJustId', async client => {
|
||||
await Promise.all([
|
||||
client.xGroupCreate('key', 'group', '$', {
|
||||
await client.xGroupCreate('key', 'group', '$', {
|
||||
MKSTREAM: true
|
||||
}),
|
||||
client.xGroupCreateConsumer('key', 'group', 'consumer'),
|
||||
]);
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
await client.xClaimJustId('key', 'group', 'consumer', 1, '0-0'),
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import EventEmitter from 'events';
|
||||
import net from 'net';
|
||||
import tls from 'tls';
|
||||
import { setTimeout } from 'timers/promises';
|
||||
import { URL } from 'url';
|
||||
import { promiseTimeout } from './utils';
|
||||
|
||||
interface RedisSocketCommonOptions {
|
||||
username?: string;
|
||||
@@ -147,7 +147,7 @@ export default class RedisSocket extends EventEmitter {
|
||||
throw retryIn;
|
||||
}
|
||||
|
||||
await setTimeout(retryIn);
|
||||
await promiseTimeout(retryIn);
|
||||
return this.#retryConnection(retries + 1);
|
||||
}
|
||||
}
|
||||
|
@@ -7,10 +7,10 @@ import { once } from 'events';
|
||||
import { RedisSocketOptions } from './socket';
|
||||
import which from 'which';
|
||||
import { SinonSpy } from 'sinon';
|
||||
import { setTimeout } from 'timers/promises';
|
||||
import RedisCluster, { RedisClusterType } from './cluster';
|
||||
import { unlink } from 'fs/promises';
|
||||
import { Context as MochaContext } from 'mocha';
|
||||
import { promiseTimeout } from './utils';
|
||||
|
||||
type RedisVersion = [major: number, minor: number, patch: number];
|
||||
|
||||
@@ -41,6 +41,8 @@ export function isRedisVersionGreaterThan(minimumVersion: PartialRedisVersion |
|
||||
for (let i = 0; i < lastIndex; i++) {
|
||||
if (REDIS_VERSION[i] > minimumVersion[i]) {
|
||||
return true;
|
||||
} else if (minimumVersion[i] > REDIS_VERSION[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +197,7 @@ export async function spawnRedisCluster(type: TestRedisClusters | null, numberOf
|
||||
}
|
||||
|
||||
while ((await spawnResults[0].client.clusterInfo()).state !== 'ok') {
|
||||
await setTimeout(CLUSTER_NODE_TIMEOUT);
|
||||
await promiseTimeout(CLUSTER_NODE_TIMEOUT);
|
||||
}
|
||||
|
||||
const disconnectPromises = [];
|
||||
@@ -360,6 +362,6 @@ export async function waitTillBeenCalled(spy: SinonSpy): Promise<void> {
|
||||
throw new Error('Waiting for more than 1 second');
|
||||
}
|
||||
|
||||
await setTimeout(1);
|
||||
await promiseTimeout(1);
|
||||
} while (spy.callCount === calls)
|
||||
}
|
3
lib/utils.ts
Normal file
3
lib/utils.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function promiseTimeout(ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
Reference in New Issue
Block a user