Skip to content

Commit

Permalink
feat: support commands added in Redis v7
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Mar 14, 2022
1 parent e93b39a commit 53ca412
Show file tree
Hide file tree
Showing 9 changed files with 769 additions and 3,890 deletions.
2 changes: 1 addition & 1 deletion bin/generateRedisCommander/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const overrides = require("./overrides");
const { getCommanderInterface } = require("@ioredis/interface-generator");

const ignoredCommands = ["monitor", "multi"];
const commands = require("redis-commands").list.filter(
const commands = require("@ioredis/commands").list.filter(
(name) => !ignoredCommands.includes(name)
);

Expand Down
9 changes: 5 additions & 4 deletions lib/Command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as commands from "redis-commands";
import { exists, getKeyIndexes } from "@ioredis/commands";
import * as calculateSlot from "cluster-key-slot";
import asCallback from "standard-as-callback";
import {
Expand Down Expand Up @@ -59,7 +59,7 @@ export interface CommandNameFlags {
* Command instance
*
* It's rare that you need to create a Command instance yourself.
*
*
* ```js
* var infoCommand = new Command('info', null, function (err, result) {
* console.log('result', result);
Expand Down Expand Up @@ -332,8 +332,9 @@ export default class Command implements Respondable {
): Array<string | Buffer> {
if (typeof this.keys === "undefined") {
this.keys = [];
if (commands.exists(this.name)) {
const keyIndexes = commands.getKeyIndexes(this.name, this.args);
if (exists(this.name)) {
// @ts-expect-error
const keyIndexes = getKeyIndexes(this.name, this.args);
for (const index of keyIndexes) {
this.args[index] = transform(this.args[index]);
this.keys.push(this.args[index] as string | Buffer);
Expand Down
2 changes: 1 addition & 1 deletion lib/Pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as calculateSlot from "cluster-key-slot";
import { exists, hasFlag } from "redis-commands";
import { exists, hasFlag } from "@ioredis/commands";
import asCallback from "standard-as-callback";
import { deprecate } from "util";
import Redis from "./Redis";
Expand Down
8 changes: 4 additions & 4 deletions lib/Redis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { exists, hasFlag } from "@ioredis/commands";
import { EventEmitter } from "events";
import * as commands from "redis-commands";
import asCallback from "standard-as-callback";
import Cluster from "./cluster";
import Command from "./Command";
Expand Down Expand Up @@ -422,8 +422,8 @@ class Redis extends Commander {
this.status === "ready" ||
(!stream &&
this.status === "connect" &&
commands.exists(command.name) &&
commands.hasFlag(command.name, "loading"));
exists(command.name) &&
hasFlag(command.name, "loading"));
if (!this.stream) {
writable = false;
} else if (!this.stream.writable) {
Expand Down Expand Up @@ -549,7 +549,7 @@ class Redis extends Commander {

/**
* Emit only when there's at least one listener.
*
*
* @ignore
*/
silentEmit(eventName: string, arg?: unknown): boolean {
Expand Down
5 changes: 2 additions & 3 deletions lib/cluster/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventEmitter } from "events";
import * as commands from "redis-commands";
import { exists, hasFlag } from "@ioredis/commands";
import { AbortError, RedisError } from "redis-errors";
import asCallback from "standard-as-callback";
import Pipeline from "../Pipeline";
Expand Down Expand Up @@ -462,8 +462,7 @@ class Cluster extends Commander {
if (to !== "master") {
const isCommandReadOnly =
command.isReadOnly ||
(commands.exists(command.name) &&
commands.hasFlag(command.name, "readonly"));
(exists(command.name) && hasFlag(command.name, "readonly"));
if (!isCommandReadOnly) {
to = "master";
}
Expand Down
8 changes: 4 additions & 4 deletions lib/utils/Commander.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { list } from "@ioredis/commands";
import asCallback from "standard-as-callback";
import {
executeWithAutoPipelining,
Expand Down Expand Up @@ -99,9 +100,7 @@ class Commander<Context extends ClientContext = { type: "default" }> {

interface Commander<Context> extends RedisCommander<Context> {}

const commands = require("redis-commands").list.filter(function (command) {
return command !== "monitor";
});
const commands = list.filter((command) => command !== "monitor");
commands.push("sentinel");

commands.forEach(function (commandName) {
Expand Down Expand Up @@ -189,7 +188,8 @@ function generateScriptingFunction(
encoding: unknown
) {
return function (...args) {
const callback = typeof args[args.length - 1] === "function" ? args.pop() : undefined;
const callback =
typeof args[args.length - 1] === "function" ? args.pop() : undefined;

let options;
if (this.options.dropBufferSupport) {
Expand Down
1,076 changes: 741 additions & 335 deletions lib/utils/RedisCommander.ts

Large diffs are not rendered by default.

Loading

0 comments on commit 53ca412

Please sign in to comment.