DistributedLock icon indicating copy to clipboard operation
DistributedLock copied to clipboard

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

Open omexus opened this issue 10 months ago • 1 comments

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!

omexus avatar Feb 28 '25 00:02 omexus

@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.

madelson avatar May 14 '25 00:05 madelson