Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add commands in Redis 7.0.2 #1611

Merged
merged 1 commit into from Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion bin/index.js
@@ -1,9 +1,18 @@
const returnTypes = require("./returnTypes");
const argumentTypes = require("./argumentTypes");
const sortArguments = require("./sortArguments");
const typeMaps = require("./typeMaps");
const overrides = require("./overrides");
const { getCommanderInterface } = require("@ioredis/interface-generator");

const HEADER = `/**
* This file is generated by @ioredis/interface-generator.
* Don't edit it manually. Instead, run \`npm run generate\` to update
* this file.
*/

`;

const ignoredCommands = ["monitor", "multi"];
const commands = require("@ioredis/commands")
.list.filter((name) => !ignoredCommands.includes(name))
Expand All @@ -24,6 +33,7 @@ async function main() {
overrides,
returnTypes,
argumentTypes,
sortArguments,
typeMaps: typeMaps,
ignoredBufferVariant: [
"incrbyfloat",
Expand All @@ -39,7 +49,7 @@ async function main() {

fs.writeFileSync(
path.join(__dirname, "..", "lib/utils/RedisCommander.ts"),
template.replace("////", () => interface)
HEADER + template.replace("////", () => interface)
);
}

Expand Down
2 changes: 1 addition & 1 deletion bin/overrides.js
Expand Up @@ -11,7 +11,7 @@ module.exports = {
overwrite: true,
defs: [
"$1(key: RedisKey, callback?: Callback<Record<string, string>>): Result<Record<string, string>, Context>",
"$1Buffer(key: RedisKey, callback?: Callback<[field: Buffer, value: Buffer][]>): Result<[field: Buffer, value: Buffer][], Context>",
"$1Buffer(key: RedisKey, callback?: Callback<Record<string, Buffer>>): Result<Record<string, Buffer>, Context>",
],
},
mset: msetOverrides,
Expand Down
17 changes: 17 additions & 0 deletions bin/sortArguments.js
@@ -0,0 +1,17 @@
module.exports = {
set: (args) => {
const sorted = args.sort((a, b) => {
const order = ["key", "value", "expiration", "condition", "get"];
const indexA = order.indexOf(a.name);
const indexB = order.indexOf(b.name);
if (indexA === -1) {
throw new Error('Invalid argument name: "' + a.name + '"');
}
if (indexB === -1) {
throw new Error('Invalid argument name: "' + b.name + '"');
}
return indexA - indexB;
});
return sorted;
},
};
3 changes: 2 additions & 1 deletion bin/template.ts
Expand Up @@ -11,7 +11,8 @@ export interface ResultTypes<Result, Context> {
pipeline: ChainableCommander;
}

export interface ChainableCommander extends RedisCommander<{ type: "pipeline" }> {
export interface ChainableCommander
extends RedisCommander<{ type: "pipeline" }> {
length: number;
}

Expand Down