@@ -58,29 +58,33 @@ macro_rules! redis_command {
5858 return $crate:: raw:: Status :: Err as c_int;
5959 }
6060
61- let mandatory_acl_categories = AclCategory :: from( $mandatory_acl_categories) ;
61+ let mandatory = AclCategory :: from( $mandatory_acl_categories) ;
6262 if let Some ( RM_SetCommandACLCategories ) = $crate:: raw:: RedisModule_SetCommandACLCategories {
63+ let mut optional_failed = true ;
6364 let mut acl_categories = CString :: default ( ) ;
6465 $(
65- let optional_acl_categories = AclCategory :: from( $optional_acl_categories) ;
66- if mandatory_acl_categories != AclCategory :: None && optional_acl_categories != AclCategory :: None {
67- acl_categories = CString :: new( format!( "{} {}" , mandatory_acl_categories, optional_acl_categories) ) . unwrap( ) ;
68- } else if optional_acl_categories != AclCategory :: None {
69- acl_categories = CString :: new( format!( "{}" , $optional_acl_categories) ) . unwrap( ) ;
66+ let optional = AclCategory :: from( $optional_acl_categories) ;
67+ assert!( optional != AclCategory :: None ) ;
68+ optional_failed = false ;
69+ if mandatory != AclCategory :: None {
70+ acl_categories = CString :: new( format!( "{mandatory} {optional}" ) ) . unwrap( ) ;
71+ } else {
72+ acl_categories = CString :: new( format!( "{optional}" ) ) . unwrap( ) ;
7073 }
7174 // Warn if optional ACL categories are not set, but don't fail.
7275 if RM_SetCommandACLCategories ( command, acl_categories. as_ptr( ) ) == $crate:: raw:: Status :: Err as c_int {
76+ optional_failed = true ;
7377 $crate:: raw:: redis_log(
7478 $ctx,
7579 & format!(
7680 "Warning: failed to set command `{}` ACL categories `{}`" ,
7781 $command_name, acl_categories. to_str( ) . unwrap( )
7882 ) ,
7983 ) ;
80- } else
84+ }
8185 ) ?
82- if mandatory_acl_categories != AclCategory :: None {
83- acl_categories = CString :: new( format!( "{}" , mandatory_acl_categories ) ) . unwrap( ) ;
86+ if optional_failed && mandatory != AclCategory :: None {
87+ acl_categories = CString :: new( format!( "{mandatory}" ) ) . unwrap( ) ;
8488
8589 // Fail if mandatory ACL categories are not set.
8690 if RM_SetCommandACLCategories ( command, acl_categories. as_ptr( ) )
@@ -89,14 +93,14 @@ macro_rules! redis_command {
8993 $crate:: raw:: redis_log(
9094 $ctx,
9195 & format!(
92- "Error: failed to set command `{}` mandatory ACL categories `{}`" ,
93- $command_name, mandatory_acl_categories
96+ "Error: failed to set command `{}` mandatory ACL categories `{mandatory }`" ,
97+ $command_name
9498 ) ,
9599 ) ;
96100 return $crate:: raw:: Status :: Err as c_int;
97101 }
98102 }
99- } else if mandatory_acl_categories != AclCategory :: None {
103+ } else if mandatory != AclCategory :: None {
100104 $crate:: raw:: redis_log(
101105 $ctx,
102106 "Error: Redis version does not support ACL categories" ,
@@ -317,9 +321,9 @@ macro_rules! redis_module {
317321 if let Some ( RM_AddACLCategory ) = raw:: RedisModule_AddACLCategory {
318322 let module_acl_category = AclCategory :: from( $module_acl_category) ;
319323 if module_acl_category != AclCategory :: None {
320- let category = CString :: new( format!( "{}" , $module_acl_category ) ) . unwrap( ) ;
324+ let category = CString :: new( format!( "{module_acl_category}" ) ) . unwrap( ) ;
321325 if RM_AddACLCategory ( ctx, category. as_ptr( ) ) == raw:: Status :: Err as c_int {
322- raw:: redis_log( ctx, & format!( "Error: failed to add ACL category `{}`" , $module_acl_category ) ) ;
326+ raw:: redis_log( ctx, & format!( "Error: failed to add ACL category `{module_acl_category }`" ) ) ;
323327 return raw:: Status :: Err as c_int;
324328 }
325329 }
0 commit comments