You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-17 19:41:06 +03:00
fix some code analyzers (LGTM, deepsource, codeclimate) issues
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
const cronometro = require('cronometro'),
|
||||
{ once } = require('events'),
|
||||
newRedis = require('redis-new'),
|
||||
oldRedis = require('redis-old');
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import RedisSocket, { RedisSocketOptions } from './socket';
|
||||
import RedisCommandsQueue, { PubSubListener, PubSubSubscribeCommands, PubSubUnsubscribeCommands, QueueCommandOptions } from './commands-queue';
|
||||
import COMMANDS from './commands';
|
||||
import { RedisCommand, RedisCommands, RedisModules, RedisReply } from './commands';
|
||||
import { RedisCommand, RedisModules, RedisReply } from './commands';
|
||||
import RedisMultiCommand, { MultiQueuedCommand, RedisMultiCommandType } from './multi-command';
|
||||
import EventEmitter from 'events';
|
||||
import { CommandOptions, commandOptions, isCommandOptions } from './command-options';
|
||||
|
@@ -56,7 +56,7 @@ export default class RedisClusterSlots<M extends RedisModules, S extends RedisLu
|
||||
throw new Error('None of the cluster nodes is available');
|
||||
}
|
||||
|
||||
async #discoverNodes(socketOptions?: RedisSocketOptions) {
|
||||
async #discoverNodes(socketOptions?: RedisSocketOptions): Promise<void> {
|
||||
const client = RedisClient.create({
|
||||
socket: socketOptions
|
||||
});
|
||||
@@ -98,6 +98,8 @@ export default class RedisClusterSlots<M extends RedisModules, S extends RedisLu
|
||||
promises.push(client.disconnect());
|
||||
this.#clientByKey.delete(key);
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
#initiateClientForNode(node: RedisClusterMasterNode | RedisClusterReplicaNode, readonly: boolean, clientsInUse: Set<string>, promises: Array<Promise<void>>): RedisClientType<M, S> {
|
||||
|
@@ -98,7 +98,7 @@ export default class RedisCluster<M extends RedisModules = RedisModules, S exten
|
||||
isReadonly: boolean | undefined,
|
||||
args: Array<string>,
|
||||
options?: ClientCommandOptions,
|
||||
redirections: number = 0
|
||||
redirections = 0
|
||||
): Promise<ReturnType<C['transformReply']>> {
|
||||
const client = this.#slots.getClient(firstKey, isReadonly);
|
||||
|
||||
@@ -118,7 +118,7 @@ export default class RedisCluster<M extends RedisModules = RedisModules, S exten
|
||||
originalArgs: Array<unknown>,
|
||||
redisArgs: Array<string>,
|
||||
options?: ClientCommandOptions,
|
||||
redirections: number = 0
|
||||
redirections = 0
|
||||
): Promise<ReturnType<S['transformReply']>> {
|
||||
const client = this.#slots.getClient(
|
||||
RedisCluster.#extractFirstKey(script, originalArgs, redisArgs),
|
||||
@@ -136,7 +136,7 @@ export default class RedisCluster<M extends RedisModules = RedisModules, S exten
|
||||
}
|
||||
}
|
||||
|
||||
async #handleCommandError(err: Error, client: RedisClientType<M, S>, redirections: number = 0): Promise<boolean> {
|
||||
async #handleCommandError(err: Error, client: RedisClientType<M, S>, redirections = 0): Promise<boolean> {
|
||||
if (redirections < (this.#options.maxCommandRedirections ?? 16)) {
|
||||
throw err;
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import LinkedList, { Node } from 'yallist';
|
||||
import LinkedList from 'yallist';
|
||||
import RedisParser from 'redis-parser';
|
||||
import { AbortError } from './errors';
|
||||
import { RedisReply } from './commands';
|
||||
@@ -208,7 +208,7 @@ export default class RedisCommandsQueue {
|
||||
return this.#pushPubSubCommand(command, channelsToSubscribe);
|
||||
}
|
||||
|
||||
unsubscribe(command: PubSubUnsubscribeCommands, channels?: string | Array<string>, listener?: PubSubListener) {
|
||||
unsubscribe(command: PubSubUnsubscribeCommands, channels?: string | Array<string>, listener?: PubSubListener): Promise<void> {
|
||||
const listeners = command === PubSubUnsubscribeCommands.UNSUBSCRIBE ? this.#pubSubListeners.channels : this.#pubSubListeners.patterns;
|
||||
if (!channels) {
|
||||
listeners.clear();
|
||||
|
@@ -24,7 +24,7 @@ interface BitFieldOptions {
|
||||
OVERFLOW?: 'WRAP' | 'SAT' | 'FAIL';
|
||||
}
|
||||
|
||||
export function transformArguments(key: string, options?: BitFieldOptions) {
|
||||
export function transformArguments(key: string, options?: BitFieldOptions): Array<string> {
|
||||
const args = ['BITFIELD', key];
|
||||
|
||||
if (options?.GET) {
|
||||
|
@@ -1,5 +1,3 @@
|
||||
import { transformReplyStringArray } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(key: string | Array<string>, timeout: number): Array<string> {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { transformReplyNumber, transformReplyNumberNull } from './generic-transformers';
|
||||
import { transformReplyNumberNull } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
|
@@ -23,7 +23,7 @@ describe('CLUSTER INFO', () => {
|
||||
'cluster_my_epoch:2',
|
||||
'cluster_stats_messages_sent:1483972',
|
||||
'cluster_stats_messages_received:1483968'
|
||||
].join('\n')),
|
||||
].join('\r\n')),
|
||||
{
|
||||
state: 'ok',
|
||||
slots: {
|
||||
|
@@ -20,26 +20,28 @@ interface ClusterInfoReply {
|
||||
};
|
||||
}
|
||||
|
||||
const regex = /.*:(?<value>.*)(\n?)/g;
|
||||
|
||||
export function transformReply(reply: string): ClusterInfoReply {
|
||||
const iterator = reply.matchAll(regex);
|
||||
const lines = reply.split('\r\n');
|
||||
|
||||
return {
|
||||
state: iterator.next().value[1],
|
||||
state: extractLineValue(lines[0]),
|
||||
slots: {
|
||||
assigned: Number(iterator.next().value[1]),
|
||||
ok: Number(iterator.next().value[1]),
|
||||
pfail: Number(iterator.next().value[1]),
|
||||
fail: Number(iterator.next().value[1])
|
||||
assigned: Number(extractLineValue(lines[1])),
|
||||
ok: Number(extractLineValue(lines[2])),
|
||||
pfail: Number(extractLineValue(lines[3])),
|
||||
fail: Number(extractLineValue(lines[4]))
|
||||
},
|
||||
knownNodes: Number(iterator.next().value[1]),
|
||||
size: Number(iterator.next().value[1]),
|
||||
currentEpoch: Number(iterator.next().value[1]),
|
||||
myEpoch: Number(iterator.next().value[1]),
|
||||
knownNodes: Number(extractLineValue(lines[5])),
|
||||
size: Number(extractLineValue(lines[6])),
|
||||
currentEpoch: Number(extractLineValue(lines[7])),
|
||||
myEpoch: Number(extractLineValue(lines[8])),
|
||||
stats: {
|
||||
messagesSent: Number(iterator.next().value[1]),
|
||||
messagesReceived: Number(iterator.next().value[1])
|
||||
messagesSent: Number(extractLineValue(lines[9])),
|
||||
messagesReceived: Number(extractLineValue(lines[10]))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function extractLineValue(line: string): string {
|
||||
return line.substring(line.indexOf(':') + 1);
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import RedisClient from '../client';
|
||||
import { TestRedisServers, itWithClient } from '../test-utils';
|
||||
import { transformArguments } from './DEL';
|
||||
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import { time } from 'console';
|
||||
import { transformReplyBoolean } from './generic-transformers';
|
||||
|
||||
export function transformArguments(key: string, timestamp: number | Date): Array<string> {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { transformReplyBoolean, transformReplyNumber } from './generic-transformers';
|
||||
import { transformReplyBoolean } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { TestRedisServers, itWithClient } from '../test-utils';
|
||||
import { transformArguments } from './READONLY';
|
||||
|
||||
describe('READONLY', () => {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { transformReplyBoolean, transformReplyNumber } from './generic-transformers';
|
||||
import { transformReplyBoolean } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { transformReplyNumber, transformReplyStringArray } from './generic-transformers';
|
||||
import { transformReplyStringArray } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { transformReplyBoolean, transformReplyNumber } from './generic-transformers';
|
||||
import { transformReplyBoolean } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 2;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { transformArgumentNumberInfinity, transformReplyNumber } from './generic-transformers';
|
||||
import { transformReplyNumber } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import { deepEqual } from 'assert/strict';
|
||||
import { transformReplySortedSetWithScores } from './generic-transformers';
|
||||
import { transformArguments as transformZPopMaxArguments } from './ZPOPMAX';
|
||||
|
||||
|
@@ -169,7 +169,7 @@ export default class RedisMultiCommand<M extends RedisModules = RedisModules, S
|
||||
return this;
|
||||
}
|
||||
|
||||
async exec(execAsPipeline: boolean = false): Promise<Array<unknown>> {
|
||||
async exec(execAsPipeline = false): Promise<Array<unknown>> {
|
||||
if (execAsPipeline) {
|
||||
return this.execAsPipeline();
|
||||
} else if (!this.#queue.length) {
|
||||
|
@@ -59,15 +59,15 @@ export default class RedisSocket extends EventEmitter {
|
||||
}
|
||||
|
||||
static #isUrlSocket(options: RedisSocketOptions): options is RedisUrlSocketOptions {
|
||||
return options.hasOwnProperty('url');
|
||||
return Object.prototype.hasOwnProperty.call(options, 'url');
|
||||
}
|
||||
|
||||
static #isUnixSocket(options: RedisSocketOptions): options is RedisUnixSocketOptions {
|
||||
return options.hasOwnProperty('path');
|
||||
return Object.prototype.hasOwnProperty.call(options, 'path');
|
||||
}
|
||||
|
||||
static #isTlsSocket(options: RedisSocketOptions): options is RedisTlsSocketOptions {
|
||||
return options.hasOwnProperty('tls');
|
||||
return Object.prototype.hasOwnProperty.call(options, 'tls');
|
||||
}
|
||||
|
||||
readonly #initiator?: RedisSocketInitiator;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import assert from 'assert/strict';
|
||||
import RedisClient, { RedisClientOptions, RedisClientType } from './client';
|
||||
import RedisClient, { RedisClientType } from './client';
|
||||
import { RedisModules } from './commands';
|
||||
import { RedisLuaScripts } from './lua-script';
|
||||
import { spawn } from 'child_process';
|
||||
|
Reference in New Issue
Block a user