Пример #1
0
        /// <summary>
        /// 注入Redis默认实例
        /// </summary>
        /// <param name="services">服务容器</param>
        /// <param name="configuration">配置</param>
        /// <param name="useHybridMode">是否启用混合模式</param>
        /// <returns></returns>
        public static void AddRedis(this IServiceCollection services,
                                    IConfiguration configuration, bool useHybridMode = false)
        {
            services.Configure <RedisCacheOptions>(options =>
            {
                RedisBootstrap.SetRedisCacheOptions(configuration, options);
            });

            if (useHybridMode)
            {
                services.AddSingleton <IRedisCacheManager, DefaultRedisCacheManager>();
            }
            else
            {
                services.AddSingleton <ICacheManager, DefaultRedisCacheManager>();
            }

            Console.WriteLine("Redis注入完成。");
        }
Пример #2
0
        /// <summary>
        /// 启用Redis
        /// </summary>
        /// <param name="configuration">配置</param>
        /// <param name="useHybridMode">是否启用混合模式</param>
        public static void UseRedis(IServiceCollection services,
                                    IConfiguration configuration, bool useHybridMode = false)
        {
            services.Configure <RedisCacheOptions>(options =>
            {
                RedisBootstrap.SetRedisCacheOptions(configuration, options);
            });

            // Hack StackExchange.Redis 1.2.6下使用单例模式会有连接线程池上限的BUG导致请求timeout
            // TODO 暂时使用Transient模式解决以上问题
            if (useHybridMode)
            {
                services.AddTransient <IRedisCacheManager, DefaultRedisCacheManager>();
            }
            else
            {
                services.AddTransient <ICacheManager, DefaultRedisCacheManager>();
            }

            Console.WriteLine("Redis 注入完成。");
        }
 /// <summary>
 /// 注入Redis默认实例
 /// </summary>
 /// <param name="services">服务容器</param>
 /// <param name="configuration">配置</param>
 /// <param name="useHybridMode">是否启用混合模式</param>
 /// <returns></returns>
 public static void AddRedis(this IServiceCollection services,
                             IConfiguration configuration, bool useHybridMode = false)
 {
     RedisBootstrap.UseRedis(services, configuration, useHybridMode);
 }