StackExchange.Redis icon indicating copy to clipboard operation
StackExchange.Redis copied to clipboard

SetCombine method throws exception: StackExchange.Redis.RedisCommandException: Multi-key operations must involve a single slot;

Open arbarik opened this issue 10 years ago • 1 comments

I am using SetCombine() method to find the difference between 2 sets . It throws an exception:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.DiscoverNewSharePointSiteCollection ---> StackExchange.Redis.RedisCommandException: Multi-key operations must involve a single slot; keys can use 'hash tags' to help this, i.e. '{/users/12345}/account' and '{/users/12345}/contacts' will always be in the same slot at StackExchange.Redis.ServerSelectionStrategy.Select(Message message)

at StackExchange.Redis.ConnectionMultiplexer.TryPushMessageToBridge[T](Message message, ResultProcessor<T> processor, ResultBox<T> resultBox, ServerEndPoint& server) 
at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor<T> processor, ServerEndPoint server) 
at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor<T> processor, ServerEndPoint server) 
at StackExchange.Redis.RedisDatabase.SetCombine(SetOperation operation, RedisKey first, RedisKey second, CommandFlags flags)

How do I fix this ?

arbarik avatar Aug 30 '16 09:08 arbarik

As the message says here, the key component is hash tags. See the example there? The bit between the {...} are hashed, and will go to the same slot in the cluster. The general form is:

{thingToHash}.restOfKey

If thingToHash is the same for 2 keys, they'll be on the same slot, and you can SetCombine() them :)

NickCraver avatar Jun 01 '18 22:06 NickCraver