internal static IDbDistributedLock CreateInternalLock(PostgresAdvisoryLockKey key, string connectionString, Action <PostgresConnectionOptionsBuilder>?options)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            var(keepaliveCadence, useMultiplexing) = PostgresConnectionOptionsBuilder.GetOptions(options);

            if (useMultiplexing)
            {
                return(new OptimisticConnectionMultiplexingDbDistributedLock(key.ToString(), connectionString, PostgresMultiplexedConnectionLockPool.Instance, keepaliveCadence));
            }

            return(new DedicatedConnectionOrTransactionDbDistributedLock(key.ToString(), () => new PostgresDatabaseConnection(connectionString), useTransaction: false, keepaliveCadence));
        }
        internal static (TimeoutValue keepaliveCadence, bool useMultiplexing) GetOptions(Action <PostgresConnectionOptionsBuilder>?optionsBuilder)
        {
            PostgresConnectionOptionsBuilder?options;

            if (optionsBuilder != null)
            {
                options = new PostgresConnectionOptionsBuilder();
                optionsBuilder(options);
            }
            else
            {
                options = null;
            }

            var keepaliveCadence = options?._keepaliveCadence ?? Timeout.InfiniteTimeSpan;
            var useMultiplexing  = options?._useMultiplexing ?? true;

            return(keepaliveCadence, useMultiplexing);
        }