Skip to content

Commit b078cca

Browse files
cmyuiclaudeinfernalfire72
authored
Modernize Rust syntax patterns (#38)
* Fix GLIBC version mismatch in Docker build Use rust:bookworm instead of rust:latest for the build stage to match the runtime stage (debian:bookworm-slim). rust:latest is now based on a newer Debian version with GLIBC 2.38, while bookworm-slim has GLIBC 2.36, causing runtime failures. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Modernize Rust syntax patterns This commit updates the codebase to use modern Rust idioms and patterns: - Replace turbofish type annotations (::<_, _, _, ()>) with type ascription (let _: () =) for unit-returning Redis operations, improving readability - Use let-else syntax (Rust 2021+) instead of is_none() + unwrap() patterns for cleaner early returns - Replace is_err() + unwrap_err() with if-let Err for more idiomatic error handling - Eliminate unnecessary .clone() calls on Option types before unwrap by using as_ref() - Optimize memory usage by removing .to_vec() from chunk iteration where not needed - Remove explicit return statements in favor of implicit returns (Rust style guide) These changes improve code clarity, reduce allocations, and align with modern Rust best practices without changing functionality. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Upgrade redis crate from 0.22.0 to 1.0.2 This commit upgrades the redis dependency to version 1.0.2, eliminating the future incompatibility warnings related to never type fallback. Breaking changes addressed: 1. **Async connection method renamed** - Changed `.get_async_connection()` to `.get_multiplexed_async_connection()` - The new multiplexed connection is designed for concurrent use without pooling 2. **Connection construction modernized** - Replaced manual `ConnectionInfo` struct construction with connection URL strings - Added `redis_url()` helper function to build proper redis:// or rediss:// URLs - Handles username, password, SSL, host, port, and database parameters - Avoids issues with private fields introduced in redis 1.0 (`tcp_settings`, etc.) - Username now uses `ArcStr` internally (handled automatically by URL parsing) 3. **Import cleanup** - Removed unused imports: `ConnectionAddr`, `ConnectionInfo`, `RedisConnectionInfo` - These types are no longer needed with URL-based connection approach Benefits of the upgrade: - ✅ Eliminates never type fallback warnings (future Rust 2024 compatibility) - ✅ Adds default connection/response timeouts (5s/10s) to prevent indefinite hangs - ✅ Better async performance with multiplexed connections - ✅ More maintainable connection string approach - ✅ Zero-copy deserialization improvements in underlying library All tests pass. No functional changes to application behavior. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Address Copilot review feedback 1. Add URL encoding for Redis credentials - Add percent-encoding dependency (already in transitive deps) - Encode username and password to handle special characters (@, :, etc.) - Prevents connection failures when credentials contain URL-unsafe chars 2. Replace unsafe unwrap with expect - Change unwrap() to expect() with descriptive message - Makes panic reason explicit if logic error occurs - Improves debugging experience Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Update src/deploy/mod.rs Co-authored-by: Julius <41292439+infernalfire72@users.noreply.github.com> * Update src/deploy/mod.rs Co-authored-by: Julius <41292439+infernalfire72@users.noreply.github.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Julius <41292439+infernalfire72@users.noreply.github.com>
1 parent 9155d9f commit b078cca

12 files changed

Lines changed: 201 additions & 82 deletions

File tree

Cargo.lock

Lines changed: 128 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ rkyv = { version = "0.7", features = ["validation"] }
3232
bytecheck = "0.6.9"
3333
tokio-executor-trait = "2.1.0"
3434
tokio-stream = "0.1.11"
35-
redis = { version = "0.22.0", features = ["tokio-comp"] }
35+
redis = { version = "1", features = ["tokio-comp"] }
36+
percent-encoding = "2.3"
3637
bcrypt = "0.13.0"
3738
uuid = { version = "1.2.1", features = ["v4"] }
3839
futures = "0.3.17"

src/api/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn api_router() -> Router {
2323

2424
pub async fn serve(ctx: Context) -> anyhow::Result<()> {
2525
let server_port = ctx.config.api_port.unwrap();
26-
let server_host = ctx.config.api_host.clone().unwrap();
26+
let server_host = ctx.config.api_host.as_ref().unwrap().clone();
2727

2828
let app = api_router().layer(
2929
ServiceBuilder::new()

src/api/routes/health.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async fn health(Extension(ctx): Extension<Arc<Context>>) -> http::StatusCode {
1313
let mut is_redis_ok = false;
1414
let mut is_database_ok = false;
1515

16-
if let Ok(mut conn) = ctx.redis.get_async_connection().await {
16+
if let Ok(mut conn) = ctx.redis.get_multiplexed_async_connection().await {
1717
if let Ok(_result) = conn
1818
.req_packed_command(&Cmd::new().arg("PING").arg(1))
1919
.await

0 commit comments

Comments
 (0)