Skip to content

Commit b272f19

Browse files
authored
chore: cleanup (#352)
1 parent 06de17c commit b272f19

File tree

7 files changed

+15
-105
lines changed

7 files changed

+15
-105
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ The following methods are able to be used like `redis-client`.
130130
* `#pubsub`
131131
* `#close`
132132

133-
The other methods are not implemented because the client cannot operate with cluster mode.
134-
`#pipelined` method splits and sends commands to each node and aggregates replies.
133+
The `#scan` method iterates all keys around every node seamlessly.
134+
The `#pipelined` method splits and sends commands to each node and aggregates replies.
135+
The `#multi` method supports the transaction feature but you should use a hashtag for your keys.
136+
The `#pubsub` method supports sharded subscriptions.
137+
Every interface handles redirections and resharding states internally.
135138

136139
## Multiple keys and CROSSSLOT error
137140
A subset of commands can be passed multiple keys. But it has a constraint the keys are in the same hash slot.

lib/redis_client/cluster.rb

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
require 'redis_client/cluster/pub_sub'
66
require 'redis_client/cluster/router'
77
require 'redis_client/cluster/transaction'
8-
require 'redis_client/cluster/pinning_node'
98
require 'redis_client/cluster/optimistic_locking'
109

1110
class RedisClient
@@ -118,13 +117,8 @@ def pubsub
118117
::RedisClient::Cluster::PubSub.new(@router, @command_builder)
119118
end
120119

121-
# TODO: This isn't an official public interface yet. Don't use in your production environment.
122-
# @see https://github.com/redis-rb/redis-cluster-client/issues/299
123-
def with(key: nil, hashtag: nil, write: true)
124-
key = process_with_arguments(key, hashtag)
125-
node_key = @router.find_node_key_by_key(key, primary: write)
126-
node = @router.find_node(node_key)
127-
node.with { |c| yield ::RedisClient::Cluster::PinningNode.new(c) }
120+
def with(...)
121+
raise NotImplementedError, 'No way to use'
128122
end
129123

130124
def close
@@ -135,19 +129,6 @@ def close
135129

136130
private
137131

138-
def process_with_arguments(key, hashtag) # rubocop:disable Metrics/CyclomaticComplexity
139-
raise ArgumentError, 'Only one of key or hashtag may be provided' if key && hashtag
140-
141-
if hashtag
142-
# The documentation says not to wrap your hashtag in {}, but people will probably
143-
# do it anyway and it's easy for us to fix here.
144-
key = hashtag&.match?(/^{.*}$/) ? hashtag : "{#{hashtag}}"
145-
end
146-
raise ArgumentError, 'One of key or hashtag must be provided' if key.nil? || key.empty?
147-
148-
key
149-
end
150-
151132
def method_missing(name, *args, **kwargs, &block)
152133
if @router.command_exists?(name)
153134
args.unshift(name)

lib/redis_client/cluster/node.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,7 @@ def build_connection_prelude
9292
end
9393
end
9494

95-
def initialize(
96-
concurrent_worker,
97-
config:,
98-
pool: nil,
99-
**kwargs
100-
)
101-
95+
def initialize(concurrent_worker, config:, pool: nil, **kwargs)
10296
@concurrent_worker = concurrent_worker
10397
@slots = build_slot_node_mappings(EMPTY_ARRAY)
10498
@replications = build_replication_mappings(EMPTY_ARRAY)

lib/redis_client/cluster/node/base_topology.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ class Cluster
55
class Node
66
class BaseTopology
77
IGNORE_GENERIC_CONFIG_KEYS = %i[url host port path].freeze
8+
EMPTY_HASH = {}.freeze
9+
EMPTY_ARRAY = [].freeze
10+
811
attr_reader :clients, :primary_clients, :replica_clients
912

1013
def initialize(pool, concurrent_worker, **kwargs)

lib/redis_client/cluster/pinning_node.rb

Lines changed: 0 additions & 35 deletions
This file was deleted.

lib/redis_client/cluster/router.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ def send_pubsub_command(method, command, args, &block) # rubocop:disable Metrics
314314
end
315315
end
316316

317-
# for redis-rb
318317
def send_watch_command(command)
319318
raise ::RedisClient::Cluster::Transaction::ConsistencyError, 'A block required. And you need to use the block argument as a client for the transaction.' unless block_given?
320319

test/redis_client/test_cluster.rb

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ def test_transaction_in_race_condition
518518
assert_equal(%w[3 4], @client.call('MGET', '{key}1', '{key}2'))
519519
end
520520

521-
# for redis-rb
522521
def test_transaction_with_dedicated_watch_command
523522
@client.call('MSET', '{key}1', '0', '{key}2', '0')
524523

@@ -683,6 +682,10 @@ def test_other_pubsub_commands
683682
ps.close
684683
end
685684

685+
def test_with_method
686+
assert_raises(NotImplementedError) { @client.with }
687+
end
688+
686689
def test_dedicated_commands # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
687690
10.times { |i| @client.call('SET', "key#{i}", i) }
688691
wait_for_replication
@@ -819,44 +822,6 @@ def test_only_reshards_own_errors
819822
client2.close
820823
end
821824

822-
def test_pinning_single_key
823-
got = @client.with(key: 'key1') do |conn|
824-
conn.call('SET', 'key1', 'hello')
825-
conn.call('GET', 'key1')
826-
end
827-
assert_equal('hello', got)
828-
end
829-
830-
def test_pinning_no_key
831-
assert_raises(ArgumentError) do
832-
@client.with {}
833-
end
834-
end
835-
836-
def test_pinning_empty_key
837-
assert_raises(ArgumentError) do
838-
@client.with(key: '') {}
839-
end
840-
end
841-
842-
def test_pinning_two_keys
843-
got = @client.with(hashtag: 'slot') do |conn|
844-
conn.call('SET', '{slot}key1', 'v1')
845-
conn.call('SET', '{slot}key2', 'v2')
846-
conn.call('MGET', '{slot}key1', '{slot}key2')
847-
end
848-
assert_equal(%w[v1 v2], got)
849-
end
850-
851-
def test_pinning_hashtag_with_braces
852-
got = @client.with(hashtag: '{slot}') do |conn|
853-
conn.call('SET', '{slot}key1', 'v1')
854-
conn.call('SET', '{slot}key2', 'v2')
855-
conn.call('MGET', '{slot}key1', '{slot}key2')
856-
end
857-
assert_equal(%w[v1 v2], got)
858-
end
859-
860825
private
861826

862827
def wait_for_replication

0 commit comments

Comments
 (0)