Skip to content

Commit 53ca412

Browse files
committedMar 14, 2022
feat: support commands added in Redis v7
1 parent e93b39a commit 53ca412

File tree

9 files changed

+769
-3890
lines changed

9 files changed

+769
-3890
lines changed
 

‎bin/generateRedisCommander/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const overrides = require("./overrides");
55
const { getCommanderInterface } = require("@ioredis/interface-generator");
66

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

‎lib/Command.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as commands from "redis-commands";
1+
import { exists, getKeyIndexes } from "@ioredis/commands";
22
import * as calculateSlot from "cluster-key-slot";
33
import asCallback from "standard-as-callback";
44
import {
@@ -59,7 +59,7 @@ export interface CommandNameFlags {
5959
* Command instance
6060
*
6161
* It's rare that you need to create a Command instance yourself.
62-
*
62+
*
6363
* ```js
6464
* var infoCommand = new Command('info', null, function (err, result) {
6565
* console.log('result', result);
@@ -332,8 +332,9 @@ export default class Command implements Respondable {
332332
): Array<string | Buffer> {
333333
if (typeof this.keys === "undefined") {
334334
this.keys = [];
335-
if (commands.exists(this.name)) {
336-
const keyIndexes = commands.getKeyIndexes(this.name, this.args);
335+
if (exists(this.name)) {
336+
// @ts-expect-error
337+
const keyIndexes = getKeyIndexes(this.name, this.args);
337338
for (const index of keyIndexes) {
338339
this.args[index] = transform(this.args[index]);
339340
this.keys.push(this.args[index] as string | Buffer);

‎lib/Pipeline.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as calculateSlot from "cluster-key-slot";
2-
import { exists, hasFlag } from "redis-commands";
2+
import { exists, hasFlag } from "@ioredis/commands";
33
import asCallback from "standard-as-callback";
44
import { deprecate } from "util";
55
import Redis from "./Redis";

‎lib/Redis.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { exists, hasFlag } from "@ioredis/commands";
12
import { EventEmitter } from "events";
2-
import * as commands from "redis-commands";
33
import asCallback from "standard-as-callback";
44
import Cluster from "./cluster";
55
import Command from "./Command";
@@ -422,8 +422,8 @@ class Redis extends Commander {
422422
this.status === "ready" ||
423423
(!stream &&
424424
this.status === "connect" &&
425-
commands.exists(command.name) &&
426-
commands.hasFlag(command.name, "loading"));
425+
exists(command.name) &&
426+
hasFlag(command.name, "loading"));
427427
if (!this.stream) {
428428
writable = false;
429429
} else if (!this.stream.writable) {
@@ -549,7 +549,7 @@ class Redis extends Commander {
549549

550550
/**
551551
* Emit only when there's at least one listener.
552-
*
552+
*
553553
* @ignore
554554
*/
555555
silentEmit(eventName: string, arg?: unknown): boolean {

‎lib/cluster/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EventEmitter } from "events";
2-
import * as commands from "redis-commands";
2+
import { exists, hasFlag } from "@ioredis/commands";
33
import { AbortError, RedisError } from "redis-errors";
44
import asCallback from "standard-as-callback";
55
import Pipeline from "../Pipeline";
@@ -462,8 +462,7 @@ class Cluster extends Commander {
462462
if (to !== "master") {
463463
const isCommandReadOnly =
464464
command.isReadOnly ||
465-
(commands.exists(command.name) &&
466-
commands.hasFlag(command.name, "readonly"));
465+
(exists(command.name) && hasFlag(command.name, "readonly"));
467466
if (!isCommandReadOnly) {
468467
to = "master";
469468
}

‎lib/utils/Commander.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { list } from "@ioredis/commands";
12
import asCallback from "standard-as-callback";
23
import {
34
executeWithAutoPipelining,
@@ -99,9 +100,7 @@ class Commander<Context extends ClientContext = { type: "default" }> {
99100

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

102-
const commands = require("redis-commands").list.filter(function (command) {
103-
return command !== "monitor";
104-
});
103+
const commands = list.filter((command) => command !== "monitor");
105104
commands.push("sentinel");
106105

107106
commands.forEach(function (commandName) {
@@ -189,7 +188,8 @@ function generateScriptingFunction(
189188
encoding: unknown
190189
) {
191190
return function (...args) {
192-
const callback = typeof args[args.length - 1] === "function" ? args.pop() : undefined;
191+
const callback =
192+
typeof args[args.length - 1] === "function" ? args.pop() : undefined;
193193

194194
let options;
195195
if (this.options.dropBufferSupport) {

‎lib/utils/RedisCommander.ts

+741-335
Large diffs are not rendered by default.

‎package-lock.json

+10-3,537
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
"url": "https://opencollective.com/ioredis"
3838
},
3939
"dependencies": {
40+
"@ioredis/commands": "^1.0.2",
4041
"cluster-key-slot": "^1.1.0",
4142
"debug": "^4.3.3",
4243
"denque": "^2.0.1",
4344
"lodash.defaults": "^4.2.0",
4445
"lodash.isarguments": "^3.1.0",
45-
"redis-commands": "1.7.0",
4646
"redis-errors": "^1.2.0",
4747
"redis-parser": "^3.0.0",
4848
"standard-as-callback": "^2.1.0"

0 commit comments

Comments
 (0)
Please sign in to comment.