|
|
|
@ -78,13 +78,96 @@ namespace RedisStudyTest
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
#region ListInsertBefore
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Key不存在时,不执行操作,返回0
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Test()
|
|
|
|
|
public void ListInsertBeforeNotKeyTest()
|
|
|
|
|
{
|
|
|
|
|
var listLenth = redisListStudy.ListInsertBefore(defaultRedisKey, "first", "firstBefore");
|
|
|
|
|
Assert.Equal(0, listLenth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 未找到指定参照值时,返回 -1
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListInsertBeforeNotPivotTest()
|
|
|
|
|
{
|
|
|
|
|
redisListStudy.ListLeftPush(defaultRedisKey, "second");
|
|
|
|
|
|
|
|
|
|
var listLenth = redisListStudy.ListInsertBefore(defaultRedisKey, "first", "firstBefore");
|
|
|
|
|
Assert.Equal(-1, listLenth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListInsertBeforeTest()
|
|
|
|
|
{
|
|
|
|
|
redisListStudy.ListLeftPush(defaultRedisKey, "third");
|
|
|
|
|
|
|
|
|
|
var listLenth = redisListStudy.ListInsertBefore(defaultRedisKey, "third", "second");
|
|
|
|
|
Assert.Equal(2, listLenth);
|
|
|
|
|
|
|
|
|
|
listLenth = redisListStudy.ListInsertBefore(defaultRedisKey, "second", "first");
|
|
|
|
|
Assert.Equal(3, listLenth);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ListInsertAfter
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Key不存在时,不执行操作,返回0
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListInsertAfterNotKeyTest()
|
|
|
|
|
{
|
|
|
|
|
var listLenth = redisListStudy.ListInsertAfter(defaultRedisKey, "first", "firstAfter");
|
|
|
|
|
Assert.Equal(0, listLenth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 未找到指定参照值时,返回 -1
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListInsertAfterNotPivotTest()
|
|
|
|
|
{
|
|
|
|
|
redisListStudy.ListLeftPush(defaultRedisKey, "second");
|
|
|
|
|
|
|
|
|
|
var listLenth = redisListStudy.ListInsertAfter(defaultRedisKey, "first", "firstAfter");
|
|
|
|
|
Assert.Equal(-1, listLenth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListInsertAfterTest()
|
|
|
|
|
{
|
|
|
|
|
redisListStudy.ListLeftPush(defaultRedisKey, "first");
|
|
|
|
|
|
|
|
|
|
var listLenth = redisListStudy.ListInsertAfter(defaultRedisKey, "first", "second");
|
|
|
|
|
Assert.Equal(2, listLenth);
|
|
|
|
|
|
|
|
|
|
listLenth = redisListStudy.ListInsertAfter(defaultRedisKey, "second", "third");
|
|
|
|
|
Assert.Equal(3, listLenth);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ListSetByIndex
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListGetByIndexNotKeyTest()
|
|
|
|
|
{
|
|
|
|
|
Assert.Throws<RedisServerException>(() => redisListStudy.ListSetByIndex(defaultRedisKey, 0, "first"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ListSetByIndexTest()
|
|
|
|
|
{
|
|
|
|
|
redisListStudy.ListLeftPush(defaultRedisKey, "first");
|
|
|
|
|
|
|
|
|
|
redisListStudy.ListSetByIndex(defaultRedisKey,0,"firstSetByIndex");
|
|
|
|
|
|
|
|
|
|
var first = redisListStudy.ListLeftPop(defaultRedisKey);
|
|
|
|
|
|
|
|
|
|
Assert.Equal("firstSetByIndex", first);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 清理
|
|
|
|
|