|
|
|
@ -192,6 +192,141 @@ namespace RedisStudyTest
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region StringSetRange
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StringSetRangeNotKeyTest()
|
|
|
|
|
{
|
|
|
|
|
var alterRangeLenth = redisStringStudy.StringSetRange(defaultRedisKey, 0, "first");
|
|
|
|
|
Assert.Equal("first".Length, alterRangeLenth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StringSetRangeTest()
|
|
|
|
|
{
|
|
|
|
|
var alterRangeLenth = redisStringStudy.StringSetRange(defaultRedisKey, 0, "first");
|
|
|
|
|
Assert.Equal("first".Length, alterRangeLenth);
|
|
|
|
|
|
|
|
|
|
alterRangeLenth = redisStringStudy.StringSetRange(defaultRedisKey, 1, "second");
|
|
|
|
|
Assert.Equal("fsecond".Length, alterRangeLenth);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region StringAppend
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StringAppendStringTest()
|
|
|
|
|
{
|
|
|
|
|
//不存在时,添加并设置初始值
|
|
|
|
|
var redisValueLenth = redisStringStudy.StringAppend(defaultRedisKey, "source");
|
|
|
|
|
Assert.Equal("source".Length, redisValueLenth);
|
|
|
|
|
|
|
|
|
|
//存在时,追加
|
|
|
|
|
redisValueLenth = redisStringStudy.StringAppend(defaultRedisKey, " append");
|
|
|
|
|
Assert.Equal("source append".Length, redisValueLenth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StringAppendNumberTest()
|
|
|
|
|
{
|
|
|
|
|
//不存在时,添加并设置初始值
|
|
|
|
|
var redisValueLenth = redisStringStudy.StringAppend(defaultRedisKey, 123);
|
|
|
|
|
Assert.Equal(3, redisValueLenth);
|
|
|
|
|
|
|
|
|
|
//存在时,追加
|
|
|
|
|
redisValueLenth = redisStringStudy.StringAppend(defaultRedisKey, 456);
|
|
|
|
|
Assert.Equal(6, redisValueLenth);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region StringIncrement
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StringIncrementIntegerTest()
|
|
|
|
|
{
|
|
|
|
|
//key不存在,则添加后自增
|
|
|
|
|
var result = redisStringStudy.StringIncrement(defaultRedisKey,1);
|
|
|
|
|
Assert.Equal(1, result);
|
|
|
|
|
|
|
|
|
|
//key存在,自增
|
|
|
|
|
result = redisStringStudy.StringIncrement(defaultRedisKey, 2);
|
|
|
|
|
Assert.Equal(3, result);
|
|
|
|
|
|
|
|
|
|
//自增负数,等于自减
|
|
|
|
|
result = redisStringStudy.StringIncrement(defaultRedisKey, -1);
|
|
|
|
|
Assert.Equal(2, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StringIncrementDoubleTest()
|
|
|
|
|
{
|
|
|
|
|
//key不存在,则添加后自增
|
|
|
|
|
var result = redisStringStudy.StringIncrement(defaultRedisKey, 1.5);
|
|
|
|
|
Assert.Equal(1.5, result);
|
|
|
|
|
|
|
|
|
|
//key存在,自增
|
|
|
|
|
result = redisStringStudy.StringIncrement(defaultRedisKey, 2.1);
|
|
|
|
|
var absResult = Math.Abs(3.6-result);
|
|
|
|
|
Assert.True(absResult < 0.1);
|
|
|
|
|
|
|
|
|
|
//自增负数,等于自减
|
|
|
|
|
result = redisStringStudy.StringIncrement(defaultRedisKey, -1.1);
|
|
|
|
|
absResult = Math.Abs(2.5 - result);
|
|
|
|
|
Assert.True(absResult < 0.1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region StringDecrement
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StringDecrementIntegerTest()
|
|
|
|
|
{
|
|
|
|
|
//key不存在,则添加后自减
|
|
|
|
|
var result = redisStringStudy.StringDecrement(defaultRedisKey, 1);
|
|
|
|
|
Assert.Equal(-1, result);
|
|
|
|
|
|
|
|
|
|
//key存在,自减
|
|
|
|
|
result = redisStringStudy.StringDecrement(defaultRedisKey, 2);
|
|
|
|
|
Assert.Equal(-3, result);
|
|
|
|
|
|
|
|
|
|
//自减负数,等于自增
|
|
|
|
|
result = redisStringStudy.StringDecrement(defaultRedisKey, -1);
|
|
|
|
|
Assert.Equal(-2, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StringDecrementDoubleTest()
|
|
|
|
|
{
|
|
|
|
|
//key不存在,则添加后自减
|
|
|
|
|
var result = redisStringStudy.StringDecrement(defaultRedisKey, 1.5);
|
|
|
|
|
Assert.Equal(-1.5, result);
|
|
|
|
|
|
|
|
|
|
//key存在,自减
|
|
|
|
|
result = redisStringStudy.StringDecrement(defaultRedisKey, 2.1);
|
|
|
|
|
var absResult = Math.Abs(-3.6 - result);
|
|
|
|
|
Assert.True(absResult < 0.1);
|
|
|
|
|
|
|
|
|
|
//自减负数,等于自增
|
|
|
|
|
result = redisStringStudy.StringDecrement(defaultRedisKey, -1.1);
|
|
|
|
|
absResult = Math.Abs(-2.5 - result);
|
|
|
|
|
Assert.True(absResult < 0.1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region StringGet
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void StringGetNotKeyTest()
|
|
|
|
|
{
|
|
|
|
|
var result = redisStringStudy.StringGet("xxxxxxxxx");
|
|
|
|
|
|
|
|
|
|
Assert.False(result.HasValue);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 清理
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|