public ActionResult TestRedisCache() { redisCacheProvider.Add <string>("vcredit:rc:dotnet.key1", "hello world"); redisCacheProvider.Add <string>("vcredit:rc:dotnet.date.now", DateTime.Now.ToLongDateString()); Dictionary <string, object> cacheContext = new Dictionary <string, object>(); string[] keys = new string[] { "vcredit:rc:dotnet.key1", "vcredit:rc:dotnet.date.now" }; foreach (string key in keys) { cacheContext.Add(key, redisCacheProvider.Select <string>(key)); } return(new JsonResult(cacheContext)); }
public void ContainKey_ReturnTrueAfterAddItem() { var redisCacheProvider = new RedisCacheProvider(connection.GetDatabase(), connection.GetServer("127.0.0.1:6379")); redisCacheProvider.Add(Key, Value); var containKeyInCache = redisCacheProvider.Contains(Key); Assert.True(containKeyInCache); }
public void AddValueToCache_NoExpiration() { var redisCacheProvider = new RedisCacheProvider(connection.GetDatabase(), connection.GetServer("127.0.0.1:6379")); redisCacheProvider.Add(Key, Value); var valueFromCache = redisCacheProvider.Get <string>(Key); Assert.Equal(Value, valueFromCache); }
public void RemoveCache_ObjectIsRemoved() { var redisCacheProvider = new RedisCacheProvider(connection.GetDatabase(), connection.GetServer("127.0.0.1:6379")); redisCacheProvider.Add(Key, Value); redisCacheProvider.Remove(Key); var containCacheKey = redisCacheProvider.Contains(Key); Assert.False(containCacheKey); }
static void Main(string[] args) { var connection = ConnectionMultiplexer.Connect("127.0.0.1:6379,abortConnect=false"); var cache = new RedisCacheProvider(connection.GetDatabase()); var key = "order_1"; var order = new Models.Order { OrderId = 1, TotalPrice = 100, Products = new List <Product> { new Product { Id = 1, Name = "Test Product", Price = 100 } } }; cache.Add <Models.Order>(key, order); var cachedOrder = cache.Get <Models.Order>(key); }