@@ -6,7 +6,7 @@ import { CommandArgs } from "./types";
6
6
// properties which are only available in redis
7
7
type redisOnly = Exclude < keyof Redis , keyof Pipeline > ;
8
8
9
- export function createAutoPipelineProxy ( _redis : Redis ) {
9
+ export function createAutoPipelineProxy ( _redis : Redis , json ?: boolean ) : Redis {
10
10
const redis = _redis as Redis & {
11
11
autoPipelineExecutor : AutoPipelineExecutor ;
12
12
} ;
@@ -22,27 +22,34 @@ export function createAutoPipelineProxy(_redis: Redis) {
22
22
return redis . autoPipelineExecutor . pipelineCounter ;
23
23
}
24
24
25
+ if ( command === "json" ) {
26
+ return createAutoPipelineProxy ( redis , true ) ;
27
+ } ;
28
+
25
29
const commandInRedisButNotPipeline =
26
30
command in redis && ! ( command in redis . autoPipelineExecutor . pipeline ) ;
27
31
28
32
if ( commandInRedisButNotPipeline ) {
29
33
return redis [ command as redisOnly ] ;
30
34
}
31
35
32
- command = command as keyof Pipeline ;
33
36
// If the method is a function on the pipeline, wrap it with the executor logic
34
- if ( typeof redis . autoPipelineExecutor . pipeline [ command ] === "function" ) {
37
+ if ( typeof redis . autoPipelineExecutor . pipeline [ command as keyof Pipeline ] === "function" ) {
35
38
return ( ...args : CommandArgs < typeof Command > ) => {
36
39
// pass the function as a callback
37
40
return redis . autoPipelineExecutor . withAutoPipeline ( ( pipeline ) => {
38
- ( pipeline [ command ] as Function ) ( ...args ) ;
41
+ if ( json ) {
42
+ ( pipeline . json [ command as keyof Pipeline [ "json" ] ] as Function ) ( ...args )
43
+ } else {
44
+ ( pipeline [ command as keyof Pipeline ] as Function ) ( ...args ) ;
45
+ }
39
46
} ) ;
40
47
} ;
41
48
}
42
49
43
50
// if the property is not a function, a property of redis or "pipelineCounter"
44
51
// simply return it from pipeline
45
- return redis . autoPipelineExecutor . pipeline [ command ] ;
52
+ return redis . autoPipelineExecutor . pipeline [ command as keyof Pipeline ] ;
46
53
} ,
47
54
} ) as Redis ;
48
55
}
0 commit comments