Exemplo n.º 1
0
        /// <inheritdoc />
        protected override async Task <BoolResult> StartupCoreAsync(OperationContext context)
        {
            Tracer.TraceStartupConfiguration(context, Configuration);

            if (Configuration.RedisGlobalStoreConnectionString != null)
            {
                RedisDatabaseFactoryForRedisGlobalStore = await RedisDatabaseFactory.CreateAsync(
                    context,
                    new LiteralConnectionStringProvider(Configuration.RedisGlobalStoreConnectionString));

                if (Configuration.RedisGlobalStoreSecondaryConnectionString != null)
                {
                    RedisDatabaseFactoryForRedisGlobalStoreSecondary = await RedisDatabaseFactory.CreateAsync(
                        context,
                        new LiteralConnectionStringProvider(Configuration.RedisGlobalStoreSecondaryConnectionString));
                }
            }
            else
            {
                // Local location store can only be used if connection string is provided for redis global store
                Contract.Assert(!Configuration.HasReadOrWriteMode(ContentLocationMode.LocalLocationStore));
            }

            // Instantiate factories for old redis only when we use old redis.
            if (Configuration.HasReadOrWriteMode(ContentLocationMode.Redis))
            {
                Contract.Assert(_contentConnectionStringProvider != null);
                Contract.Assert(_machineConnectionStringProvider != null);
                RedisDatabaseFactoryForContent = await RedisDatabaseFactory.CreateAsync(context, _contentConnectionStringProvider);

                RedisDatabaseFactoryForMachineLocations = await RedisDatabaseFactory.CreateAsync(context, _machineConnectionStringProvider);
            }

            return(BoolResult.Success);
        }
Exemplo n.º 2
0
        public static async Task <RedisDatabaseFactory> CreateAsync(Func <IConnectionMultiplexer> connectionMultiplexerFactory, Func <IConnectionMultiplexer, Task> connectionMultiplexerShutdownFunc)
        {
            var databaseFactory = new RedisDatabaseFactory(() => Task.FromResult(connectionMultiplexerFactory()), connectionMultiplexerShutdownFunc);
            await databaseFactory.InitializeAsync();

            return(databaseFactory);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RedisDatabaseAdapter"/> class.
 /// </summary>
 public RedisDatabaseAdapter(RedisDatabaseFactory databaseFactory, string keySpace, int redisConnectionErrorLimit = int.MaxValue)
 {
     _databaseFactory           = databaseFactory;
     KeySpace                   = keySpace;
     _redisConnectionErrorLimit = redisConnectionErrorLimit;
     _redisRetryStrategy        = new RetryPolicy(new RedisRetryPolicy(OnRedisException), RetryStrategy.DefaultExponential);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Factory method for a database factory.
        /// </summary>
        public static Task <RedisDatabaseFactory> CreateAsync(IConnectionStringProvider provider, IConnectionMultiplexer connectionMultiplexer)
        {
            var databaseFactory = new RedisDatabaseFactory(provider);

            databaseFactory._connectionMultiplexer = connectionMultiplexer;
            return(Task.FromResult(databaseFactory));
        }
Exemplo n.º 5
0
 public RedisDatabaseAdapter(RedisDatabaseFactory databaseFactory, RedisDatabaseAdapterConfiguration configuration, IClock?clock = null)
 {
     _configuration      = configuration;
     _redisRetryStrategy = configuration.CreateRetryPolicy(OnRedisException);
     _databaseFactory    = databaseFactory;
     _clock = clock ?? SystemClock.Instance;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Factory method for a database factory.
        /// </summary>
        public static async Task <RedisDatabaseFactory> CreateAsync(Context context, IConnectionStringProvider provider)
        {
            var databaseFactory = new RedisDatabaseFactory(provider);
            await databaseFactory.StartupAsync(context);

            return(databaseFactory);
        }
Exemplo n.º 7
0
        public static Task <RedisDatabaseFactory> CreateAsync(Func <IConnectionMultiplexer> connectionMultiplexerFactory, Func <IConnectionMultiplexer, Task> connectionMultiplexerShutdownFunc)
        {
            var connectionMultiplexer = connectionMultiplexerFactory();
            var databaseFactory       = new RedisDatabaseFactory(connectionMultiplexer, () => Task.FromResult(connectionMultiplexerFactory()), connectionMultiplexerShutdownFunc);

            return(Task.FromResult(databaseFactory));
        }
        /// <inheritdoc />
        public Task <BoolResult> StartupAsync(Context context)
        {
            StartupStarted = true;
            return(StartupCall <ContentSessionTracer> .RunAsync(
                       _tracer,
                       context,
                       async() =>
            {
                _tracer.TraceStartupConfiguration(context, _configuration);

                if (_configuration.RedisGlobalStoreConnectionString != null)
                {
                    _redisDatabaseFactoryForRedisGlobalStore = await RedisDatabaseFactory.CreateAsync(
                        context,
                        new LiteralConnectionStringProvider(_configuration.RedisGlobalStoreConnectionString));

                    if (_configuration.RedisGlobalStoreSecondaryConnectionString != null)
                    {
                        _redisDatabaseFactoryForRedisGlobalStoreSecondary = await RedisDatabaseFactory.CreateAsync(
                            context,
                            new LiteralConnectionStringProvider(_configuration.RedisGlobalStoreSecondaryConnectionString));
                    }
                }
                else
                {
                    // Local location store can only be used if connection string is provided for redis global store
                    Contract.Assert(!_configuration.HasReadOrWriteMode(ContentLocationMode.LocalLocationStore));
                }

                _redisDatabaseFactoryForContent = await RedisDatabaseFactory.CreateAsync(context, _contentConnectionStringProvider);
                _redisDatabaseFactoryForMachineLocations = await RedisDatabaseFactory.CreateAsync(context, _machineConnectionStringProvider);
                StartupCompleted = true;
                return BoolResult.Success;
            }));
        }
Exemplo n.º 9
0
        public static Task <RedisDatabaseFactory> CreateAsync(IConnectionStringProvider provider, IConnectionMultiplexer connectionMultiplexer)
        {
            Func <Task <IConnectionMultiplexer> > connectionMultiplexerFactory = () => Task.FromResult(connectionMultiplexer);

            Func <IConnectionMultiplexer, Task> connectionMultiplexerShutdownFunc = m => BoolResult.SuccessTask;

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

            return(Task.FromResult(databaseFactory));
        }
 private RedisDatabaseAdapter CreateDatabase(RedisDatabaseFactory factory, bool optional = false)
 {
     if (factory != null)
     {
         return(new RedisDatabaseAdapter(factory, _keySpace));
     }
     else
     {
         Contract.Assert(optional);
         return(null);
     }
 }
Exemplo n.º 11
0
 private RedisDatabaseAdapter CreateDatabase(RedisDatabaseFactory factory, bool optional = false)
 {
     if (factory != null)
     {
         return(new RedisDatabaseAdapter(factory, KeySpace, redisConnectionErrorLimit: Configuration.RedisConnectionErrorLimit));
     }
     else
     {
         Contract.Assert(optional);
         return(null);
     }
 }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        protected override async Task <BoolResult> StartupCoreAsync(OperationContext context)
        {
            Tracer.TraceStartupConfiguration(context, Configuration);

            RedisDatabaseFactoryForRedisGlobalStore = await RedisDatabaseFactory.CreateAsync(
                context,
                new LiteralConnectionStringProvider(Configuration.RedisGlobalStoreConnectionString));

            if (Configuration.RedisGlobalStoreSecondaryConnectionString != null)
            {
                RedisDatabaseFactoryForRedisGlobalStoreSecondary = await RedisDatabaseFactory.CreateAsync(
                    context,
                    new LiteralConnectionStringProvider(Configuration.RedisGlobalStoreSecondaryConnectionString));
            }

            return(BoolResult.Success);
        }
Exemplo n.º 14
0
        private RedisDatabaseAdapter CreateDatabase(RedisDatabaseFactory factory, string databaseName, bool optional = false)
        {
            if (factory != null)
            {
                var adapterConfiguration = new RedisDatabaseAdapterConfiguration(
                    KeySpace,
                    Configuration.RedisConnectionErrorLimit,
                    traceOperationFailures: Configuration.TraceRedisFailures,
                    traceTransientFailures: Configuration.TraceRedisTransientFailures,
                    databaseName: databaseName);

                return(new RedisDatabaseAdapter(factory, adapterConfiguration));
            }
            else
            {
                Contract.Assert(optional);
                return(null);
            }
        }
        protected override async Task <BoolResult> StartupCoreAsync(OperationContext context)
        {
            Tracer.TraceStartupConfiguration(context, Configuration);

            RedisDatabaseFactoryForRedisGlobalStore = await RedisDatabaseFactory.CreateAsync(
                context,
                new LiteralConnectionStringProvider(Configuration.RedisGlobalStoreConnectionString),
                logSeverity : Configuration.RedisInternalLogSeverity ?? Severity.Unknown,
                usePreventThreadTheft : Configuration.UsePreventThreadTheftFeature);

            if (Configuration.RedisGlobalStoreSecondaryConnectionString != null)
            {
                RedisDatabaseFactoryForRedisGlobalStoreSecondary = await RedisDatabaseFactory.CreateAsync(
                    context,
                    new LiteralConnectionStringProvider(Configuration.RedisGlobalStoreSecondaryConnectionString),
                    logSeverity : Configuration.RedisInternalLogSeverity ?? Severity.Unknown,
                    usePreventThreadTheft : Configuration.UsePreventThreadTheftFeature);
            }

            return(BoolResult.Success);
        }
Exemplo n.º 16
0
 public RedisDatabaseAdapter(RedisDatabaseFactory databaseFactory, string keySpace)
     : this(databaseFactory, new RedisDatabaseAdapterConfiguration(keySpace))
 {
 }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RedisDatabaseAdapter"/> class.
 /// </summary>
 public RedisDatabaseAdapter(RedisDatabaseFactory databaseFactory, string keySpace)
 {
     _databaseFactory    = databaseFactory;
     KeySpace            = keySpace;
     _redisRetryStrategy = new RetryPolicy(new RedisRetryPolicy(), RetryStrategy.DefaultExponential);
 }
Exemplo n.º 18
0
 public RedisDatabaseAdapter(RedisDatabaseFactory databaseFactory, string keySpace, IClock?clock = null)
     : this(databaseFactory, new RedisDatabaseAdapterConfiguration(keySpace), clock)
 {
 }
Exemplo n.º 19
0
 public RedisDatabaseAdapter(RedisDatabaseFactory databaseFactory, RedisDatabaseAdapterConfiguration configuration)
 {
     _configuration      = configuration;
     _redisRetryStrategy = configuration.CreateRetryPolicy(OnRedisException);
     _databaseFactory    = databaseFactory;
 }