Skip to content

Conversation

@xangelix
Copy link

@xangelix xangelix commented Nov 26, 2025

Currently, LockManager abstracts away the underlying Redis connections, which prevents users from inspecting the value of a lock they failed to acquire without creating a separate, redundant Redis client.

In distributed systems where a lock represents "Leader" or "Worker" ownership of a resource, the lock's value often contains the address (e.g., DNS name or IP) of the current owner.

If a client fails to acquire a lock (lock() returns Err), they often need to "follow" the lock by reading its value to find out who currently owns it (e.g., to proxy a request to the active leader).

This allows users to reuse the existing connection pool managed by rslock to perform these lookups, rather than managing a secondary Redis pool just for inspection.

// Example usage enabled by this PR:
let manager = LockManager::new(uris);

match manager.lock(resource, ttl).await {
    Ok(lock) => { /* I am the leader */ },
    Err(_) => {
        // I am not the leader, but I can now find out who is:
        if let Ok(Some(value)) = manager.query_redis_for_key_value(resource).await {
             let leader_address = String::from_utf8(value).unwrap();
             // proxy_request(leader_address, ...);
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant