1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-17 19:41:06 +03:00

clean code

This commit is contained in:
leibale
2021-07-02 18:27:50 -04:00
parent 81837c67eb
commit a2de68c572
9 changed files with 12 additions and 22 deletions

View File

@@ -1,3 +1,5 @@
'use strict';
const cronometro = require('cronometro'), const cronometro = require('cronometro'),
newRedis = require('redis-new'), newRedis = require('redis-new'),
oldRedis = require('redis-old'); oldRedis = require('redis-old');

View File

@@ -6,12 +6,12 @@ import { RedisReply } from './commands';
export interface QueueCommandOptions { export interface QueueCommandOptions {
asap?: boolean; asap?: boolean;
signal?: AbortSignal; signal?: AbortSignal;
chainId?: Symbol; chainId?: symbol;
} }
interface CommandWaitingToBeSent extends CommandWaitingForReply { interface CommandWaitingToBeSent extends CommandWaitingForReply {
encodedCommand: string; encodedCommand: string;
chainId?: Symbol; chainId?: symbol;
abort?: { abort?: {
signal: AbortSignal; signal: AbortSignal;
listener(): void; listener(): void;
@@ -119,7 +119,7 @@ export default class RedisCommandsQueue {
returnError: (err: Error) => this.#shiftWaitingForReply().reject(err) returnError: (err: Error) => this.#shiftWaitingForReply().reject(err)
}); });
#chainInExecution: Symbol | undefined; #chainInExecution: symbol | undefined;
constructor(maxLength: number | null | undefined, executor: CommandsQueueExecutor) { constructor(maxLength: number | null | undefined, executor: CommandsQueueExecutor) {
this.#maxLength = maxLength; this.#maxLength = maxLength;
@@ -293,7 +293,7 @@ export default class RedisCommandsQueue {
const encoded: Array<string> = []; const encoded: Array<string> = [];
let size = 0, let size = 0,
lastCommandChainId: Symbol | undefined; lastCommandChainId: symbol | undefined;
for (const command of this.#waitingToBeSent) { for (const command of this.#waitingToBeSent) {
encoded.push(command.encodedCommand); encoded.push(command.encodedCommand);
size += command.encodedCommand.length; size += command.encodedCommand.length;

View File

@@ -31,7 +31,7 @@ interface AclLog {
context: string; context: string;
object: string; object: string;
username: string; username: string;
ageSeconds: Number; ageSeconds: number;
clientInfo: string; clientInfo: string;
} }

View File

@@ -95,8 +95,6 @@ describe('CLUSTER NODES', () => {
}); });
itWithCluster(TestRedisClusters.OPEN, 'cluster.clusterNodes', async cluster => { itWithCluster(TestRedisClusters.OPEN, 'cluster.clusterNodes', async cluster => {
const nodes = await cluster.clusterNodes();
for (const node of (await cluster.clusterNodes())) { for (const node of (await cluster.clusterNodes())) {
assert.equal(typeof node.id, 'string'); assert.equal(typeof node.id, 'string');
assert.equal(typeof node.url, 'string'); assert.equal(typeof node.url, 'string');

View File

@@ -81,7 +81,7 @@ describe('SET', () => {
it('with GET', () => { it('with GET', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'value', { transformArguments('key', 'value', {
GET: 1 GET: true
}), }),
['SET', 'key', 'value', 'GET'] ['SET', 'key', 'value', 'GET']
); );

View File

@@ -1,5 +1,4 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { triggerAsyncId } from 'async_hooks';
import { TestRedisServers, itWithClient } from '../test-utils'; import { TestRedisServers, itWithClient } from '../test-utils';
import { transformArguments, transformReply } from './XINFO_STREAM'; import { transformArguments, transformReply } from './XINFO_STREAM';

View File

@@ -32,11 +32,4 @@ export function transformArguments(
return args; return args;
} }
interface XPendingReply {
messageId: string;
owner: string;
msSinceLastDelivery: number;
deliveriesCounter: number;
}
export const transformReply = transformReplyStreamMessages; export const transformReply = transformReplyStreamMessages;

View File

@@ -25,7 +25,7 @@ export interface MultiQueuedCommand {
transformReply?: RedisCommand['transformReply']; transformReply?: RedisCommand['transformReply'];
} }
export type RedisMultiExecutor = (queue: Array<MultiQueuedCommand>, chainId?: Symbol) => Promise<Array<RedisReply>>; export type RedisMultiExecutor = (queue: Array<MultiQueuedCommand>, chainId?: symbol) => Promise<Array<RedisReply>>;
export default class RedisMultiCommand<M extends RedisModules = RedisModules, S extends RedisLuaScripts = RedisLuaScripts> { export default class RedisMultiCommand<M extends RedisModules = RedisModules, S extends RedisLuaScripts = RedisLuaScripts> {
static defineCommand(on: any, name: string, command: RedisCommand): void { static defineCommand(on: any, name: string, command: RedisCommand): void {

View File

@@ -217,11 +217,9 @@ export async function spawnRedisCluster(type: TestRedisClusters | null, numberOf
export async function spawnGlobalRedisCluster(type: TestRedisClusters | null, numberOfNodes: number, args?: Array<string>): Promise<Array<number>> { export async function spawnGlobalRedisCluster(type: TestRedisClusters | null, numberOfNodes: number, args?: Array<string>): Promise<Array<number>> {
const results = await spawnRedisCluster(type, numberOfNodes, args); const results = await spawnRedisCluster(type, numberOfNodes, args);
after(() => { after(() => Promise.all(
for (const { cleanup } of results) { results.map(({ cleanup }) => cleanup())
cleanup(); ));
}
});
return results.map(({ port }) => port); return results.map(({ port }) => port);
} }