本文整理汇总了C#中RedisClient.Expire方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.Expire方法的具体用法?C# RedisClient.Expire怎么用?C# RedisClient.Expire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedisClient
的用法示例。
在下文中一共展示了RedisClient.Expire方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestExpire
public void TestExpire()
{
using (var mock = new FakeRedisSocket(":1\r\n", ":0\r\n"))
using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
{
Assert.IsTrue(redis.Expire("test1", TimeSpan.FromSeconds(10)));
Assert.AreEqual("*3\r\n$6\r\nEXPIRE\r\n$5\r\ntest1\r\n$2\r\n10\r\n", mock.GetMessage());
Assert.IsFalse(redis.Expire("test2", 20));
Assert.AreEqual("*3\r\n$6\r\nEXPIRE\r\n$5\r\ntest2\r\n$2\r\n20\r\n", mock.GetMessage());
}
}
示例2: TestExpire
public void TestExpire()
{
using(var mock = new MockConnector("localhost", 9999, ":1\r\n", ":0\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.True(redis.Expire("test1", TimeSpan.FromSeconds(10)));
Assert.Equal("*3\r\n$6\r\nEXPIRE\r\n$5\r\ntest1\r\n$2\r\n10\r\n", mock.GetMessage());
Assert.False(redis.Expire("test2", 20));
Assert.Equal("*3\r\n$6\r\nEXPIRE\r\n$5\r\ntest2\r\n$2\r\n20\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" }, { "key2", "value2" } });
Assert.True(redis.Expire("key1", TimeSpan.FromSeconds(10)));
Assert.True(redis.Expire("key2", 20));
Assert.True(redis.Ttl("key1") <= 10);
Assert.True(redis.Ttl("key2") <= 20);
});
}
示例3: TestTtl
public void TestTtl()
{
using(var mock = new MockConnector("localhost", 9999, ":123\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.Equal(123, redis.Ttl("test"));
Assert.Equal("*2\r\n$3\r\nTTL\r\n$4\r\ntest\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" }, { "key2", "value2" } });
Assert.True(redis.Expire("key1", TimeSpan.FromSeconds(10)));
Assert.True(redis.Expire("key2", 20));
Assert.True(redis.Ttl("key1", RedisExpireTimeUnit.PX) <= 10 * 1000);
Assert.True(redis.Ttl("key2", RedisExpireTimeUnit.PX) <= 20 * 1000);
});
}
示例4: PExpire
public void PExpire()
{
using(var mock = new MockConnector("localhost", 9999, ":1\r\n", ":0\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.True(redis.Expire("test1", TimeSpan.FromMilliseconds(5000), RedisExpireTimeUnit.PX));
Assert.Equal("*3\r\n$7\r\nPEXPIRE\r\n$5\r\ntest1\r\n$4\r\n5000\r\n", mock.GetMessage());
Assert.False(redis.Expire("test2", 6000, RedisExpireTimeUnit.PX));
Assert.Equal("*3\r\n$7\r\nPEXPIRE\r\n$5\r\ntest2\r\n$4\r\n6000\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" }, { "key2", "value2" } });
Assert.True(redis.Expire("key1", TimeSpan.FromSeconds(10), RedisExpireTimeUnit.PX));
Assert.True(redis.Expire("key2", 20 * 1000, RedisExpireTimeUnit.PX));
Assert.True(redis.Ttl("key1") <= 10 * 1000);
Assert.True(redis.Ttl("key2") <= 20 * 1000);
});
}