Xuanwo opened a new pull request, #8956: URL: https://github.com/apache/opendal/pull/8956
# Which issue does this PR close? None. # Rationale for this change `opendal-service-redis` had four bugs across TTL encoding, endpoint parsing, metadata/range reads, and builder/URI configuration: 1. **`default_ttl` truncated to whole seconds**: `RedisCore::set` passed `dur.as_secs()` to `SETEX`, so any positive `default_ttl` under 1 second sent `SETEX key 0` (failing every write in Redis), and fractional values such as `1500ms` silently truncated to `1s`. 2. **Broken IPv6 literals and schemeless endpoints**: `RedisBuilder::get_connection_info` kept brackets returned by `http::Uri::host()` (e.g., `"[::1]"`) when constructing `ConnectionAddr::Tcp` / `ConnectionAddr::TcpTls`, breaking TCP resolution and TLS SNI. Schemeless host-only endpoints such as `"redis.internal"` were parsed by `http::Uri` as a path with no host, silently falling back to `127.0.0.1:6379`. 3. **Multi-round-trip `stat` and `read` range races**: `RedisCore::len` issued separate `EXISTS` and `STRLEN` commands, so a key expiring between them produced a false `0`-byte file instead of `NotFound` (and could hit different nodes under cluster replica reads). `RedisReader` also issued `len()` followed by `get_range()` in separate round trips, where concurrent key expiry or mutation could return empty/mismatched bytes instead of `NotFound` or a retryable temporary error. 4. **Config panic and ignored URI credentials**: `connection_pool_max_size = Some(0)` panicked inside `fastpool::bounded::Pool::new` instead of returning `ConfigInvalid`. `RedisConfig::from_uri` ignored userinfo credentials from `redis://user:password@host:port/db`. # What changes are included in this PR? - **Millisecond `default_ttl` via `SET ... PX`**: Unify `default_ttl` and per-write `expires` encoding through `encode_expiration` / `resolve_expiration`, rounding positive durations up to whole milliseconds (`PX`), treating `Duration::ZERO` as disabled for `default_ttl` (while keeping zero per-write `expires` as `ConfigInvalid`), and validating out-of-range `default_ttl` during `RedisBuilder::build`. Update builder and service docs accordingly. - **IPv6 and schemeless endpoint parsing**: Normalize schemeless TCP endpoints by prefixing `tcp://` before URI parsing, strip enclosing `[` `]` from IPv6 hosts, reject missing hosts and missing Unix socket paths with `ConfigInvalid`, and fix the `Client::open` error context to avoid unwrapping `self.config.endpoint`. - **Single-pipeline `len` and `get_range`**: Pipeline `STRLEN` + `EXISTS` in `RedisCore::len` and `GETRANGE` + `STRLEN` + `EXISTS` in `RedisCore::get_range` on one connection. Return `NotFound` when the key is missing (`len == 0 && !exists`) and return a temporary `Unexpected` error if the returned slice length disagrees with the computed range due to concurrent modification. - **Config validation and URI credentials**: Reject `connection_pool_max_size == Some(0)` in `RedisBuilder::build` with `ConfigInvalid`, and populate `username` and `password` from `OperatorUri` in `RedisConfig::from_uri` without overriding explicit options. - **Unit tests**: Add unit tests covering expiration resolution and bounds, IPv6/schemeless/Unix endpoint parsing, config validation, `from_uri` credentials, and `GETRANGE` bound conversion. # Are there any user-facing changes? - `RedisBuilder::default_ttl` now uses millisecond precision (`SET ... PX`) with sub-millisecond positive durations rounded up to `1ms`, and `Duration::ZERO` disables default expiration instead of failing writes. - IPv6 endpoints (e.g., `redis://[::1]:6380`, `rediss://[::1]`, `[::1]:6380`) and schemeless hostnames (e.g., `redis.internal`, `redis.internal:6380`) now connect to the configured host instead of failing or falling back to `127.0.0.1`. - Setting `connection_pool_max_size` to `0` now returns `ErrorKind::ConfigInvalid` instead of panicking. - `Operator::from_uri` for `redis://` and `rediss://` now extracts `username` and `password` from the URI when not explicitly overridden in options. # Breaking changes # AI Usage Statement - Harness: pi - Model: Gemini 4 Neon - Effort: high - Role: Audited the reported bugs in `opendal-service-redis`, implemented the fixes and unit tests, and verified the changes against `cargo fmt`, `cargo clippy`, unit/doc tests, and a local Redis server running the `redis` behavior test suite and `MONITOR` inspection of `SET ... PX` and pipelined `STRLEN`/`EXISTS` commands. No cluster or replica deployment was tested live; single-connection pipelining relies on `redis-rs` routing all commands for the same key to one slot/connection. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
