benashford / redis-async-rs

A Rust client for Redis, using Tokio
Apache License 2.0
253 stars 30 forks source link

how to connect redis with password #49

Closed panicfrog closed 4 years ago

panicfrog commented 4 years ago

i don't konw how to connect redis with password

benashford commented 4 years ago

Hello,

There's no specific support for Redis authentication in this library yet. There's no "connect with password" function, largely because in the use-cases to which it has currently been applied, there's been no need.

But it can still be used to connect to Redis servers that need a password by sending the AUTH command yourself. So something like:

    let connection = client::paired_connect(&addr).await?;
    match connection.send(resp_array!["AUTH", password]).await {
        Ok(()) => println!("Authenticated"),
        Err(e) => eprintln!("Error authenticating {}", e)
    }

Although this might cause issues if the connection drops, the library will try to reconnect automatically, but the connection may need to be reauthenticated afterwards. But the best way of handling that depends on the structure of the application.

panicfrog commented 4 years ago

think you