You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In case of the above architecture, if you don't pass the `fixed_hostname` option to the client and servers return IP addresses of nodes, the client may fail to verify certificates.
78
+
79
+
## Transaction with an optimistic locking
80
+
Since Redis cluster is a distributed system, several behaviors are different from a standalone server.
81
+
Client libraries can make them compatible up to a point, but a part of features needs some restrictions.
82
+
Especially, some cautions are needed to use the transaction feature with an optimistic locking.
83
+
84
+
```ruby
85
+
redis.watch("{my}key") do |client| # The client is an instance of the internal adapter
86
+
if redis.get("{my}key") =="some value"# We can't use the client passed by the block argument
87
+
client.multi do |tx| # The tx is the same instance of the internal adapter
88
+
tx.set("{my}key", "other value")
89
+
tx.incr("{my}counter")
90
+
end
91
+
else
92
+
client.unwatch
93
+
end
94
+
end
95
+
```
96
+
97
+
In a cluster mode client, you need to pass a block if you call the watch method and you need to specify an argument to the block.
98
+
Also, you should use the block argument as a receiver to call the transaction feature methods in the block.
99
+
The commands called by methods of the receiver are added to the internal pipeline for the transaction and they are sent to the server lastly.
100
+
On the other hand, if you want to call other methods for commands, you can use the global instance of the client instead of the block argument.
101
+
It affects out of the transaction pipeline and the replies are returned soon.
102
+
Although the above restrictions are needed, this implementations is compatible with a standalone client.
0 commit comments