Skip to content

Commit d8f31b4

Browse files
authored
Fix documents and refactoring (#63)
1 parent f924e8d commit d8f31b4

File tree

7 files changed

+109
-16
lines changed

7 files changed

+109
-16
lines changed
File renamed without changes.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# RedisClient::Cluster
2+
3+
```mermaid
4+
classDiagram
5+
class RedisClient_Cluster {
6+
+inspect()
7+
+call()
8+
+call_once()
9+
+blocking_call()
10+
+scan()
11+
+sscan()
12+
+hscan()
13+
+zscan()
14+
+pipelined()
15+
+pubsub()
16+
+close()
17+
}
18+
19+
class RedisClient_ClusterConfig {
20+
+inspect()
21+
+new_pool()
22+
+new_client()
23+
+per_node_key()
24+
+use_replica?()
25+
+update_node()
26+
+add_node()
27+
+dup()
28+
}
29+
30+
class RedisClient_Cluster_Command {
31+
+self.load()
32+
+extract_first_key()
33+
+should_send_to_primary?()
34+
+should_send_to_replica?()
35+
}
36+
37+
class module_RedisClient_Cluster_KeySlotConverter {
38+
+convert()
39+
}
40+
41+
class RedisClient_Cluster_Node {
42+
+self.load_info()
43+
+inspect()
44+
+each()
45+
+sample()
46+
+node_keys()
47+
+primary_node_keys()
48+
+replica_node_keys()
49+
+find_by()
50+
+call_all()
51+
+call_primaries()
52+
+call_replicas()
53+
+send_ping()
54+
+scale_reading_clients()
55+
+find_node_key_of_primary()
56+
+find_node_key_of_replica()
57+
+update_slot()
58+
+replicated?()
59+
}
60+
61+
class module_RedisClient_Cluster_NodeKey {
62+
+hashify()
63+
+split()
64+
+build_from_uri()
65+
+build_from_host_port()
66+
}
67+
68+
class RedisClient_Cluster_Pipeline {
69+
+call()
70+
+call_once()
71+
+blocking_call()
72+
+empty?()
73+
+execute()
74+
}
75+
76+
class RedisClient_Cluster_PubSub {
77+
+call()
78+
+close()
79+
+next_event()
80+
}
81+
82+
class RedisClient_Cluster_Router {
83+
+send_command()
84+
+try_send()
85+
+scan()
86+
+assign_node()
87+
+find_node_key()
88+
+find_node()
89+
}
90+
91+
RedisClient_ClusterConfig ..> RedisClient_Cluster : new
92+
93+
RedisClient_Cluster ..> RedisClient_Cluster_Pipeline : new
94+
RedisClient_Cluster ..> RedisClient_Cluster_PubSub : new
95+
RedisClient_Cluster ..> RedisClient_Cluster_Router : new
96+
97+
RedisClient_Cluster_Router ..> RedisClient_Cluster_Node : new
98+
RedisClient_Cluster_Router ..> RedisClient_Cluster_Command : new
99+
RedisClient_Cluster_Router ..> module_RedisClient_Cluster_KeySlotConverter : call
100+
RedisClient_Cluster_Router ..> module_RedisClient_Cluster_NodeKey : call
101+
```
File renamed without changes.
File renamed without changes.

lib/redis_client/cluster.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
require 'redis_client'
44
require 'redis_client/cluster/pipeline'
5-
require 'redis_client/cluster/pubsub'
5+
require 'redis_client/cluster/pub_sub'
66
require 'redis_client/cluster/router'
77

88
class RedisClient
99
class Cluster
1010
ZERO_CURSOR_FOR_SCAN = '0'
11-
CMD_SCAN = 'SCAN'
12-
CMD_SSCAN = 'SSCAN'
13-
CMD_HSCAN = 'HSCAN'
14-
CMD_ZSCAN = 'ZSCAN'
1511

1612
def initialize(config, pool: nil, **kwargs)
1713
@router = ::RedisClient::Cluster::Router.new(config, pool: pool, **kwargs)
@@ -38,24 +34,24 @@ def scan(*args, **kwargs, &block)
3834

3935
cursor = ZERO_CURSOR_FOR_SCAN
4036
loop do
41-
cursor, keys = @router.scan(CMD_SCAN, cursor, *args, **kwargs)
37+
cursor, keys = @router.scan('SCAN', cursor, *args, **kwargs)
4238
keys.each(&block)
4339
break if cursor == ZERO_CURSOR_FOR_SCAN
4440
end
4541
end
4642

4743
def sscan(key, *args, **kwargs, &block)
48-
node = @router.assign_node(CMD_SSCAN, key)
44+
node = @router.assign_node('SSCAN', key)
4945
@router.try_send(node, :sscan, key, *args, **kwargs, &block)
5046
end
5147

5248
def hscan(key, *args, **kwargs, &block)
53-
node = @router.assign_node(CMD_HSCAN, key)
49+
node = @router.assign_node('HSCAN', key)
5450
@router.try_send(node, :hscan, key, *args, **kwargs, &block)
5551
end
5652

5753
def zscan(key, *args, **kwargs, &block)
58-
node = @router.assign_node(CMD_ZSCAN, key)
54+
node = @router.assign_node('ZSCAN', key)
5955
@router.try_send(node, :zscan, key, *args, **kwargs, &block)
6056
end
6157

lib/redis_client/cluster/router.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ class RedisClient
1111
class Cluster
1212
class Router
1313
ZERO_CURSOR_FOR_SCAN = '0'
14-
CMD_ASKING = 'ASKING'
15-
REPLY_OK = 'OK'
16-
REPLY_MOVED = 'MOVED'
17-
REPLY_ASK = 'ASK'
1814

1915
attr_reader :node
2016

@@ -69,13 +65,13 @@ def try_send(node, method, *args, retry_count: 3, **kwargs, &block) # rubocop:di
6965
rescue ::RedisClient::CommandError => e
7066
raise if retry_count <= 0
7167

72-
if e.message.start_with?(REPLY_MOVED)
68+
if e.message.start_with?('MOVED')
7369
node = assign_redirection_node(e.message)
7470
retry_count -= 1
7571
retry
76-
elsif e.message.start_with?(REPLY_ASK)
72+
elsif e.message.start_with?('ASK')
7773
node = assign_asking_node(e.message)
78-
node.call(CMD_ASKING)
74+
node.call('ASKING')
7975
retry_count -= 1
8076
retry
8177
else

0 commit comments

Comments
 (0)