Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 47b49ad

Browse files
committed
impl new RemoveItemsFromSortedSet
1 parent 7a5bbdd commit 47b49ad

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

lib/ServiceStack.Interfaces.dll

2 KB
Binary file not shown.

src/ServiceStack.Redis/RedisClient_SortedSet.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ public bool RemoveItemFromSortedSet(string setId, string value)
124124
return base.ZRem(setId, value.ToUtf8Bytes()) == Success;
125125
}
126126

127+
public long RemoveItemsFromSortedSet(string setId, List<string> values)
128+
{
129+
return base.ZRem(setId, values.Map(x => x.ToUtf8Bytes()).ToArray());
130+
}
131+
127132
public string PopItemWithLowestScoreFromSortedSet(string setId)
128133
{
129134
//TODO: this should be atomic

src/ServiceStack.Redis/RedisNativeClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,7 @@ public long ZRem(string setId, byte[][] values)
16621662
var cmdWithArgs = MergeCommandWithArgs(Commands.ZRem, setId.ToUtf8Bytes(), values);
16631663
return SendExpectLong(cmdWithArgs);
16641664
}
1665+
16651666
public double ZIncrBy(string setId, double incrBy, byte[] value)
16661667
{
16671668
AssertSetIdAndValue(setId, value);

tests/ServiceStack.Redis.Tests/RedisClientSortedSetTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ public void Can_RemoveFromSet()
9595
Assert.That(members, Is.EquivalentTo(storeMembers));
9696
}
9797

98+
[Test]
99+
public void Can_RemoveItemsFromSortedSet()
100+
{
101+
var removeMembers = new[] { "two" , "four", "six" };
102+
103+
storeMembers.ForEach(x => Redis.AddItemToSortedSet(SetId, x));
104+
105+
var removeCount = Redis.RemoveItemsFromSortedSet(SetId, removeMembers.ToList());
106+
Assert.That(removeCount, Is.EqualTo(2));
107+
108+
removeMembers.Each(x => storeMembers.Remove(x));
109+
110+
var members = Redis.GetAllItemsFromSortedSet(SetId);
111+
Assert.That(members, Is.EquivalentTo(storeMembers));
112+
}
113+
98114
[Test]
99115
public void Can_PopFromSet()
100116
{

0 commit comments

Comments
 (0)