redis / redis-rb

A Ruby client library for Redis
MIT License
3.96k stars 1.03k forks source link

Fix a cluster client interface for CAS operations to be more compatible with standalone client #1270

Closed supercaracal closed 4 months ago

supercaracal commented 4 months ago

Sorry the implementation changed again and again. I recently fixed the optimistic locking feature (a.k.a CAS operation), But I've considered a better implementation for the feature in the cluster client. I haven't convinced the previous implementation at a point that users incur to use two receivers depending on the use case. So this pull request makes receivers consolidated.

Before

redis.watch("{my}key") do |client|
  if redis.get("{my}key") == "some value" # <= this receiver
    client.multi do |tx|
      tx.set("{my}key", "other value")
      tx.incr("{my}counter")
    end
  else
    client.unwatch
  end
end

After

redis.watch("{my}key") do |client|
  if client.get("{my}key") == "some value" # <= this receiver
    client.multi do |tx|
      tx.set("{my}key", "other value")
      tx.incr("{my}counter")
    end
  else
    client.unwatch
  end
end