public static RedisDatabaseFactory Create(Context context, IConnectionStringProvider provider, RedisConnectionMultiplexerConfiguration configuration)
        {
            Func <Task <IConnectionMultiplexer> > connectionMultiplexerFactory = () => RedisConnectionMultiplexer.CreateAsync(context, provider, configuration);

            Func <IConnectionMultiplexer, Task> connectionMultiplexerShutdownFunc = async m =>
            {
                ConfigurationOptions options = ConfigurationOptions.Parse(m.Configuration);
                await RedisConnectionMultiplexer.ForgetAsync(context, options);
            };

            return(new RedisDatabaseFactory(connectionMultiplexerFactory, connectionMultiplexerShutdownFunc));
        }
        public static async Task <RedisDatabaseFactory> CreateAsync(Context context, IConnectionStringProvider provider, Severity logSeverity, bool usePreventThreadTheft)
        {
            Func <Task <IConnectionMultiplexer> > connectionMultiplexerFactory = () => RedisConnectionMultiplexer.CreateAsync(context, provider, logSeverity, usePreventThreadTheft);

            Func <IConnectionMultiplexer, Task> connectionMultiplexerShutdownFunc = async m =>
            {
                ConfigurationOptions options = ConfigurationOptions.Parse(m.Configuration);
                await RedisConnectionMultiplexer.ForgetAsync(context, options);
            };

            var connectionMultiplexer = await connectionMultiplexerFactory();

            return(new RedisDatabaseFactory(connectionMultiplexer, connectionMultiplexerFactory, connectionMultiplexerShutdownFunc));
        }
Exemple #3
0
        public static async Task <RedisDatabaseFactory> CreateAsync(Context context, IConnectionStringProvider provider)
        {
            Func <Task <IConnectionMultiplexer> > connectionMultiplexerFactory = () => RedisConnectionMultiplexer.CreateAsync(context, provider);

            Func <IConnectionMultiplexer, Task> connectionMultiplexerShutdownFunc = async m =>
            {
                ConfigurationOptions options = ConfigurationOptions.Parse(m.Configuration);
                await RedisConnectionMultiplexer.ForgetAsync(options);
            };

            var multiplexer = await RedisConnectionMultiplexer.CreateAsync(context, provider);

            var databaseFactory = new RedisDatabaseFactory(multiplexer, connectionMultiplexerFactory, connectionMultiplexerShutdownFunc);

            return(databaseFactory);
        }
Exemple #4
0
        /// <summary>
        /// Gets a Redis Database object with a specified key prefix.
        /// </summary>
        public async Task <IDatabase> GetDatabaseWithKeyPrefix(Context context, string keySpace)
        {
            if (_resetConnectionMultiplexer)
            {
                using (await SemaphoreSlimToken.Wait(_creationSemaphore))
                {
                    if (_resetConnectionMultiplexer)
                    {
                        ConfigurationOptions options = ConfigurationOptions.Parse(_connectionMultiplexer.Configuration);
                        await RedisConnectionMultiplexer.ForgetAsync(options);

                        _connectionMultiplexer = await RedisConnectionMultiplexer.CreateAsync(context, _connectionStringProvider);

                        _resetConnectionMultiplexer = false;
                    }
                }
            }

            return(_connectionMultiplexer.GetDatabase().WithKeyPrefix(keySpace));
        }
Exemple #5
0
 /// <summary>
 /// Starts up the database factory.
 /// </summary>
 private async Task StartupAsync(Context context)
 {
     _connectionMultiplexer = await RedisConnectionMultiplexer.CreateAsync(context, _connectionStringProvider);
 }