@@ -15,7 +15,7 @@ fn json_set(ctx: &Context, args: Vec<String>) -> RedisResult {
15
15
let mut args = args. into_iter ( ) . skip ( 1 ) ;
16
16
17
17
let key = args. next_string ( ) ?;
18
- let value = args. next_string ( ) ?;
18
+ let value = args. next_string ( ) ?;
19
19
20
20
let key = ctx. open_key_writable ( & key) ;
21
21
@@ -40,22 +40,37 @@ fn json_get(ctx: &Context, args: Vec<String>) -> RedisResult {
40
40
let key = ctx. open_key_writable ( & key) ;
41
41
42
42
let value = match key. get_value :: < RedisJSON > ( & REDIS_JSON_TYPE ) ? {
43
- Some ( doc) => { doc. to_string ( & path) ?. into ( ) }
43
+ Some ( doc) => doc. to_string ( & path) ?. into ( ) ,
44
44
None => ( ) . into ( )
45
45
} ;
46
46
47
47
Ok ( value)
48
48
}
49
49
50
- fn json_type ( ctx : & Context , args : Vec < String > ) -> RedisResult {
50
+ fn json_strlen ( ctx : & Context , args : Vec < String > ) -> RedisResult {
51
51
let mut args = args. into_iter ( ) . skip ( 1 ) ;
52
52
let key = args. next_string ( ) ?;
53
53
let path = args. next_string ( ) ?;
54
+
55
+ let key = ctx. open_key_writable ( & key) ;
56
+
57
+ let length = match key. get_value :: < RedisJSON > ( & REDIS_JSON_TYPE ) ? {
58
+ Some ( doc) => doc. str_len ( & path) ?. into ( ) ,
59
+ None => ( ) . into ( )
60
+ } ;
61
+
62
+ Ok ( length)
63
+ }
54
64
65
+ fn json_type ( ctx : & Context , args : Vec < String > ) -> RedisResult {
66
+ let mut args = args. into_iter ( ) . skip ( 1 ) ;
67
+ let key = args. next_string ( ) ?;
68
+ let path = args. next_string ( ) ?;
69
+
55
70
let key = ctx. open_key_writable ( & key) ;
56
71
57
72
let value = match key. get_value :: < RedisJSON > ( & REDIS_JSON_TYPE ) ? {
58
- Some ( doc) => { doc. get_type ( & path) ?. into ( ) }
73
+ Some ( doc) => doc. get_type ( & path) ?. into ( ) ,
59
74
None => ( ) . into ( )
60
75
} ;
61
76
@@ -73,6 +88,7 @@ redis_module! {
73
88
commands: [
74
89
[ "json.set" , json_set, "write" ] ,
75
90
[ "json.get" , json_get, "" ] ,
91
+ [ "json.strlen" , json_strlen, "" ] ,
76
92
[ "json.type" , json_type, "" ] ,
77
93
] ,
78
94
}
0 commit comments