예제 #1
0
        public AtomicCounter(RedisOptions redisOptions, IWebHostEnvironment environment)
        {
            var options = new ConfigurationOptions
            {
                Password = redisOptions.Password,
                Ssl      = true,
            };

            var servers = redisOptions.Server.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList();

            servers.ForEach(i => options.EndPoints.Add(i));

            redisConnection = ConnectionMultiplexer.Connect(options);

            applicationName = redisOptions.ApplicationName;
            environmentName = environment.EnvironmentName;
        }
예제 #2
0
        public static IServiceCollection AddRedisCounter(this IServiceCollection services, Action <RedisOptions> configure = null)
        {
            var redisOptions = new RedisOptions();

            if (configure != null)
            {
                configure.Invoke(redisOptions);
            }

            var serviceProvider = services.BuildServiceProvider();

            serviceProvider.GetRequiredService <IConfiguration>().GetSection(RedisOptions.ConfigurationSection).Bind(redisOptions);

            services.AddSingleton(redisOptions);
            services.AddSingleton <IAtomicCounter, AtomicCounter>();

            return(services);
        }