valkey_module/context/
auth.rs

1use crate::{raw, Context, ValkeyString};
2use std::os::raw::{c_char, c_int};
3use std::ptr;
4
5impl Context {
6    /// Authenticates a client using an ACL user
7    ///
8    /// # Arguments
9    /// * `username` - ACL username to authenticate with
10    ///
11    /// # Returns
12    /// * `Status::Ok` - Authentication successful
13    /// * `Status::Err` - Authentication failed
14    pub fn authenticate_client_with_acl_user(&self, username: &ValkeyString) -> raw::Status {
15        let result = unsafe {
16            raw::RedisModule_AuthenticateClientWithACLUser.unwrap()(
17                self.ctx,
18                username.as_ptr().cast::<c_char>(),
19                username.len(),
20                None,
21                ptr::null_mut(),
22                ptr::null_mut(),
23            )
24        };
25
26        if result == raw::REDISMODULE_OK as c_int {
27            raw::Status::Ok
28        } else {
29            raw::Status::Err
30        }
31    }
32}