There are some differences of the interface for the transaction feature between redis gem and redis-client gem. It seems that the redis-client gem is designed to be more simpler than the redis gem.
redis.multi(watch: %w[key]) do |tx|
next unless redis.call('GET', 'key') == 'some value'
tx.call('SET', 'key', 'other value')
tx.call('INCR', 'counter')
end
On the redis-clustering gem side, I fixed some bugs for the transaction feature, but several compatibilities were broken.
1255
So I tried to implement to keep the compatibility as possible by using an adapter. The adapter fills the interface gap between the redis-clustering gem and the redis-cluster-client gem. Because the cluster client implementation for the transaction feature tends to be complex for the sharding, we are hard to keep the same behaviors between the redis gem and the redis-clustering gem. But I thought it is possible up to a point.
redis.watch('{my}key') do |client| # The client is an instance of the adapter
if redis.get('{my}key') == 'some value' # We can't use the client passed by the block argument
client.multi do |tx| # The tx is the same instance of the adapter
tx.set('{my}key', 'other value')
tx.incr('{my}counter')
end
else
client.unwatch
end
end
There are some differences of the interface for the transaction feature between redis gem and redis-client gem. It seems that the redis-client gem is designed to be more simpler than the redis gem.
redis gem: https://github.com/redis/redis-rb/blob/cdfe17264f1a67b35eb60d1532cee103c18692f1/lib/redis/commands/transactions.rb#L38-L49
redis-client gem: https://github.com/redis-rb/redis-client?tab=readme-ov-file#transactions
On the redis-clustering gem side, I fixed some bugs for the transaction feature, but several compatibilities were broken.
1255
So I tried to implement to keep the compatibility as possible by using an adapter. The adapter fills the interface gap between the redis-clustering gem and the redis-cluster-client gem. Because the cluster client implementation for the transaction feature tends to be complex for the sharding, we are hard to keep the same behaviors between the redis gem and the redis-clustering gem. But I thought it is possible up to a point.