/// <summary>
 /// Shutdown and forget a connection multiplexer.
 /// </summary>
 public static async Task ForgetAsync(Context context, ConfigurationOptions options)
 {
     RedisEndpoint endPoints = options.GetRedisEndpoint();
     context.Debug($"Removing {nameof(RedisConnectionMultiplexer)} for endpoint: {endPoints}");
     if (Multiplexers.TryRemove(endPoints, out var multiplexerTask))
     {
         context.Debug($"Closing connection multiplexer. Endpoint: {options.GetRedisEndpoint()}");
         IConnectionMultiplexer multiplexer = await multiplexerTask.Value;
         await multiplexer.CloseAsync(allowCommandsToComplete: true);
         multiplexer.Dispose();
     }
     else
     {
         context.Warning($"Can't find {nameof(RedisConnectionMultiplexer)} for endpoint: {endPoints}");
     }
 }
Пример #2
0
        private static async Task <IConnectionMultiplexer> GetConnectionMultiplexerAsync(Context context, ConfigurationOptions options, Severity logSeverity)
        {
            var operationContext = new OperationContext(context);
            var endpoint         = options.GetRedisEndpoint();

            return(await operationContext.PerformNonResultOperationAsync(
                       Tracer,
                       async() =>
            {
                context.Debug($"{nameof(RedisConnectionMultiplexer)}: Connecting to redis endpoint: {endpoint}");
                if (logSeverity != Severity.Unknown)
                {
                    var replacementContext = context.CreateNested(componentName: nameof(RedisConnectionMultiplexer));
                    var logger = new TextWriterAdapter(replacementContext, logSeverity, component: "Redis.StackExchange");
                    return await ConnectionMultiplexer.ConnectAsync(options, logger);
                }

                return await ConnectionMultiplexer.ConnectAsync(options);
            },
                       extraEndMessage : r => $"Endpoint: {endpoint}",
                       traceOperationStarted : false));
        }
Пример #3
0
        private static async Task <IConnectionMultiplexer> GetConnectionMultiplexerAsync(Context context, ConfigurationOptions options, Severity logSeverity, bool usePreventThreadTheft)
        {
            var operationContext = new OperationContext(context);
            var endpoint         = options.GetRedisEndpoint();

            if (usePreventThreadTheft)
            {
                // See "Thread Theft" article for more details: https://stackexchange.github.io/StackExchange.Redis/ThreadTheft
                // TLDR; when the feature is on all the continuations used inside the library are executed asynchronously.
                ConnectionMultiplexer.SetFeatureFlag("preventthreadtheft", true);
            }

            return(await operationContext.PerformNonResultOperationAsync(
                       Tracer,
                       async() =>
            {
                context.Debug($"{nameof(RedisConnectionMultiplexer)}: Connecting to redis endpoint: {endpoint}");
                var result = await CreateMultiplexerCoreAsync(context, options, logSeverity);

                return result;
            },
                       extraEndMessage : r => $"Endpoint: {endpoint}",
                       traceOperationStarted : false));
        }