@@ -15,7 +15,7 @@ fn json_set(ctx: &Context, args: Vec<String>) -> RedisResult {
1515 let mut args = args. into_iter ( ) . skip ( 1 ) ;
1616
1717 let key = args. next_string ( ) ?;
18- let value = args. next_string ( ) ?;
18+ let value = args. next_string ( ) ?;
1919
2020 let key = ctx. open_key_writable ( & key) ;
2121
@@ -40,22 +40,37 @@ fn json_get(ctx: &Context, args: Vec<String>) -> RedisResult {
4040 let key = ctx. open_key_writable ( & key) ;
4141
4242 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 ( ) ,
4444 None => ( ) . into ( )
4545 } ;
4646
4747 Ok ( value)
4848}
4949
50- fn json_type ( ctx : & Context , args : Vec < String > ) -> RedisResult {
50+ fn json_strlen ( ctx : & Context , args : Vec < String > ) -> RedisResult {
5151 let mut args = args. into_iter ( ) . skip ( 1 ) ;
5252 let key = args. next_string ( ) ?;
5353 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+ }
5464
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+
5570 let key = ctx. open_key_writable ( & key) ;
5671
5772 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 ( ) ,
5974 None => ( ) . into ( )
6075 } ;
6176
@@ -73,6 +88,7 @@ redis_module! {
7388 commands: [
7489 [ "json.set" , json_set, "write" ] ,
7590 [ "json.get" , json_get, "" ] ,
91+ [ "json.strlen" , json_strlen, "" ] ,
7692 [ "json.type" , json_type, "" ] ,
7793 ] ,
7894}
0 commit comments