public void redis_set_and_get_test() { var key = string.Format(keyTemplate, 1); redisWrapper.Set(key, "123"); var value = redisWrapper.Get(key); value.Should().NotBeNull(); value.ToString().Should().Be("123"); }
public override void Set(CacheKey key, object value, CachePolicy cachePolicy) { var dataStr = serializer.Serialize <string>(value); var expiry = ComputeExpiryTimeSpan(cachePolicy); redisWrapper.Set(key.Key, dataStr, expiry); ManageCacheDependencies(key); }
public void Set(CacheKey key, object value, CachePolicy cachePolicy) { var jsonString = serializer.SerializeToString(value); var expiry = ComputeExpiryTimeSpan(cachePolicy); redisWrapper.Set(key.Key, jsonString, expiry); ManageCacheDependencies(key); }
public void multiple_clients_to_safely_execute() { //The number of concurrent clients to run const int noOfClients = 10; var asyncResults = new List <IAsyncResult>(noOfClients); for (var i = 1; i <= noOfClients; i++) { var clientNo = i; var actionFn = (Action) delegate { using (LockFactory.GetLock("testlock")) { testOutput.WriteLine("client {0} acquired lock", clientNo); var value = redisWrapper.Get("atomic-counter"); int counter = 0; if (value != null) { counter = value.ToString().ToInt(0); } //Add an artificial delay to demonstrate locking behaviour Thread.Sleep(RandomHelper.GetRandom(100, 200)); redisWrapper.Set("atomic-counter", (counter + 1).ToString()); testOutput.WriteLine("client {0} released lock", clientNo); } }; //Asynchronously invoke the above delegate in a background thread asyncResults.Add(actionFn.BeginInvoke(null, null)); } //Wait at most 1 minute for all the threads to complete asyncResults.WaitAll(TimeSpan.FromMinutes(1)); //Print out the 'atomic-counter' result var result = redisWrapper.Get("atomic-counter").ToString().ToInt(); testOutput.WriteLine("atomic-counter after 1min: {0}", result); }