|
|
|
@ -231,6 +231,34 @@ namespace RedisStudyTest
|
|
|
|
|
redisDatabase.KeyDelete(preHashKey + student.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void HashDecrement()
|
|
|
|
|
{
|
|
|
|
|
string redisKey = preHashKey + student.Id;
|
|
|
|
|
|
|
|
|
|
//Key不存在,则新创建之
|
|
|
|
|
Assert.Equal(-1, hashStudy.HashDecrement(redisKey, "Id", 1));
|
|
|
|
|
Assert.Equal(-1, hashStudy.HashGet(redisKey, "Id"));
|
|
|
|
|
|
|
|
|
|
//字段不存在,则创建之
|
|
|
|
|
Assert.Equal(-1, hashStudy.HashDecrement(redisKey, "Age", 1));
|
|
|
|
|
Assert.Equal(-1, hashStudy.HashGet(redisKey, "Age"));
|
|
|
|
|
|
|
|
|
|
//字段不为数据字,则改为数字
|
|
|
|
|
//注意:是否原注释错误?,因为实际执行抛出异常,而不是操作前改为0
|
|
|
|
|
Assert.True(hashStudy.HashSet(redisKey, "Name","wanggaofeng"));
|
|
|
|
|
Assert.Throws<RedisServerException>(()=>hashStudy.HashDecrement(redisKey, "Name", 1));
|
|
|
|
|
//Assert.Equal(-1, hashStudy.HashGet(redisKey, "Name"));
|
|
|
|
|
|
|
|
|
|
//字段减少1
|
|
|
|
|
Assert.Equal(-2, hashStudy.HashDecrement(redisKey, "Age", 1));
|
|
|
|
|
//字段减少
|
|
|
|
|
Assert.Equal(-4, hashStudy.HashDecrement(redisKey, "Age", 2));
|
|
|
|
|
|
|
|
|
|
//增加负数时,啥情况
|
|
|
|
|
Assert.Equal(-2, hashStudy.HashDecrement(redisKey, "Age", -2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取
|
|
|
|
|