Redis SortedSet pop mutliple items

Hello,

I created a sorted set in Redis :

Redis.As<Dummy>().SortedSets[id];

Added some items and I want to retrieve multiple items from the OrderedSet (order is important) …
I tried PopItemsFromSet (maybe it’s Set specific and does not work for SortedSet?)

Redis.PopItemsFromSet(@event.Id, 10)

but it gives me

ServiceStack.Redis.RedisResponseException: wrong number of arguments for 'spop' command\r\n   at 
ServiceStack.Redis.RedisNativeClient.ReadMultiData()\r\n   at ServiceStack.Redis.RedisNativeClient.SendReceive[T]
(Byte[][] cmdWithBinaryArgs, Func`1 fn, Action`1 completePipelineFn, Boolean sendWithoutRead)\r\n   at 
ServiceStack.Redis.RedisNativeClient.SendExpectMultiData(Byte[][] cmdWithBinaryArgs)\r\n   at 
ServiceStack.Redis.RedisNativeClient.SPop(String setId, Int32 count)\r\n   at 
ServiceStack.Redis.RedisClient.PopItemsFromSet(String setId, Int32 count)\r\n

Redis.PopItemWithHighestScoreFromSortedSet(@event.Id) works but only retrieve one item per request.

Would you have an idea on how to make this work? Should I use Redis queues instead?

Thanks,
Olivier

Yes it uses SPop which is a Redis operation specific to SET’s you can use the RemoveRangeFromSortedSet* APIs to remove multiple items from a sorted set.

The issue comes from Redis 3.2 introduced an optional count argument that can be passed to SPOP in order to retrieve multiple elements in a single call.. I’m on 3.0.3, it should explain the issue :stuck_out_tongue:

1 Like