Ejemplo n.º 1
0
        public void Create_Instance_Of_IDistributedCache_By_Constructing_RedisClient()
        {
            try
            {
                string server   = "localhost";
                string port     = "6379";
                string cnstring = $"{server}:{port}";

                var redisOptions = new RedisCacheOptions
                {
                    ConfigurationOptions = new ConfigurationOptions()
                };
                redisOptions.ConfigurationOptions.EndPoints.Add(cnstring);
                var opts = Options.Create <RedisCacheOptions>(redisOptions);

                IDistributedCache cache = new Microsoft.Extensions.Caching.StackExchangeRedis.RedisCache(opts);
                string            expectedStringData = "Hello world";
                cache.Set("key003", System.Text.Encoding.UTF8.GetBytes(expectedStringData));
                var dataFromCache          = cache.Get("key003");
                var actualCachedStringData = System.Text.Encoding.UTF8.GetString(dataFromCache);
                Assert.AreEqual(expectedStringData, actualCachedStringData);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
                throw;
            }
        }
Ejemplo n.º 2
0
        private static void Main()
        {
            Console.WriteLine("Hello World!");

            RedisCacheOptions redisOptions = new RedisCacheOptions();

            redisOptions.ConfigurationOptions.

            Microsoft.Extensions.Caching.StackExchangeRedis.RedisCache redis = new Microsoft.Extensions.Caching.StackExchangeRedis.RedisCache()
        }
Ejemplo n.º 3
0
        public override void Initialize(string store)
        {
            lock (_lock)
            {
                if (IsInitialized)
                {
                    Logger.Technical().From <RedisCache>().Debug($"Redis Cache {store} is already initialized.").Log();
                    return;
                }
                Name = store;

                if (Container.TryResolve <IKeyValueSettings>(store, out var settings))
                {
                    if (settings.Values.ContainsKey(ConnectionStringKey))
                    {
                        ConnectionString = settings.Values[ConnectionStringKey];
                    }

                    if (settings.Values.ContainsKey(DatabaseNameKey))
                    {
                        DatabaseName = settings.Values[DatabaseNameKey];
                    }

                    if (settings.Values.ContainsKey(SerializerNameKey))
                    {
                        SerializerName = settings.Values[SerializerNameKey];
                    }
                    else
                    {
                        SerializerName = store;
                    }

                    var option = new RedisCacheOptions
                    {
                        InstanceName  = DatabaseName,
                        Configuration = ConnectionString
                    };

                    DistributeCache = new StackExchangeRedis(option);

                    if (!Container.TryResolve <IObjectSerialization>(SerializerName, out var serializerFactory))
                    {
                        SerializerFactory = Container.Resolve <IObjectSerialization>();
                    }
                    else
                    {
                        SerializerFactory = serializerFactory;
                    }

                    IsInitialized = true;
                    Logger.Technical().From <RedisCache>().System($"Redis Cache {store} is initialized.").Log();
                }
            }
        }
Ejemplo n.º 4
0
 public ToolStackRedisCache(RedisCacheOptions optionsAccessor)
 {
     _cache = new Microsoft.Extensions.Caching.StackExchangeRedis.RedisCache(optionsAccessor);
 }