RedisListStudyTest

master
ruyu 7 years ago
parent 94144bafe0
commit fc7c0f385f

@ -78,13 +78,96 @@ namespace RedisStudyTest
} }
#endregion #endregion
#region #region ListInsertBefore
/// <summary>
/// Key不存在时不执行操作返回0
/// </summary>
[Fact] [Fact]
public void Test() public void ListInsertBeforeNotKeyTest()
{ {
var listLenth = redisListStudy.ListInsertBefore(defaultRedisKey, "first", "firstBefore"); var listLenth = redisListStudy.ListInsertBefore(defaultRedisKey, "first", "firstBefore");
Assert.Equal(0, listLenth); 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 #endregion
#region 清理 #region 清理

@ -97,7 +97,7 @@ namespace RedisStuy
/// </summary> /// </summary>
/// <returns> /// <returns>
/// 插入后,列表长度 /// 插入后,列表长度
/// 未找到指定key值时,返回 -1 /// 未找到指定参照值时,返回 -1
/// </returns> /// </returns>
public long ListInsertBefore(RedisKey key, RedisValue pivot, RedisValue value, CommandFlags flags = CommandFlags.None) public long ListInsertBefore(RedisKey key, RedisValue pivot, RedisValue value, CommandFlags flags = CommandFlags.None)
{ {

Loading…
Cancel
Save