Skip to content

IDistributedLockProvider for Redis won't acquire lock when using multiple databases #240

Open

Description

@omexus

Given:

        var connectionPoolManager = services.BuildServiceProvider().GetService<IRedisConnectionPoolManager>()
                                    ?? new RedisConnectionPoolManager(connectionConfiguration);
        var dbs = connectionPoolManager.GetConnections().Select(c => c.GetDatabase());

This wont work (handle returns null always - no exception thrown):
services.AddSingleton<IDistributedLockProvider>(_ => new RedisDistributedSynchronizationProvider(dbs);
But this does work:

services.AddSingleton<IDistributedLockProvider>(_ => new RedisDistributedSynchronizationProvider(dbs.First()));

Cool library btw - Thanks!

Activity

  1. madelson commented on May 14, 2025

    @madelson
    Owner

    @omexus in this scenario are the different IDatabase objects pointing to separate keyspaces/distinct servers? If they are different views to the same DB, it won't work.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions