|
|
|
@ -67,8 +67,13 @@ namespace RedisStudyTest
|
|
|
|
|
"secnd",
|
|
|
|
|
"third"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var listLenth = redisListStudy.ListLeftPush(defaultRedisKey, listValues);
|
|
|
|
|
Assert.Equal(3, listLenth);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(listValues[2], redisListStudy.ListGetByIndex(defaultRedisKey, 0));
|
|
|
|
|
Assert.Equal(listValues[1], redisListStudy.ListGetByIndex(defaultRedisKey, 1));
|
|
|
|
|
Assert.Equal(listValues[0], redisListStudy.ListGetByIndex(defaultRedisKey, 2));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
@ -178,7 +183,7 @@ namespace RedisStudyTest
|
|
|
|
|
|
|
|
|
|
#region ListSetByIndex
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListGetByIndexNotKeyTest()
|
|
|
|
|
public void ListSetByIndexNotKeyTest()
|
|
|
|
|
{
|
|
|
|
|
Assert.Throws<RedisServerException>(() => redisListStudy.ListSetByIndex(defaultRedisKey, 0, "first"));
|
|
|
|
|
}
|
|
|
|
@ -196,6 +201,31 @@ namespace RedisStudyTest
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ListGetByIndex
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListGetByIndexNotKeyTest()
|
|
|
|
|
{
|
|
|
|
|
var result = redisListStudy.ListGetByIndex(defaultRedisKey, 0);
|
|
|
|
|
Assert.False(result.HasValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Test()
|
|
|
|
|
{
|
|
|
|
|
redisListStudy.ListLeftPush(defaultRedisKey, new RedisValue[] { "first", "second", "third" });
|
|
|
|
|
|
|
|
|
|
var result = redisListStudy.ListGetByIndex(defaultRedisKey, 0);
|
|
|
|
|
Assert.Equal("third", result);
|
|
|
|
|
|
|
|
|
|
result = redisListStudy.ListGetByIndex(defaultRedisKey, 1);
|
|
|
|
|
Assert.Equal("second", result);
|
|
|
|
|
|
|
|
|
|
result = redisListStudy.ListGetByIndex(defaultRedisKey, 2);
|
|
|
|
|
Assert.Equal("first", result);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ListLength
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListLengthNotKeyTest()
|
|
|
|
@ -304,6 +334,65 @@ namespace RedisStudyTest
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ListRightPopLeftPush
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListRightPopLeftPushNotKeyTest()
|
|
|
|
|
{
|
|
|
|
|
//操作
|
|
|
|
|
var firsValue = redisListStudy.ListRightPopLeftPush(defaultRedisKey, "RedisStudy:List:xUnitTest2");
|
|
|
|
|
|
|
|
|
|
//断言
|
|
|
|
|
Assert.False(firsValue.HasValue);
|
|
|
|
|
Assert.False(redisDatabase.KeyExists("RedisStudy:List:xUnitTest2"));
|
|
|
|
|
|
|
|
|
|
//清理
|
|
|
|
|
redisDatabase.KeyDelete("RedisStudy:List:xUnitTest");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 目标list不存在
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListRightPopLeftPushNotDestinationTest()
|
|
|
|
|
{
|
|
|
|
|
//准备
|
|
|
|
|
redisListStudy.ListLeftPush(defaultRedisKey, new RedisValue[] { "first", "second" });
|
|
|
|
|
|
|
|
|
|
//操作
|
|
|
|
|
var firsValue = redisListStudy.ListRightPopLeftPush(defaultRedisKey, "RedisStudy:List:xUnitTest2");
|
|
|
|
|
|
|
|
|
|
//断言
|
|
|
|
|
Assert.Equal(1, redisListStudy.ListLength(defaultRedisKey));
|
|
|
|
|
Assert.Equal("first",firsValue);
|
|
|
|
|
Assert.True(redisDatabase.KeyExists("RedisStudy:List:xUnitTest2"));
|
|
|
|
|
|
|
|
|
|
//清理
|
|
|
|
|
redisDatabase.KeyDelete("RedisStudy:List:xUnitTest");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListRightPopLeftPushTest()
|
|
|
|
|
{
|
|
|
|
|
//准备
|
|
|
|
|
string secondListKey = "RedisStudy:List:xUnitTest2";
|
|
|
|
|
redisListStudy.ListLeftPush(defaultRedisKey, new RedisValue[] { "first", "second" });
|
|
|
|
|
|
|
|
|
|
redisListStudy.ListLeftPush(secondListKey, new RedisValue[] {});
|
|
|
|
|
|
|
|
|
|
//操作
|
|
|
|
|
var resultValue = redisListStudy.ListRightPopLeftPush(defaultRedisKey, secondListKey);
|
|
|
|
|
|
|
|
|
|
//断言
|
|
|
|
|
Assert.Equal("first", resultValue);
|
|
|
|
|
Assert.Equal(1, redisListStudy.ListLength(defaultRedisKey));
|
|
|
|
|
Assert.True(redisDatabase.KeyExists(secondListKey));
|
|
|
|
|
|
|
|
|
|
//清理
|
|
|
|
|
redisDatabase.KeyDelete(secondListKey);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 清理
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|