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