当前位置: 首页>>代码示例>>C#>>正文


C# RedisClient.IncrementValue方法代码示例

本文整理汇总了C#中RedisClient.IncrementValue方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.IncrementValue方法的具体用法?C# RedisClient.IncrementValue怎么用?C# RedisClient.IncrementValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RedisClient的用法示例。


在下文中一共展示了RedisClient.IncrementValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Acquiring_lock_with_timeout

		public void Acquiring_lock_with_timeout()
		{
			var redisClient = new RedisClient(TestConfig.SingleHost);

			//Initialize and set counter to '1'
			redisClient.IncrementValue("atomic-counter"); 
			
			//Acquire lock and never release it
			redisClient.AcquireLock("testlock");

			var waitFor = TimeSpan.FromSeconds(2);
			var now = DateTime.Now;

			try
			{
				using (var newClient = new RedisClient(TestConfig.SingleHost))
				{
					//Attempt to acquire a lock with a 2 second timeout
					using (newClient.AcquireLock("testlock", waitFor))
					{
						//If lock was acquired this would be incremented to '2'
						redisClient.IncrementValue("atomic-counter"); 
					}
				}
			}
			catch (TimeoutException tex)
			{
				var timeTaken = DateTime.Now - now;
				Debug.WriteLine(String.Format("After '{0}', Received TimeoutException: '{1}'", timeTaken, tex.Message));

				var counter = redisClient.Get<int>("atomic-counter");
				Debug.WriteLine(String.Format("atomic-counter remains at '{0}'", counter));
			}
		}
开发者ID:modulexcite,项目名称:ServiceStack.Redis,代码行数:34,代码来源:SimpleLocks.cs

示例2: Does_retry_failed_commands_auth

        public void Does_retry_failed_commands_auth()
        {
            // -> Redis must have "requirepass testpassword" in config
            var connstr = "[email protected]";
            RedisStats.Reset();

            var redisCtrl = new RedisClient(connstr); //RedisConfig.DefaultHost
            redisCtrl.FlushAll();
            redisCtrl.SetClient("redisCtrl");

            var redis = new RedisClient(connstr);
            redis.SetClient("redisRetry");

            var clientInfo = redisCtrl.GetClientsInfo();
            var redisId = clientInfo.First(m => m["name"] == "redisRetry")["id"];
            Assert.That(redisId.Length, Is.GreaterThan(0));

            Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(1));

            redis.OnBeforeFlush = () =>
            {
                redisCtrl.KillClients(withId: redisId);
            };

            Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(2));
            Assert.That(redis.Get<int>("retryCounter"), Is.EqualTo(2));

            Assert.That(RedisStats.TotalRetryCount, Is.EqualTo(1));
            Assert.That(RedisStats.TotalRetrySuccess, Is.EqualTo(1));
            Assert.That(RedisStats.TotalRetryTimedout, Is.EqualTo(0));
        }
开发者ID:ServiceStack,项目名称:ServiceStack.Redis,代码行数:31,代码来源:AuthIssue.cs

示例3: Does_retry_failed_commands

        public void Does_retry_failed_commands()
        {
            //LogManager.LogFactory = new ConsoleLogFactory(debugEnabled: true);

            RedisStats.Reset();

            var redisCtrl = new RedisClient(RedisConfig.DefaultHost);
            redisCtrl.FlushAll();
            redisCtrl.SetClient("redisCtrl");

            var redis = new RedisClient(RedisConfig.DefaultHost);
            redis.SetClient("redisRetry");

            var clientInfo = redisCtrl.GetClientsInfo();
            var redisId = clientInfo.First(m => m["name"] == "redisRetry")["id"];
            Assert.That(redisId.Length, Is.GreaterThan(0));

            Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(1));

            redis.OnBeforeFlush = () =>
            {
                redisCtrl.KillClients(withId: redisId);
            };

            Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(2));
            Assert.That(redis.Get<int>("retryCounter"), Is.EqualTo(2));

            Assert.That(RedisStats.TotalRetryCount, Is.EqualTo(1));
            Assert.That(RedisStats.TotalRetrySuccess, Is.EqualTo(1));
            Assert.That(RedisStats.TotalRetryTimedout, Is.EqualTo(0));
        }
开发者ID:CatomStudio,项目名称:ServiceStack.Redis,代码行数:31,代码来源:RetryCommandTests.cs

示例4: Does_Timeout_with_repeated_SocketException

        public void Does_Timeout_with_repeated_SocketException()
        {
            RedisConfig.Reset();
            RedisConfig.DefaultRetryTimeout = 100;

            var redis = new RedisClient(RedisConfig.DefaultHost);
            redis.FlushAll();

            Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(1));

            redis.OnBeforeFlush = () =>
            {
                throw new SocketException();
            };

            try
            {
                redis.IncrementValue("retryCounter");
                Assert.Fail("Should throw");
            }
            catch (RedisException ex)
            {
                Assert.That(ex.Message, Is.StringStarting("Exceeded timeout"));

                redis.OnBeforeFlush = null;
                Assert.That(redis.Get<int>("retryCounter"), Is.EqualTo(1));

                Assert.That(RedisStats.TotalRetryCount, Is.GreaterThan(1));
                Assert.That(RedisStats.TotalRetrySuccess, Is.EqualTo(0));
                Assert.That(RedisStats.TotalRetryTimedout, Is.EqualTo(1));
            }

            RedisConfig.Reset();
        }
开发者ID:CatomStudio,项目名称:ServiceStack.Redis,代码行数:34,代码来源:RetryCommandTests.cs

示例5: Does_retry_failed_commands_with_SocketException

        public void Does_retry_failed_commands_with_SocketException()
        {
            RedisStats.Reset();

            var redis = new RedisClient(RedisConfig.DefaultHost);
            redis.FlushAll();

            Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(1));

            redis.OnBeforeFlush = () =>
            {
                redis.OnBeforeFlush = null;
                throw new SocketException();
            };

            Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(2));
            Assert.That(redis.Get<int>("retryCounter"), Is.EqualTo(2));

            Assert.That(RedisStats.TotalRetryCount, Is.EqualTo(1));
            Assert.That(RedisStats.TotalRetrySuccess, Is.EqualTo(1));
            Assert.That(RedisStats.TotalRetryTimedout, Is.EqualTo(0));
        }
开发者ID:CatomStudio,项目名称:ServiceStack.Redis,代码行数:22,代码来源:RetryCommandTests.cs


注:本文中的RedisClient.IncrementValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。