Skip to content

Commit

Permalink
update bb8_redis
Browse files Browse the repository at this point in the history
this was needed to support ipv6 url
  • Loading branch information
muhamadazmy committed Apr 11, 2023
1 parent 30d8a67 commit 511d12c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 26 deletions.
38 changes: 13 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tar = "0.4"
flate2 = "1.0"
snap = "1.0.5"
async-recursion = "1.0.0"
bb8-redis = "0.11.0"
bb8-redis = "0.13"
async-trait = "0.1.53"
url = "2.3.1"
# next are only needed for the binarys
Expand Down
32 changes: 32 additions & 0 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl Cache {

u.set_path("");

log::debug!("switching namespace to: {:?}", namespace);
let mgr = RedisConnectionManager::new(u)?;
let namespace = WithNamespace { namespace };
let pool = Pool::builder()
Expand Down Expand Up @@ -199,3 +200,34 @@ impl Locker {
Ok(())
}
}

#[cfg(test)]
mod test {
#[test]
fn test_url() {
let mut u =
url::Url::parse("redis://[2001:728:1000:402:70b4:a3ff:fe89:bf13]:9900/604-22888-zdb1")
.unwrap();
let namespace: Option<String> = match u.path_segments() {
None => None,
Some(mut segments) => segments.next().map(|s| s.to_owned()),
};

assert!(matches!(namespace, Some(ref s) if s == "604-22888-zdb1"));

u.set_path("");

assert_eq!(
u.to_string(),
"redis://[2001:728:1000:402:70b4:a3ff:fe89:bf13]:9900"
);
}

#[test]
fn test_redis() {
use bb8_redis::redis::{cmd, Client};
let mut con = Client::open("redis://[2001:728:1000:402:70b4:a3ff:fe89:bf13]:9900").unwrap();

let _: () = cmd("PING").query(&mut con).unwrap();
}
}

0 comments on commit 511d12c

Please sign in to comment.