本文整理汇总了C#中RedisClient.Ttl方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.Ttl方法的具体用法?C# RedisClient.Ttl怎么用?C# RedisClient.Ttl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedisClient
的用法示例。
在下文中一共展示了RedisClient.Ttl方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
});
}
示例2: TestTtl
public void TestTtl()
{
using (var mock = new FakeRedisSocket(":123\r\n"))
using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
{
Assert.AreEqual(123, redis.Ttl("test"));
Assert.AreEqual("*2\r\n$3\r\nTTL\r\n$4\r\ntest\r\n", mock.GetMessage());
}
}
示例3: TestExpireAt
public void TestExpireAt()
{
using(var mock = new MockConnector("localhost", 9999, ":1\r\n", ":0\r\n"))
using(var redis = new RedisClient(mock))
{
// 1402643208 = ISO 8601:2014-06-13T07:06:48Z
Assert.True(redis.ExpireAt("test1", new DateTime(2014, 6, 13, 7, 6, 48, DateTimeKind.Utc)));
Assert.Equal("*3\r\n$8\r\nEXPIREAT\r\n$5\r\ntest1\r\n$10\r\n1402643208\r\n", mock.GetMessage());
Assert.False(redis.ExpireAt("test2", 1402643208));
Assert.Equal("*3\r\n$8\r\nEXPIREAT\r\n$5\r\ntest2\r\n$10\r\n1402643208\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" } });
var now = DateTime.Now;
Assert.True(redis.ExpireAt("key1", now.AddSeconds(10)));
var ttl = redis.Ttl("key1");
Assert.True(ttl <= 10);
});
}
示例4: 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);
});
}
示例5: PExpireAt
public void PExpireAt()
{
using(var mock = new MockConnector("localhost", 9999, ":1\r\n", ":0\r\n"))
using(var redis = new RedisClient(mock))
{
// 1402643208123 = ISO 8601:2014-06-13T07:06:48Z +123ms
Assert.True(redis.ExpireAt("test1", new DateTime(2014, 6, 13, 7, 6, 48, 123, DateTimeKind.Utc), RedisExpireTimeUnit.PX));
Assert.Equal("*3\r\n$9\r\nPEXPIREAT\r\n$5\r\ntest1\r\n$13\r\n1402643208123\r\n", mock.GetMessage());
Assert.False(redis.ExpireAt("test2", 1402643208123, RedisExpireTimeUnit.PX));
Assert.Equal("*3\r\n$9\r\nPEXPIREAT\r\n$5\r\ntest2\r\n$13\r\n1402643208123\r\n", mock.GetMessage());
}
this.RealCall(redis =>
{
redis.MSet(new RedisDictionary { { "key1", "value1" } });
Assert.True(redis.ExpireAt("key1", DateTime.Now.AddSeconds(10), RedisExpireTimeUnit.PX));
Assert.True(redis.Ttl("key1") <= 10 * 1000);
});
}
示例6: 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);
});
}