Skip to content

Commit a0f560f

Browse files
authored
chore: fix some stuff, readme and test cases (#323)
1 parent 473b36e commit a0f560f

File tree

4 files changed

+40
-48
lines changed

4 files changed

+40
-48
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ and conditional execution with `WATCH`. Redis does not support cross-node transa
175175
transaction must live in the same key slot. To use transactions, you can use `#multi` method same as the [redis-client](https://github.com/redis-rb/redis-client#usage):
176176

177177
```ruby
178-
conn.multi do |tx|
178+
cli.multi do |tx|
179179
tx.call('INCR', 'my_key')
180180
tx.call('INCR', 'my_key')
181181
end
@@ -192,7 +192,7 @@ it _is_ possible to perform a transaction on the keys `{tag}foo` and `{tag}bar`.
192192
To perform such transactions on this gem, use `hashtag:
193193

194194
```ruby
195-
conn.multi do |tx|
195+
cli.multi do |tx|
196196
tx.call('INCR', '{user123}coins_spent')
197197
tx.call('DECR', '{user123}coins_available')
198198
end
@@ -201,11 +201,11 @@ end
201201
```ruby
202202
# Conditional execution with WATCH can be used to e.g. atomically swap two keys
203203
cli.call('MSET', '{myslot}1', 'v1', '{myslot}2', 'v2')
204-
conn.multi(watch: %w[{myslot}1 {myslot}2]) do |txn|
204+
cli.multi(watch: %w[{myslot}1 {myslot}2]) do |tx|
205205
old_key1 = cli.call('GET', '{myslot}1')
206206
old_key2 = cli.call('GET', '{myslot}2')
207-
txn.call('SET', '{myslot}1', old_key2)
208-
txn.call('SET', '{myslot}2', old_key1)
207+
tx.call('SET', '{myslot}1', old_key2)
208+
tx.call('SET', '{myslot}2', old_key1)
209209
end
210210
# This transaction will swap the values of {myslot}1 and {myslot}2 only if no concurrent connection modified
211211
# either of the values

lib/redis_client/cluster.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def pubsub
104104
# @see https://github.com/redis-rb/redis-cluster-client/issues/299
105105
def with(key: nil, hashtag: nil, write: true, _retry_count: 0, &_)
106106
key = process_with_arguments(key, hashtag)
107-
108107
node_key = @router.find_node_key_by_key(key, primary: write)
109108
node = @router.find_node(node_key)
110109
yield ::RedisClient::Cluster::PinningNode.new(node)

test/redis_client/test_cluster.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,19 @@ def test_transaction_with_error
308308
assert_equal('x', @client.call('GET', 'key1'))
309309
end
310310

311+
def test_transaction_without_error_during_queueing
312+
@client.call('SET', 'key1', 'x')
313+
314+
assert_raises(::RedisClient::CommandError) do
315+
@client.multi do |tx|
316+
tx.call('SET', 'key1', 'aaa')
317+
tx.call('INCR', 'key1')
318+
end
319+
end
320+
321+
assert_equal('aaa', @client.call('GET', 'key1'))
322+
end
323+
311324
def test_transaction_with_block
312325
@client.call('MSET', '{key}1', 'a', '{key}2', 'b', '{key}3', 'c')
313326

@@ -318,6 +331,14 @@ def test_transaction_with_block
318331
end
319332

320333
assert_equal(%w[aaa bbb ccc], got)
334+
335+
got = @client.multi(watch: %w[{key}1 {key}2 {key}3]) do |tx|
336+
tx.call('GET', '{key}1') { |x| "#{x}11" }
337+
tx.call('GET', '{key}2') { |x| "#{x}22" }
338+
tx.call('GET', '{key}3') { |x| "#{x}33" }
339+
end
340+
341+
assert_equal(%w[a11 b22 c33], got)
321342
end
322343

323344
def test_pubsub_without_subscription

test/test_against_cluster_state.rb

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ def test_the_state_of_cluster_resharding_with_pipelining
6060
end
6161

6262
def test_the_state_of_cluster_resharding_with_transaction
63+
call_cnt = 0
64+
6365
do_resharding_test do |keys|
6466
@client.multi do |tx|
67+
call_cnt += 1
6568
keys.each do |key|
6669
tx.call('SET', key, '0')
6770
tx.call('INCR', key)
@@ -74,6 +77,8 @@ def test_the_state_of_cluster_resharding_with_transaction
7477
assert_equal(want, got, "Case: GET: #{key}")
7578
end
7679
end
80+
81+
assert_equal(1, call_cnt)
7782
end
7883

7984
def test_the_state_of_cluster_resharding_with_pipelining_on_new_connection
@@ -145,27 +150,16 @@ def new_test_client
145150
class ScaleReadRandom < TestingWrapper
146151
include Mixin
147152

148-
# FIXME: https://github.com/redis/redis/issues/11312
149153
def test_the_state_of_cluster_resharding
150-
keys = nil
151-
do_resharding_test { |ks| keys = ks }
152-
keys.each { |key| assert_equal(key, @client.call('GET', key), "Case: GET: #{key}") }
154+
skip('https://github.com/redis/redis/issues/11312')
153155
end
154156

155-
# FIXME: https://github.com/redis/redis/issues/11312
156157
def test_the_state_of_cluster_resharding_with_pipelining
157-
keys = nil
158-
do_resharding_test { |ks| keys = ks }
159-
values = @client.pipelined { |pipeline| keys.each { |key| pipeline.call('GET', key) } }
160-
keys.each_with_index { |key, i| assert_equal(key, values[i], "Case: GET: #{key}") }
158+
skip('https://github.com/redis/redis/issues/11312')
161159
end
162160

163-
# FIXME: https://github.com/redis/redis/issues/11312
164161
def test_the_state_of_cluster_resharding_with_transaction
165-
keys = nil
166-
do_resharding_test { |ks| keys = ks }
167-
@client.multi { |tx| keys.each { |key| tx.call('SET', key, key) } }
168-
keys.each { |key| assert_equal(key, @client.call('GET', key), "Case: GET: #{key}") }
162+
skip('https://github.com/redis/redis/issues/11312')
169163
end
170164

171165
private
@@ -184,27 +178,16 @@ def new_test_client
184178
class ScaleReadRandomWithPrimary < TestingWrapper
185179
include Mixin
186180

187-
# FIXME: https://github.com/redis/redis/issues/11312
188181
def test_the_state_of_cluster_resharding
189-
keys = nil
190-
do_resharding_test { |ks| keys = ks }
191-
keys.each { |key| assert_equal(key, @client.call('GET', key), "Case: GET: #{key}") }
182+
skip('https://github.com/redis/redis/issues/11312')
192183
end
193184

194-
# FIXME: https://github.com/redis/redis/issues/11312
195185
def test_the_state_of_cluster_resharding_with_pipelining
196-
keys = nil
197-
do_resharding_test { |ks| keys = ks }
198-
values = @client.pipelined { |pipeline| keys.each { |key| pipeline.call('GET', key) } }
199-
keys.each_with_index { |key, i| assert_equal(key, values[i], "Case: GET: #{key}") }
186+
skip('https://github.com/redis/redis/issues/11312')
200187
end
201188

202-
# FIXME: https://github.com/redis/redis/issues/11312
203189
def test_the_state_of_cluster_resharding_with_transaction
204-
keys = nil
205-
do_resharding_test { |ks| keys = ks }
206-
@client.multi { |tx| keys.each { |key| tx.call('SET', key, key) } }
207-
keys.each { |key| assert_equal(key, @client.call('GET', key), "Case: GET: #{key}") }
190+
skip('https://github.com/redis/redis/issues/11312')
208191
end
209192

210193
private
@@ -223,27 +206,16 @@ def new_test_client
223206
class ScaleReadLatency < TestingWrapper
224207
include Mixin
225208

226-
# FIXME: https://github.com/redis/redis/issues/11312
227209
def test_the_state_of_cluster_resharding
228-
keys = nil
229-
do_resharding_test { |ks| keys = ks }
230-
keys.each { |key| assert_equal(key, @client.call('GET', key), "Case: GET: #{key}") }
210+
skip('https://github.com/redis/redis/issues/11312')
231211
end
232212

233-
# FIXME: https://github.com/redis/redis/issues/11312
234213
def test_the_state_of_cluster_resharding_with_pipelining
235-
keys = nil
236-
do_resharding_test { |ks| keys = ks }
237-
values = @client.pipelined { |pipeline| keys.each { |key| pipeline.call('GET', key) } }
238-
keys.each_with_index { |key, i| assert_equal(key, values[i], "Case: GET: #{key}") }
214+
skip('https://github.com/redis/redis/issues/11312')
239215
end
240216

241-
# FIXME: https://github.com/redis/redis/issues/11312
242217
def test_the_state_of_cluster_resharding_with_transaction
243-
keys = nil
244-
do_resharding_test { |ks| keys = ks }
245-
@client.multi { |tx| keys.each { |key| tx.call('SET', key, key) } }
246-
keys.each { |key| assert_equal(key, @client.call('GET', key), "Case: GET: #{key}") }
218+
skip('https://github.com/redis/redis/issues/11312')
247219
end
248220

249221
private

0 commit comments

Comments
 (0)