@@ -25,17 +25,22 @@ FUNCTION LOAD "#!lua name=library\nredis.register_function{function_name='add',
25
25
Load the prior redis function on the _ redis server_ before running the example below.
26
26
27
27
``` typescript
28
- import { createClient } from ' redis' ;
28
+ import { CommandParser } from ' @redis/client/lib/client/parser' ;
29
+ import { NumberReply } from ' @redis/client/lib/RESP/types' ;
30
+ import { createClient , RedisArgument } from ' redis' ;
29
31
30
32
const client = createClient ({
31
33
functions: {
32
34
library: {
33
35
add: {
34
36
NUMBER_OF_KEYS: 1 ,
35
- FIRST_KEY_INDEX: 1 ,
36
- parseCommand(parser : CommandParser , key : RedisArgument , toAdd : RedisArgument ) {
37
- parser .pushKey (key );
38
- parser .push (toAdd );
37
+ parseCommand(
38
+ parser : CommandParser ,
39
+ key : RedisArgument ,
40
+ toAdd : RedisArgument
41
+ ) {
42
+ parser .pushKey (key )
43
+ parser .push (toAdd )
39
44
},
40
45
transformReply: undefined as unknown as () => NumberReply
41
46
}
@@ -44,35 +49,39 @@ const client = createClient({
44
49
});
45
50
46
51
await client .connect ();
47
-
48
52
await client .set (' key' , ' 1' );
49
- await client .library .add (' key' , 2 ); // 3
53
+ await client .library .add (' key' , ' 2 ' ); // 3
50
54
```
51
55
52
56
## [ Lua Scripts] ( https://redis.io/docs/manual/programmability/eval-intro/ )
53
57
54
58
The following is an end-to-end example of the prior concept.
55
59
56
60
``` typescript
57
- import { createClient , defineScript , NumberReply } from ' redis' ;
61
+ import { CommandParser } from ' @redis/client/lib/client/parser' ;
62
+ import { NumberReply } from ' @redis/client/lib/RESP/types' ;
63
+ import { createClient , defineScript , RedisArgument } from ' redis' ;
58
64
59
65
const client = createClient ({
60
66
scripts: {
61
67
add: defineScript ({
62
68
SCRIPT: ' return redis.call("GET", KEYS[1]) + ARGV[1];' ,
63
69
NUMBER_OF_KEYS: 1 ,
64
70
FIRST_KEY_INDEX: 1 ,
65
- parseCommand(parser : CommandParser , key : RedisArgument , toAdd : RedisArgument ) {
66
- parser .pushKey (key );
67
- parser .push (toAdd );
71
+ parseCommand(
72
+ parser : CommandParser ,
73
+ key : RedisArgument ,
74
+ toAdd : RedisArgument
75
+ ) {
76
+ parser .pushKey (key )
77
+ parser .push (toAdd )
68
78
},
69
79
transformReply: undefined as unknown as () => NumberReply
70
80
})
71
81
}
72
82
});
73
83
74
84
await client .connect ();
75
-
76
85
await client .set (' key' , ' 1' );
77
- await client .add (' key' , 2 ); // 3
86
+ await client .add (' key' , ' 2 ' ); // 3
78
87
```
0 commit comments