|
|
|
@ -327,6 +327,51 @@ namespace RedisStudyTest
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region StringGetRange
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StringGetRangeTest()
|
|
|
|
|
{
|
|
|
|
|
redisStringStudy.StringSet(defaultRedisKey, "wanggaofeng", TimeSpan.FromSeconds(10));
|
|
|
|
|
|
|
|
|
|
var getRange = redisStringStudy.StringGetRange(defaultRedisKey, 2, -1);
|
|
|
|
|
Assert.Equal("nggaofeng", getRange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region StringGetSet
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StringGetSetTest()
|
|
|
|
|
{
|
|
|
|
|
//key不存在时,返回null
|
|
|
|
|
var oldValue = redisStringStudy.StringGetSet(defaultRedisKey, "wanggaofeng");
|
|
|
|
|
Assert.False(oldValue.HasValue);
|
|
|
|
|
|
|
|
|
|
//存在,返回旧值
|
|
|
|
|
oldValue = redisStringStudy.StringGetSet(defaultRedisKey, "王高峰");
|
|
|
|
|
Assert.Equal("wanggaofeng", oldValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region StringGetWithExpiry
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StringGetWithExpiryTest()
|
|
|
|
|
{
|
|
|
|
|
redisStringStudy.StringSet(defaultRedisKey, "wanggaofeng", TimeSpan.FromSeconds(20));
|
|
|
|
|
|
|
|
|
|
var redisValueWithExpiry =redisStringStudy.StringGetWithExpiry(defaultRedisKey);
|
|
|
|
|
|
|
|
|
|
Assert.Equal("wanggaofeng",redisValueWithExpiry.Value);
|
|
|
|
|
Assert.True(redisValueWithExpiry.Expiry.HasValue);
|
|
|
|
|
Assert.True(redisValueWithExpiry.Expiry.Value.Seconds <= 20 && redisValueWithExpiry.Expiry.Value.Seconds>=15);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 清理
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|