redis-rb icon indicating copy to clipboard operation
redis-rb copied to clipboard

Implement #watch and #multi specially for cluster-client

Open KJTsanaktsidis opened this issue 4 months ago • 0 comments

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.

(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" 😂 )

KJTsanaktsidis avatar Feb 21 '24 02:02 KJTsanaktsidis