4
4
5
5
class Redis
6
6
class Cluster
7
- class TransactionAdapter < RedisClient ::Cluster ::Transaction
7
+ class TransactionAdapter
8
+ class Internal < RedisClient ::Cluster ::Transaction
9
+ def initialize ( client , router , command_builder , node : nil , slot : nil , asking : false )
10
+ @client = client
11
+ super ( router , command_builder , node : node , slot : slot , asking : asking )
12
+ end
13
+
14
+ def multi
15
+ raise ( Redis ::Cluster ::TransactionConsistencyError , "Can't nest multi transaction" )
16
+ end
17
+
18
+ def exec
19
+ # no need to do anything
20
+ end
21
+
22
+ def discard
23
+ # no need to do anything
24
+ end
25
+
26
+ def watch ( *_ )
27
+ raise ( Redis ::Cluster ::TransactionConsistencyError , "Can't use watch in a transaction" )
28
+ end
29
+
30
+ def unwatch
31
+ # no need to do anything
32
+ end
33
+
34
+ private
35
+
36
+ def method_missing ( name , *args , **kwargs , &block )
37
+ return call ( name , *args , **kwargs , &block ) if @client . respond_to? ( name )
38
+
39
+ super
40
+ end
41
+
42
+ def respond_to_missing? ( name , include_private = false )
43
+ return true if @client . respond_to? ( name )
44
+
45
+ super
46
+ end
47
+ end
48
+
8
49
def initialize ( client , router , command_builder , node : nil , slot : nil , asking : false )
9
50
@client = client
10
- super ( router , command_builder , node : node , slot : slot , asking : asking )
51
+ @router = router
52
+ @command_builder = command_builder
53
+ @node = node
54
+ @slot = slot
55
+ @asking = asking
56
+ @lock_released = false
57
+ end
58
+
59
+ def lock_released?
60
+ @lock_released
11
61
end
12
62
13
63
def multi
14
- yield self
64
+ @lock_released = true
65
+ transaction = Redis ::Cluster ::TransactionAdapter ::Internal . new (
66
+ @client , @router , @command_builder , node : @node , slot : @slot , asking : @asking
67
+ )
68
+ yield transaction
69
+ transaction . execute
15
70
end
16
71
17
72
def exec
@@ -23,20 +78,18 @@ def discard
23
78
end
24
79
25
80
def watch ( *_ )
26
- raise (
27
- Redis ::Cluster ::TransactionConsistencyError ,
28
- 'You should pass all the keys to a watch method if you use the cluster client.'
29
- )
81
+ raise ( Redis ::Cluster ::TransactionConsistencyError , "Can't nest watch command if you use the cluster client" )
30
82
end
31
83
32
84
def unwatch
33
- # no need to do anything
85
+ @lock_released = true
86
+ @node . call ( 'UNWATCH' )
34
87
end
35
88
36
89
private
37
90
38
91
def method_missing ( name , *args , **kwargs , &block )
39
- return call ( name , *args , **kwargs , &block ) if @client . respond_to? ( name )
92
+ return @client . public_send ( name , *args , **kwargs , &block ) if @client . respond_to? ( name )
40
93
41
94
super
42
95
end
0 commit comments