Commit 80dd68f6 authored by Tomasz Żmuda's avatar Tomasz Żmuda Committed by Marc Gravell

Support count argument in SPOP (#918)

* Get multiple elements with SetPop

* Adjust names
parent 7ec50486
......@@ -563,12 +563,19 @@ public void SetMove()
}
[Fact]
public void SetPop()
public void SetPop_1()
{
wrapper.SetPop("key", CommandFlags.HighPriority);
mock.Verify(_ => _.SetPop("prefix:key", CommandFlags.HighPriority));
}
[Fact]
public void SetPop_2()
{
wrapper.SetPop("key", 5, CommandFlags.HighPriority);
mock.Verify(_ => _.SetPop("prefix:key", 5, CommandFlags.HighPriority));
}
[Fact]
public void SetRandomMember()
{
......
......@@ -535,12 +535,19 @@ public void SetMoveAsync()
}
[Fact]
public void SetPopAsync()
public void SetPopAsync_1()
{
wrapper.SetPopAsync("key", CommandFlags.HighPriority);
mock.Verify(_ => _.SetPopAsync("prefix:key", CommandFlags.HighPriority));
}
[Fact]
public void SetPopAsync_2()
{
wrapper.SetPopAsync("key", 5, CommandFlags.HighPriority);
mock.Verify(_ => _.SetPopAsync("prefix:key", 5, CommandFlags.HighPriority));
}
[Fact]
public void SetRandomMemberAsync()
{
......
......@@ -962,6 +962,16 @@ public interface IDatabase : IRedis, IDatabaseAsync
/// <remarks>https://redis.io/commands/spop</remarks>
RedisValue SetPop(RedisKey key, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Removes and returns an array of count random elements from the set value stored at key.
/// </summary>
/// <param name="key">The key of the set.</param>
/// <param name="count">The count of members to get.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>An array of elements, or an empty array when key does not exist.</returns>
/// <remarks>https://redis.io/commands/spop</remarks>
RedisValue[] SetPop(RedisKey key, long count, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Return a random element from the set value stored at key.
/// </summary>
......
......@@ -925,6 +925,16 @@ public interface IDatabaseAsync : IRedisAsync
/// <remarks>https://redis.io/commands/spop</remarks>
Task<RedisValue> SetPopAsync(RedisKey key, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Removes and returns an array of count random elements from the set value stored at key.
/// </summary>
/// <param name="key">The key of the set.</param>
/// <param name="count">The count of members to get.</param>
/// <param name="flags">The flags to use for this operation.</param>
/// <returns>An array of elements, or an empty array when key does not exist.</returns>
/// <remarks>https://redis.io/commands/spop</remarks>
Task<RedisValue[]> SetPopAsync(RedisKey key, long count, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Return a random element from the set value stored at key.
/// </summary>
......
......@@ -447,6 +447,11 @@ public RedisValue SetPop(RedisKey key, CommandFlags flags = CommandFlags.None)
return Inner.SetPop(ToInner(key), flags);
}
public RedisValue[] SetPop(RedisKey key, long count, CommandFlags flags = CommandFlags.None)
{
return Inner.SetPop(ToInner(key), count, flags);
}
public RedisValue SetRandomMember(RedisKey key, CommandFlags flags = CommandFlags.None)
{
return Inner.SetRandomMember(ToInner(key), flags);
......
......@@ -426,6 +426,11 @@ public Task<RedisValue> SetPopAsync(RedisKey key, CommandFlags flags = CommandFl
return Inner.SetPopAsync(ToInner(key), flags);
}
public Task<RedisValue[]> SetPopAsync(RedisKey key, long count, CommandFlags flags = CommandFlags.None)
{
return Inner.SetPopAsync(ToInner(key), count, flags);
}
public Task<RedisValue> SetRandomMemberAsync(RedisKey key, CommandFlags flags = CommandFlags.None)
{
return Inner.SetRandomMemberAsync(ToInner(key), flags);
......
......@@ -1245,12 +1245,24 @@ public RedisValue SetPop(RedisKey key, CommandFlags flags = CommandFlags.None)
return ExecuteSync(msg, ResultProcessor.RedisValue);
}
public RedisValue[] SetPop(RedisKey key, long count, CommandFlags flags = CommandFlags.None)
{
var msg = Message.Create(Database, flags, RedisCommand.SPOP, key, count);
return ExecuteSync(msg, ResultProcessor.RedisValueArray);
}
public Task<RedisValue> SetPopAsync(RedisKey key, CommandFlags flags = CommandFlags.None)
{
var msg = Message.Create(Database, flags, RedisCommand.SPOP, key);
return ExecuteAsync(msg, ResultProcessor.RedisValue);
}
public Task<RedisValue[]> SetPopAsync(RedisKey key, long count, CommandFlags flags = CommandFlags.None)
{
var msg = Message.Create(Database, flags, RedisCommand.SPOP, key, count);
return ExecuteAsync(msg, ResultProcessor.RedisValueArray);
}
public RedisValue SetRandomMember(RedisKey key, CommandFlags flags = CommandFlags.None)
{
var msg = Message.Create(Database, flags, RedisCommand.SRANDMEMBER, key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment