11#[ macro_use]
22extern crate redismodule;
33
4- use redismodule:: { Context , RedisResult , NextArg } ;
4+ use redismodule:: { Context , RedisResult , NextArg , REDIS_OK } ;
55use redismodule:: native_types:: RedisType ;
66
77mod redisjson;
@@ -11,7 +11,6 @@ use crate::redisjson::RedisJSON;
1111static REDIS_JSON_TYPE : RedisType = RedisType :: new ( "RedisJSON" ) ;
1212
1313fn json_set ( ctx : & Context , args : Vec < String > ) -> RedisResult {
14-
1514 let mut args = args. into_iter ( ) . skip ( 1 ) ;
1615
1716 let key = args. next_string ( ) ?;
@@ -30,7 +29,7 @@ fn json_set(ctx: &Context, args: Vec<String>) -> RedisResult {
3029 }
3130 }
3231
33- Ok ( "OK" . into ( ) )
32+ REDIS_OK
3433}
3534
3635fn json_get ( ctx : & Context , args : Vec < String > ) -> RedisResult {
@@ -39,13 +38,12 @@ fn json_get(ctx: &Context, args: Vec<String>) -> RedisResult {
3938 let key = args. next_string ( ) ?;
4039
4140 let mut path = loop {
42-
4341 let arg = match args. next_string ( ) {
44- Ok ( n ) => n ,
45- Err ( _) => String :: from ( "$" ) // path is optional
42+ Ok ( s ) => s . to_uppercase ( ) ,
43+ Err ( _) => "$" . to_owned ( ) // path is optional
4644 } ;
4745
48- match arg. as_ref ( ) {
46+ match arg. as_str ( ) {
4947 "INDENT" => args. next ( ) , // TODO add support
5048 "NEWLINE" => args. next ( ) , // TODO add support
5149 "SPACE" => args. next ( ) , // TODO add support
@@ -54,6 +52,7 @@ fn json_get(ctx: &Context, args: Vec<String>) -> RedisResult {
5452 _ => break arg
5553 } ;
5654 } ;
55+
5756 if path. starts_with ( "." ) { // backward compatibility
5857 path. insert ( 0 , '$' ) ;
5958 }
0 commit comments