@@ -16,11 +16,25 @@ pub enum SetOptions {
1616 AlreadyExists ,
1717}
1818
19+ fn json_del ( ctx : & Context , args : Vec < String > ) -> RedisResult {
20+ let mut args = args. into_iter ( ) . skip ( 1 ) ;
21+
22+ let key = args. next_string ( ) ?;
23+ let path = args. next_string ( ) ?;
24+
25+ let key = ctx. open_key_writable ( & key) ;
26+ let deleted = match key. get_value :: < RedisJSON > ( & REDIS_JSON_TYPE ) ? {
27+ Some ( doc) => doc. delete_path ( & path) ?,
28+ None => 0
29+ } ;
30+ Ok ( deleted. into ( ) )
31+ }
32+
1933fn json_set ( ctx : & Context , args : Vec < String > ) -> RedisResult {
2034 let mut args = args. into_iter ( ) . skip ( 1 ) ;
2135
2236 let key = args. next_string ( ) ?;
23- let _path = args. next_string ( ) ?; // TODO handle this path
37+ let path = args. next_string ( ) ?;
2438 let value = args. next_string ( ) ?;
2539
2640 let set_option = args. next ( )
@@ -39,7 +53,7 @@ fn json_set(ctx: &Context, args: Vec<String>) -> RedisResult {
3953 match ( current, set_option) {
4054 ( Some ( _) , Some ( SetOptions :: NotExists ) ) => Ok ( ( ) . into ( ) ) ,
4155 ( Some ( ref mut doc) , _) => {
42- doc. set_value ( & value) ?;
56+ doc. set_value ( & value, & path ) ?;
4357 REDIS_OK
4458 }
4559 ( None , Some ( SetOptions :: AlreadyExists ) ) => Ok ( ( ) . into ( ) ) ,
@@ -112,8 +126,6 @@ fn json_mget(ctx: &Context, args: Vec<String>) -> RedisResult {
112126 } else {
113127 Err ( RedisError :: WrongArity )
114128 }
115-
116-
117129}
118130
119131
@@ -157,6 +169,7 @@ redis_module! {
157169 ] ,
158170 commands: [
159171 [ "json.set" , json_set, "write" ] ,
172+ [ "json.del" , json_del, "write" ] ,
160173 [ "json.get" , json_get, "" ] ,
161174 [ "json.mget" , json_mget, "" ] ,
162175 [ "json.strlen" , json_strlen, "" ] ,
0 commit comments