mco_redis/cmd/
auth.rs

1use super::{Command, CommandError};
2use crate::codec_redis::{BulkString, Request, Response};
3
4/// AUTH redis command
5pub fn Auth<T>(password: T) -> AuthCommand
6where
7    BulkString: From<T>,
8{
9    AuthCommand(Request::Array(vec![
10        Request::from_static("AUTH"),
11        Request::BulkString(password.into()),
12    ]))
13}
14
15pub struct AuthCommand(Request);
16
17impl Command for AuthCommand {
18    type Output = bool;
19
20    fn to_request(self) -> Request {
21        self.0
22    }
23
24    fn to_output(val: Response) -> Result<Self::Output, CommandError> {
25        match val {
26            Response::String(val) => Ok(val == "OK"),
27            _ => Ok(false),
28        }
29    }
30}