marcoCasamento / Hangfire.Redis.StackExchange

HangFire Redis storage based on original (and now unsupported) Hangfire.Redis but using lovely StackExchange.Redis client
Other
452 stars 108 forks source link

Redis cluster Prefix issue #68

Closed jblagorce closed 6 years ago

jblagorce commented 6 years ago

Using a Redis cluster with 3 master nodes, I noticed that all the hangfire data ends up on a single node.

In fact, as far as I understand, it seems like expected behaviour because :

I an attempt to distribute the data across the three nodes, I set up a prefix without curly brackets, "hangfire".

GlobalConfiguration.Configuration.UseRedisStorage(Redis, new RedisStorageOptions() { Prefix = "hangfire." });

Now each time I try to enqueue a job, I end up with the following 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"

I assume, that now that hashing distributes the keys across all nodes, the transaction mechanism prevents operation involving several nodes

Did I miss something obvious ? If not, is there a way to overcome this behaviour (something like disabling transaction mechanism when using redis cluster ?)

marcoCasamento commented 6 years ago

As far as I know you got it right. Basically you can’t distribute a redis transaction across multiple nodes. Transactions are needed to this library, especially for the Batches support, so, in order to allow the users of Hangfire.Redis to use their Redis cluster I’ve put curly brace in the default prefix. Answering to the question, no, there is no mechanism to disable the transactions, and I won’t go that way.

Da: jblagorce Inviato: mercoledì 20 settembre 2017 18:30 A: marcoCasamento/Hangfire.Redis.StackExchange Cc: Subscribed Oggetto: [marcoCasamento/Hangfire.Redis.StackExchange] Redis cluster Prefixissue (#68)

Using a Redis cluster with 3 master nodes, I noticed that all the hangfire data ends up on a single node. In fact, as far as I understand, it seems like expected behaviour because : • the default value for RedisStorageOptions.Prefix is "{hangfire}" • the algorithm for calculating the hash slot for a key will only consider the "hangfire" string for calculating the hash slot, according to cluster specification, because of the curly brackets in the prefix I an attempt to distribute the data across the three nodes, I set up a prefix without curly brackets, "hangfire". GlobalConfiguration.Configuration.UseRedisStorage(Redis, new RedisStorageOptions() { Prefix = "hangfire." }); Now each time I try to enqueue a job, I end up with the following 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" I assume, that now that hashing distributes the keys across all nodes, the transaction mechanism prevents operation involving several nodes Did I miss something obvious ? If not, is there a way to overcome this behaviour (something like disabling transaction mechanism when using redis cluster ?) — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

jblagorce commented 6 years ago

Thanks for this quick and clear reply