This PR makes watch & multi work more or less the same way for clustering as they do for normal redis.
Since it's supposed to be valid to perform your multi call on the original redis object, like this:
redis.watch('key') do
redis.multi do |tx|
# tx is performed on the same connection as the watch
end
end
we need to keeps some state in an ivar @active_watcher so we know to call MULTI on the same actual connection as WATCH (and appropriately fail if the keys got redirected or the node went down). This is technically threadsafe, because the watch/multi implementation is wrapped in the synchronize monitor; however, for good performance in multithreaded environments, you will most likely want to use a connection pool of Redis::Cluster instances.
This PR makes watch & multi work more or less the same way for clustering as they do for normal redis.
Since it's supposed to be valid to perform your multi call on the original redis object, like this:
we need to keeps some state in an ivar @active_watcher so we know to call MULTI on the same actual connection as WATCH (and appropriately fail if the keys got redirected or the node went down). This is technically threadsafe, because the watch/multi implementation is wrapped in the
synchronize
monitor; however, for good performance in multithreaded environments, you will most likely want to use a connection pool of Redis::Cluster instances.(note - this will need https://github.com/redis-rb/redis-cluster-client/pull/339 to be merged in order to work. But "the tests pass on my machine, I promise" 😂 )