-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathConnectionConfiguration.cs
33 lines (30 loc) · 1.28 KB
/
ConnectionConfiguration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Linq;
using Microsoft.Extensions.Configuration;
using StackExchange.Redis;
using ViennaNET.Redis.Configuration;
namespace ViennaNET.Redis
{
/// <inheritdoc />
public class ConnectionConfiguration : IConnectionConfiguration
{
private readonly IConfiguration _configuration;
/// <summary>
/// Инициализирует экземпляр ссылкой на <see cref="IConfiguration" />
/// </summary>
/// <param name="configuration">Ссылка на интерфейс, обеспечивающий доступ к конфигурации</param>
public ConnectionConfiguration(IConfiguration configuration)
{
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
}
/// <inheritdoc />
public ConnectionOptions GetConnectionConfigurationOptions()
{
var redisConfiguration = _configuration.GetSection("redis").Get<RedisConfiguration>();
return new ConnectionOptions(ConfigurationOptions.Parse(redisConfiguration.Connection), redisConfiguration.Key,
redisConfiguration.ExpirationMinValue, redisConfiguration.ExpirationMaxValue,
redisConfiguration.KeyLifetimes.ToDictionary(x => x.Name, x => x.Time),
redisConfiguration.ClearOnStartup);
}
}
}