Skip to content

rslock 0.10.0

Latest

Choose a tag to compare

@hexcowboy hexcowboy released this 27 Oct 04:04
0.10.0
3ec66fe

Changes

  • Runtime selection is now explicit: enable tokio-comp or smol-comp. No runtime is enabled by default.
  • Redis Cluster support no longer implicitly enables Smol. Select cluster together with a runtime.
  • Lock and LockGuard now provide consuming async release() methods. The guard's blocking Drop implementation has been removed.
  • Tokio and Smol expose the same lock API, including acquire, acquire_no_guard, and using. Retry timing and automatic renewal work without a Tokio runtime.
  • Dependencies are updated, including Redis 1.8.0. Examples and CI cover both runtimes, cluster configurations, and combined features.

Migrating from 0.9

Choose your runtime explicitly:

rslock = { version = "~0.10.0", features = ["tokio-comp"] }
# Or:
rslock = { version = "~0.10.0", features = ["smol-comp"] }
# For Redis Cluster, add "cluster" to either feature list.

async-std-comp remains a compatibility alias for smol-comp; Redis no longer provides a separate async-std backend. Both backends include Rustls support and can be enabled together.

Replace implicit guard cleanup with an awaited release:

let guard = manager.acquire("resource", Duration::from_secs(10)).await?;
// Work while the lock is valid.
guard.release().await;

Release consumes the guard or lock and returns (). Await it before returning, including error paths. Shared locks can continue to use manager.unlock(&lock).await.

Release awaits best-effort cleanup on all backends; it does not confirm deletion on unreachable servers. Dropping a guard, cancelling a future, or panicking performs no background cleanup. The Redis key remains until its TTL expires. Keep work within the lock's validity period and renew it as needed.

For automatic renewal, using is available on either runtime:

let result = manager.using(b"resource", Duration::from_secs(10), async || {
    do_work().await
}).await?;

using attempts release when the routine finishes or renewal fails. Cancellation and panic still rely on TTL expiry.

Thanks to @maxnoel for the original default-feature change in #56, preserved in #57. Implementation: #57 and #58.