Skip to content

Commit 32eb381

Browse files
committed
feat: support Redis Functions introduced in Redis 7.0
1 parent 53ca412 commit 32eb381

File tree

5 files changed

+83
-52
lines changed

5 files changed

+83
-52
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ Supports Redis >= 2.6.12 and (Node.js >= 12.22.0). Completely compatible with Re
1818
ioredis is a robust, full-featured Redis client that is
1919
used in the world's biggest online commerce company [Alibaba](http://www.alibaba.com/) and many other awesome companies.
2020

21-
0. Full-featured. It supports [Cluster](http://redis.io/topics/cluster-tutorial), [Sentinel](http://redis.io/topics/sentinel), [Streams](https://redis.io/topics/streams-intro), [Pipelining](http://redis.io/topics/pipelining) and of course [Lua scripting](http://redis.io/commands/eval) & [Pub/Sub](http://redis.io/topics/pubsub) (with the support of binary messages).
22-
1. High performance 🚀.
23-
2. Delightful API 😄. It works with Node callbacks and Native promises.
24-
3. Transformation of command arguments and replies.
25-
4. Transparent key prefixing.
26-
5. Abstraction for Lua scripting, allowing you to define custom commands.
27-
6. Support for binary data.
28-
7. Support for TLS 🔒.
29-
8. Support for offline queue and ready checking.
30-
9. Support for ES6 types, such as `Map` and `Set`.
31-
10. Support for GEO commands 📍.
32-
11. Support for Redis ACL.
33-
12. Sophisticated error handling strategy.
34-
13. Support for NAT mapping.
35-
14. Support for autopipelining
21+
0. Full-featured. It supports [Cluster](http://redis.io/topics/cluster-tutorial), [Sentinel](http://redis.io/topics/sentinel), [Streams](https://redis.io/topics/streams-intro), [Pipelining](http://redis.io/topics/pipelining), and of course [Lua scripting](http://redis.io/commands/eval), [Redis Functions](https://redis.io/topics/functions-intro), [Pub/Sub](http://redis.io/topics/pubsub) (with the support of binary messages).
22+
0. High performance 🚀.
23+
0. Delightful API 😄. It works with Node callbacks and Native promises.
24+
0. Transformation of command arguments and replies.
25+
0. Transparent key prefixing.
26+
0. Abstraction for Lua scripting, allowing you to [define custom commands](https://github.com/luin/ioredis#lua-scripting).
27+
0. Supports [binary data](https://github.com/luin/ioredis#handle-binary-data).
28+
0. Supports [TLS](https://github.com/luin/ioredis#tls-options) 🔒.
29+
0. Supports offline queue and ready checking.
30+
0. Supports ES6 types, such as `Map` and `Set`.
31+
0. Supports GEO commands 📍.
32+
0. Supports Redis ACL.
33+
0. Sophisticated error handling strategy.
34+
0. Supports NAT mapping.
35+
0. Supports autopipelining
3636

3737
# Versions
3838

bin/generateRedisCommander/returnTypes.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ module.exports = {
1717
if (hasToken(types, ["NX", "XX"])) return "'OK' | null";
1818
return "'OK'";
1919
},
20+
function: (types) => {
21+
if (
22+
matchSubcommand(types, [
23+
"LOAD",
24+
"DELETE",
25+
"DUMP",
26+
"FLUSH",
27+
"KILL",
28+
"RESTORE",
29+
])
30+
) {
31+
return "string";
32+
}
33+
if (matchSubcommand(types, ["LIST"])) {
34+
return "unknown[]";
35+
}
36+
},
2037
ping: (types) => {
2138
return types.length ? "string" : "'PONG'";
2239
},

lib/utils/RedisCommander.ts

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,79 +1144,93 @@ interface RedisCommander<Context extends ClientContext = { type: "default" }> {
11441144
flushdb(sync: 'SYNC', callback?: Callback<'OK'>): Result<'OK', Context>;
11451145

11461146
/**
1147-
* List information about all the functions
1147+
* Dump all functions into a serialized binary payload
11481148
* - _group_: scripting
11491149
* - _complexity_: O(N) where N is the number of functions
11501150
* - _since_: 7.0.0
11511151
*/
1152-
function(subcommand: 'LIST', callback?: Callback<unknown>): Result<unknown, Context>;
1153-
function(subcommand: 'LIST', withcode: 'WITHCODE', callback?: Callback<unknown>): Result<unknown, Context>;
1154-
function(subcommand: 'LIST', libraryNamePatternToken: 'LIBRARYNAME', libraryNamePattern: string | Buffer, callback?: Callback<unknown>): Result<unknown, Context>;
1155-
function(subcommand: 'LIST', libraryNamePatternToken: 'LIBRARYNAME', libraryNamePattern: string | Buffer, withcode: 'WITHCODE', callback?: Callback<unknown>): Result<unknown, Context>;
1152+
function(subcommand: 'DUMP', callback?: Callback<string>): Result<string, Context>;
1153+
functionBuffer(subcommand: 'DUMP', callback?: Callback<Buffer>): Result<Buffer, Context>;
11561154

11571155
/**
1158-
* Restore all the functions on the given payload
1156+
* Show helpful text about the different subcommands
11591157
* - _group_: scripting
1160-
* - _complexity_: O(N) where N is the number of functions on the payload
1158+
* - _complexity_: O(1)
11611159
* - _since_: 7.0.0
11621160
*/
1163-
function(subcommand: 'RESTORE', serializedValue: string | Buffer | number, callback?: Callback<unknown>): Result<unknown, Context>;
1164-
function(subcommand: 'RESTORE', serializedValue: string | Buffer | number, flush: 'FLUSH', callback?: Callback<unknown>): Result<unknown, Context>;
1165-
function(subcommand: 'RESTORE', serializedValue: string | Buffer | number, append: 'APPEND', callback?: Callback<unknown>): Result<unknown, Context>;
1166-
function(subcommand: 'RESTORE', serializedValue: string | Buffer | number, replace: 'REPLACE', callback?: Callback<unknown>): Result<unknown, Context>;
1161+
function(subcommand: 'HELP', callback?: Callback<unknown>): Result<unknown, Context>;
11671162

11681163
/**
1169-
* Delete a function by name
1164+
* Deleting all functions
11701165
* - _group_: scripting
1171-
* - _complexity_: O(1)
1166+
* - _complexity_: O(N) where N is the number of functions deleted
11721167
* - _since_: 7.0.0
11731168
*/
1174-
function(subcommand: 'DELETE', libraryName: string | Buffer, callback?: Callback<unknown>): Result<unknown, Context>;
1169+
function(subcommand: 'FLUSH', callback?: Callback<string>): Result<string, Context>;
1170+
functionBuffer(subcommand: 'FLUSH', callback?: Callback<Buffer>): Result<Buffer, Context>;
1171+
function(subcommand: 'FLUSH', async: 'ASYNC', callback?: Callback<string>): Result<string, Context>;
1172+
functionBuffer(subcommand: 'FLUSH', async: 'ASYNC', callback?: Callback<Buffer>): Result<Buffer, Context>;
1173+
function(subcommand: 'FLUSH', sync: 'SYNC', callback?: Callback<string>): Result<string, Context>;
1174+
functionBuffer(subcommand: 'FLUSH', sync: 'SYNC', callback?: Callback<Buffer>): Result<Buffer, Context>;
11751175

11761176
/**
1177-
* Create a function with the given arguments (name, code, description)
1177+
* Kill the function currently in execution.
11781178
* - _group_: scripting
1179-
* - _complexity_: O(1) (considering compilation time is redundant)
1179+
* - _complexity_: O(1)
11801180
* - _since_: 7.0.0
11811181
*/
1182-
function(subcommand: 'LOAD', engineName: string | Buffer, libraryName: string | Buffer, functionCode: string | Buffer, callback?: Callback<unknown>): Result<unknown, Context>;
1183-
function(subcommand: 'LOAD', engineName: string | Buffer, libraryName: string | Buffer, libraryDescriptionToken: 'DESCRIPTION', libraryDescription: string | Buffer, functionCode: string | Buffer, callback?: Callback<unknown>): Result<unknown, Context>;
1184-
function(subcommand: 'LOAD', engineName: string | Buffer, libraryName: string | Buffer, replace: 'REPLACE', functionCode: string | Buffer, callback?: Callback<unknown>): Result<unknown, Context>;
1185-
function(subcommand: 'LOAD', engineName: string | Buffer, libraryName: string | Buffer, replace: 'REPLACE', libraryDescriptionToken: 'DESCRIPTION', libraryDescription: string | Buffer, functionCode: string | Buffer, callback?: Callback<unknown>): Result<unknown, Context>;
1182+
function(subcommand: 'KILL', callback?: Callback<string>): Result<string, Context>;
1183+
functionBuffer(subcommand: 'KILL', callback?: Callback<Buffer>): Result<Buffer, Context>;
11861184

11871185
/**
1188-
* Kill the function currently in execution.
1186+
* Delete a function by name
11891187
* - _group_: scripting
11901188
* - _complexity_: O(1)
11911189
* - _since_: 7.0.0
11921190
*/
1193-
function(subcommand: 'KILL', callback?: Callback<unknown>): Result<unknown, Context>;
1191+
function(subcommand: 'DELETE', libraryName: string | Buffer, callback?: Callback<string>): Result<string, Context>;
1192+
functionBuffer(subcommand: 'DELETE', libraryName: string | Buffer, callback?: Callback<Buffer>): Result<Buffer, Context>;
11941193

11951194
/**
1196-
* Dump all functions into a serialized binary payload
1195+
* Restore all the functions on the given payload
11971196
* - _group_: scripting
1198-
* - _complexity_: O(N) where N is the number of functions
1197+
* - _complexity_: O(N) where N is the number of functions on the payload
11991198
* - _since_: 7.0.0
12001199
*/
1201-
function(subcommand: 'DUMP', callback?: Callback<unknown>): Result<unknown, Context>;
1200+
function(subcommand: 'RESTORE', serializedValue: string | Buffer | number, callback?: Callback<string>): Result<string, Context>;
1201+
functionBuffer(subcommand: 'RESTORE', serializedValue: string | Buffer | number, callback?: Callback<Buffer>): Result<Buffer, Context>;
1202+
function(subcommand: 'RESTORE', serializedValue: string | Buffer | number, flush: 'FLUSH', callback?: Callback<string>): Result<string, Context>;
1203+
functionBuffer(subcommand: 'RESTORE', serializedValue: string | Buffer | number, flush: 'FLUSH', callback?: Callback<Buffer>): Result<Buffer, Context>;
1204+
function(subcommand: 'RESTORE', serializedValue: string | Buffer | number, append: 'APPEND', callback?: Callback<string>): Result<string, Context>;
1205+
functionBuffer(subcommand: 'RESTORE', serializedValue: string | Buffer | number, append: 'APPEND', callback?: Callback<Buffer>): Result<Buffer, Context>;
1206+
function(subcommand: 'RESTORE', serializedValue: string | Buffer | number, replace: 'REPLACE', callback?: Callback<string>): Result<string, Context>;
1207+
functionBuffer(subcommand: 'RESTORE', serializedValue: string | Buffer | number, replace: 'REPLACE', callback?: Callback<Buffer>): Result<Buffer, Context>;
12021208

12031209
/**
1204-
* Show helpful text about the different subcommands
1210+
* List information about all the functions
12051211
* - _group_: scripting
1206-
* - _complexity_: O(1)
1212+
* - _complexity_: O(N) where N is the number of functions
12071213
* - _since_: 7.0.0
12081214
*/
1209-
function(subcommand: 'HELP', callback?: Callback<unknown>): Result<unknown, Context>;
1215+
function(subcommand: 'LIST', callback?: Callback<unknown[]>): Result<unknown[], Context>;
1216+
function(subcommand: 'LIST', withcode: 'WITHCODE', callback?: Callback<unknown[]>): Result<unknown[], Context>;
1217+
function(subcommand: 'LIST', libraryNamePatternToken: 'LIBRARYNAME', libraryNamePattern: string | Buffer, callback?: Callback<unknown[]>): Result<unknown[], Context>;
1218+
function(subcommand: 'LIST', libraryNamePatternToken: 'LIBRARYNAME', libraryNamePattern: string | Buffer, withcode: 'WITHCODE', callback?: Callback<unknown[]>): Result<unknown[], Context>;
12101219

12111220
/**
1212-
* Deleting all functions
1221+
* Create a function with the given arguments (name, code, description)
12131222
* - _group_: scripting
1214-
* - _complexity_: O(N) where N is the number of functions deleted
1223+
* - _complexity_: O(1) (considering compilation time is redundant)
12151224
* - _since_: 7.0.0
12161225
*/
1217-
function(subcommand: 'FLUSH', callback?: Callback<unknown>): Result<unknown, Context>;
1218-
function(subcommand: 'FLUSH', async: 'ASYNC', callback?: Callback<unknown>): Result<unknown, Context>;
1219-
function(subcommand: 'FLUSH', sync: 'SYNC', callback?: Callback<unknown>): Result<unknown, Context>;
1226+
function(subcommand: 'LOAD', engineName: string | Buffer, libraryName: string | Buffer, functionCode: string | Buffer, callback?: Callback<string>): Result<string, Context>;
1227+
functionBuffer(subcommand: 'LOAD', engineName: string | Buffer, libraryName: string | Buffer, functionCode: string | Buffer, callback?: Callback<Buffer>): Result<Buffer, Context>;
1228+
function(subcommand: 'LOAD', engineName: string | Buffer, libraryName: string | Buffer, libraryDescriptionToken: 'DESCRIPTION', libraryDescription: string | Buffer, functionCode: string | Buffer, callback?: Callback<string>): Result<string, Context>;
1229+
functionBuffer(subcommand: 'LOAD', engineName: string | Buffer, libraryName: string | Buffer, libraryDescriptionToken: 'DESCRIPTION', libraryDescription: string | Buffer, functionCode: string | Buffer, callback?: Callback<Buffer>): Result<Buffer, Context>;
1230+
function(subcommand: 'LOAD', engineName: string | Buffer, libraryName: string | Buffer, replace: 'REPLACE', functionCode: string | Buffer, callback?: Callback<string>): Result<string, Context>;
1231+
functionBuffer(subcommand: 'LOAD', engineName: string | Buffer, libraryName: string | Buffer, replace: 'REPLACE', functionCode: string | Buffer, callback?: Callback<Buffer>): Result<Buffer, Context>;
1232+
function(subcommand: 'LOAD', engineName: string | Buffer, libraryName: string | Buffer, replace: 'REPLACE', libraryDescriptionToken: 'DESCRIPTION', libraryDescription: string | Buffer, functionCode: string | Buffer, callback?: Callback<string>): Result<string, Context>;
1233+
functionBuffer(subcommand: 'LOAD', engineName: string | Buffer, libraryName: string | Buffer, replace: 'REPLACE', libraryDescriptionToken: 'DESCRIPTION', libraryDescription: string | Buffer, functionCode: string | Buffer, callback?: Callback<Buffer>): Result<Buffer, Context>;
12201234

12211235
/**
12221236
* Return information about the function currently running (name, description, duration)

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"url": "https://opencollective.com/ioredis"
3838
},
3939
"dependencies": {
40-
"@ioredis/commands": "^1.0.2",
40+
"@ioredis/commands": "^1.1.0",
4141
"cluster-key-slot": "^1.1.0",
4242
"debug": "^4.3.3",
4343
"denque": "^2.0.1",

0 commit comments

Comments
 (0)