Created
March 8, 2017 00:45
-
-
Save alexandrebl/b9a03ae9c73df9821bec2d22fbdaa3d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Newtonsoft.Json; | |
| using StackExchange.Redis; | |
| using StackExchange.Redis.Extensions.Core; | |
| using StackExchange.Redis.Extensions.Newtonsoft; | |
| namespace Library { | |
| /// <summary> | |
| /// Gerenciador de cache | |
| /// </summary> | |
| /// <typeparam name="T">tipo</typeparam> | |
| public class CacheManagerUtility<T> : ICacheManagerUtility<T> { | |
| /// <summary> | |
| /// Servidor Redis | |
| /// </summary> | |
| private string _host; | |
| /// <summary> | |
| /// Chanal | |
| /// </summary> | |
| private string _channel; | |
| /// <summary> | |
| /// Método construtor | |
| /// </summary> | |
| /// <param name="configurationUtility">utilitário de configuração</param> | |
| public CacheManagerUtility(IConfigurationUtility configurationUtility) { | |
| //Servidor | |
| _host = configurationUtility.RedisCacheServerIP; | |
| //Canal | |
| _channel = configurationUtility.RedisInputChannel; | |
| } | |
| /// <summary> | |
| /// Publicação | |
| /// </summary> | |
| /// <param name="obj">objeto</param> | |
| void ICacheManagerUtility<T>.Publish(T obj) { | |
| //Inicializa o canal | |
| var redisChannel = new RedisChannel(_channel, RedisChannel.PatternMode.Auto); | |
| //Cria o cliente | |
| using (var stackExchangeRedisCacheClient = new StackExchangeRedisCacheClient( | |
| ConnectionMultiplexer.Connect($"{_host}:6379"), | |
| new NewtonsoftSerializer(new JsonSerializerSettings()))) { | |
| //Publica os dados | |
| stackExchangeRedisCacheClient.Publish(redisChannel, obj); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment