Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect to IPv6 with interface fails #293

Closed
nils-van-zuijlen opened this issue Mar 5, 2020 · 8 comments · Fixed by #370
Closed

Connect to IPv6 with interface fails #293

nils-van-zuijlen opened this issue Mar 5, 2020 · 8 comments · Fixed by #370

Comments

@nils-van-zuijlen
Copy link

I'm trying to connect to an IPv6 redis server the same way as with the redis-cli command below:

$ redis-cli -h fe80::cafe:beef%eno1
[fe80::cafe:beef%eno1]:6379> 

I'm trying to do it with the rust code

let client = redis::Client::open("redis://fe80::cafe:beef%eno1/").expect("Can't connect to redis");

But when I run it, I get the following error:

thread 'main' panicked at 'Can't connect to redis: Redis URL did not parse', src/libcore/result.rs:1165:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

I also tried this alternative syntax, but I got the same result.

let client = redis::Client::open("redis://fe80::cafe:beef%eno1/").expect("Can't connect to redis");
@badboy
Copy link
Collaborator

badboy commented Mar 16, 2020

In general IPv6 addresses in URLs need to be wrapped in [ and ] to be parsed correctly. Looks like the %eno1 suffix however still won't work. I'd need to check how and if that's valid in URLs.

Can you try and build a ConnectionInfo directly?

@badboy
Copy link
Collaborator

badboy commented Mar 19, 2020

With this patch it could be possible to do it like this:

redis::Client::open(("fe80::cafe:beef%eno1", 6379))

@sallyyu0
Copy link

sallyyu0 commented Jun 1, 2020

I used ConnectionInfo with ipv6 address wrapped in [] but failed with following error.

234:failed to get connection for cluster ConnectionInfo { addr: Tcp("[fd00:10:0:5:5861:50ff:fe00:85]", 6379), db: 0, passwd: None } : failed to lookup address information: Name or service not known
234:failed to get connection for cluster ConnectionInfo { addr: Tcp("[fd00:10:0:5:5861:50ff:fe00:a2]", 6379), db: 0, passwd: None } : failed to lookup address information: Name or service not known
234:failed to get connection for cluster ConnectionInfo { addr: Tcp("[fd00:10:0:4:5861:50ff:fe00:8e]", 6379), db: 0, passwd: None } : failed to lookup address information: Name or service not known
234:failed to get connection for cluster ConnectionInfo { addr: Tcp("[fd00:10:0:5:5861:50ff:fe00:94]", 6379), db: 0, passwd: None } : failed to lookup address information: Name or service not known

@badboy
Copy link
Collaborator

badboy commented Jun 1, 2020

You shouldn't need the brackets ([]) in ConnectionInfo.

@sallyyu0
Copy link

sallyyu0 commented Jun 1, 2020

yup, removed [] and it worked.

@sallyyu0
Copy link

sallyyu0 commented Jun 5, 2020

There are places that connect() still uses string url stored in slots(ex: "redis://fd00:10:0:5:5861:50ff:fe00:85:6379") instead of ConnectionInfo. Can those be updated to use ConnectionInfo instead?

fn get_conn_info(redis_url: &str) -> Option<ConnectionInfo> {
    let v: Vec<&str> = redis_url.split("://").collect();
    if v.len() == 2 {
        let h: Vec<&str> = v[1].split(":").collect();
        let port: u16 = h[h.len() - 1].parse().unwrap();
        let (host, _) = v[1].split_at(v[1].len() - port.to_string().len() - 1);
        return Some(ConnectionInfo {
            addr: Box::new(ConnectionAddr::Tcp(host.to_string(), port)),
            db: 0,
            passwd: None,
        });
    } else {
        return None;
    }
}

@badboy
Copy link
Collaborator

badboy commented Jun 5, 2020

Can you open a separate issue for that?

@sallyyu0
Copy link

sallyyu0 commented Jun 5, 2020

@badboy Opened issue #332, thanks.

badboy added a commit that referenced this issue Jul 29, 2020
A TCP connection only needs a host and a port.
These can be passed in as a tuple now:

  redis::Client::open(("127.0.0.1", 6379))

In addition one should be able to specify an interface:

  redis::Client::open(("fe80::cafe:beef%eno1", 6379))

Fixes #293
badboy added a commit that referenced this issue Jul 29, 2020
A TCP connection only needs a host and a port.
These can be passed in as a tuple now:

  redis::Client::open(("127.0.0.1", 6379))

In addition one should be able to specify an interface:

  redis::Client::open(("fe80::cafe:beef%eno1", 6379))

Fixes #293
jaymell pushed a commit that referenced this issue Sep 14, 2022
nonirosenfeldredis pushed a commit to nonirosenfeldredis/redis-rs that referenced this issue Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants