From 2059c12868549889f8c59bda81d343a9b8cae107 Mon Sep 17 00:00:00 2001 From: tottoto Date: Sat, 6 Dec 2025 23:49:47 +0900 Subject: [PATCH] examples: Update to redis 1 (#3528) --- examples/Cargo.lock | 40 ++++++++++++++++++-------------- examples/tokio-redis/Cargo.toml | 3 ++- examples/tokio-redis/src/main.rs | 14 ++++------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/examples/Cargo.lock b/examples/Cargo.lock index 6d0a0b38..58bb532d 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -87,6 +87,12 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" +[[package]] +name = "arcstr" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03918c3dbd7701a85c6b9887732e2921175f26c350b4563841d0958c21d57e6d" + [[package]] name = "arrayref" version = "0.3.9" @@ -412,12 +418,13 @@ dependencies = [ [[package]] name = "bb8" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d8b8e1a22743d9241575c6ba822cf9c8fef34771c86ab7e477a4fbfd254e5" +checksum = "457d7ed3f888dfd2c7af56d4975cade43c622f74bdcddfed6d4352f57acc6310" dependencies = [ "futures-util", "parking_lot", + "portable-atomic", "tokio", ] @@ -432,16 +439,6 @@ dependencies = [ "tokio-postgres", ] -[[package]] -name = "bb8-redis" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5143936af5e1eea1a881e3e3d21b6777da6315e5e307bc3d0c2301c44fa37da9" -dependencies = [ - "bb8", - "redis", -] - [[package]] name = "bincode" version = "1.3.3" @@ -1825,7 +1822,8 @@ name = "example-tokio-redis" version = "0.1.0" dependencies = [ "axum", - "bb8-redis", + "bb8", + "redis", "tokio", "tracing", "tracing-subscriber", @@ -2704,7 +2702,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" dependencies = [ "cfg-if 1.0.0", - "windows-targets 0.52.6", + "windows-targets 0.53.5", ] [[package]] @@ -3681,16 +3679,17 @@ dependencies = [ [[package]] name = "redis" -version = "0.32.7" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "014cc767fefab6a3e798ca45112bccad9c6e0e218fbd49720042716c73cfef44" +checksum = "47ba378d39b8053bffbfc2750220f5a24a06189b5129523d5db01618774e0239" dependencies = [ + "arcstr", + "bb8", "bytes", "cfg-if 1.0.0", "combine", "futures-util", "itoa", - "num-bigint", "percent-encoding", "pin-project-lite", "ryu", @@ -3698,6 +3697,7 @@ dependencies = [ "tokio", "tokio-util", "url", + "xxhash-rust", ] [[package]] @@ -5719,6 +5719,12 @@ dependencies = [ "tap", ] +[[package]] +name = "xxhash-rust" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3" + [[package]] name = "yoke" version = "0.8.0" diff --git a/examples/tokio-redis/Cargo.toml b/examples/tokio-redis/Cargo.toml index 440065c9..ffc1a757 100644 --- a/examples/tokio-redis/Cargo.toml +++ b/examples/tokio-redis/Cargo.toml @@ -6,7 +6,8 @@ publish = false [dependencies] axum = { path = "../../axum" } -bb8-redis = "0.24" +bb8 = "0.9" +redis = { version = "1", default-features = false, features = ["tokio-comp", "bb8"] } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/tokio-redis/src/main.rs b/examples/tokio-redis/src/main.rs index 6c32b666..fc179055 100644 --- a/examples/tokio-redis/src/main.rs +++ b/examples/tokio-redis/src/main.rs @@ -10,11 +10,7 @@ use axum::{ routing::get, Router, }; -use bb8_redis::{ - bb8::{self, Pool, PooledConnection}, - redis::AsyncCommands, - RedisConnectionManager, -}; +use redis::AsyncCommands; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] @@ -28,8 +24,8 @@ async fn main() { .init(); tracing::debug!("connecting to redis"); - let manager = RedisConnectionManager::new("redis://localhost").unwrap(); - let pool = bb8::Pool::builder().build(manager).await.unwrap(); + let client = redis::Client::open("redis://localhost").unwrap(); + let pool = bb8::Pool::builder().build(client).await.unwrap(); { // ping the database before starting @@ -56,7 +52,7 @@ async fn main() { axum::serve(listener, app).await.unwrap(); } -type ConnectionPool = Pool; +type ConnectionPool = bb8::Pool; async fn using_connection_pool_extractor( State(pool): State, @@ -68,7 +64,7 @@ async fn using_connection_pool_extractor( // we can also write a custom extractor that grabs a connection from the pool // which setup is appropriate depends on your application -struct DatabaseConnection(PooledConnection<'static, RedisConnectionManager>); +struct DatabaseConnection(bb8::PooledConnection<'static, redis::Client>); impl FromRequestParts for DatabaseConnection where