DavidBM / rsmq-async-rs

RSMQ port to async rust. RSMQ is a simple redis queue system that works in any redis v2.6+
MIT License
43 stars 8 forks source link

Error connecting to Redis instance #16

Closed SvenKratzEasel closed 11 months ago

SvenKratzEasel commented 11 months ago

Hi we're having trouble connecting to our Redis instance, and we believe we've set all RsmqOptions correctly (e.g., hostname and password work when connecting manually via redis-cli). There might be a bug in the way the password is prefixed with "redis" in normal_facade.rs (l24):

 pub async fn new(options: RsmqOptions) -> RsmqResult<Rsmq> {
        let password = if let Some(password) = options.password.clone() {
            format!("redis:{}@", password)
        } else {
            "".to_string()
        }; 

Is prefixing "redis" a necessity? I think this is causing our authentication issue.

DavidBM commented 11 months ago

What is happening there is that the username is "redis" and then it is inserting the password into the string.

Does the password contain characters like ":" or "@"?

DavidBM commented 11 months ago

I think I will change it, so it uses the redis ConnectionInfo type directly rather than a string. So we can avoid problems with passwords with special characters

DavidBM commented 11 months ago

One thing you can do is to use the method new_with_connection. So you can build the Redis connection using the Redis crate, and then pass it to the library. In that way you won't have any issue.

Btw, the preferred way to use it is to use the MultiplexedRsmq. So you could do:

let conn_info = redis::ConnectionInfo {
    addr: redis::ConnectionAddr::Tcp("host".to_string(), 1234),
    redis: redis::RedisConnectionInfo {
        db: 1,
        username: Some("username".to_string()),
        password: Some("password".to_string()),
    },
};

let client = redis::Client::open(url)?;

let connection = client.get_multiplexed_async_connection().await?;

let mut options = RsmqOptions::default();

options.realtime = true; // or false, up to you
options.ns = "my ns"; //whatever your ns is, or let skip to use default ns

MultiplexedRsmq::new_with_connection(options, connection)
DavidBM commented 11 months ago

It would be similar if you use the normal facade, btw.

I see the interface isn't ideal. I will see if I can code some better functions tonight or tomorrow. Meanwhile, try that and let me know

DavidBM commented 11 months ago

Just updated the library to v6.0.0 which uses the internal types from redis to build the ConnectionInfo so the password is passed as-is to the redis library. That should fix your issues.

Will close this issue. Feel free to reopen if you have any other issues.

SvenKratzEasel commented 11 months ago

Thanks, David, we'll try it out!