redis-cluster-client 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/redis_client/cluster/node/latency_replica.rb +3 -3
- data/lib/redis_client/cluster/pub_sub.rb +40 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16cd5b517f21a96b53fcaa47eb44e28b0c8d12aef23e3d2d239b2568d5ba61cd
|
4
|
+
data.tar.gz: ec4a1ebf3e548fdd7bfb184a910511f98919eecda1987674bef8d135bfc8b9da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92a61bcbb6964cb41ed791768d346f65b48d1943627fbea13b86cf995e921990dcc41651553f7c5200e60cebc7c5cc7e519795e02a9173e37dd1ef4da1201006
|
7
|
+
data.tar.gz: a27605d3438d40da8be910776db98fd6ede734c9ac8824c3bcedfc599d0d1f3f6f00187a7e785f96d0da8d1f480b0c6f012fa4670e31edf1c152f189a59bcf73
|
@@ -10,7 +10,7 @@ class RedisClient
|
|
10
10
|
|
11
11
|
attr_reader :replica_clients
|
12
12
|
|
13
|
-
|
13
|
+
DUMMY_LATENCY_MSEC = 100 * 1000 * 1000
|
14
14
|
MEASURE_ATTEMPT_COUNT = 10
|
15
15
|
|
16
16
|
def initialize(replications, options, pool, **kwargs)
|
@@ -45,7 +45,7 @@ class RedisClient
|
|
45
45
|
Thread.new(k, v) do |node_key, client|
|
46
46
|
Thread.current[:node_key] = node_key
|
47
47
|
|
48
|
-
min =
|
48
|
+
min = DUMMY_LATENCY_MSEC
|
49
49
|
MEASURE_ATTEMPT_COUNT.times do
|
50
50
|
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
|
51
51
|
client.call_once('PING')
|
@@ -55,7 +55,7 @@ class RedisClient
|
|
55
55
|
|
56
56
|
Thread.current[:latency] = min
|
57
57
|
rescue StandardError
|
58
|
-
Thread.current[:latency] =
|
58
|
+
Thread.current[:latency] = DUMMY_LATENCY_MSEC
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -3,33 +3,61 @@
|
|
3
3
|
class RedisClient
|
4
4
|
class Cluster
|
5
5
|
class PubSub
|
6
|
+
MAX_THREADS = Integer(ENV.fetch('REDIS_CLIENT_MAX_THREADS', 5))
|
7
|
+
|
6
8
|
def initialize(router, command_builder)
|
7
9
|
@router = router
|
8
10
|
@command_builder = command_builder
|
9
|
-
@
|
11
|
+
@pubsub_states = {}
|
10
12
|
end
|
11
13
|
|
12
14
|
def call(*args, **kwargs)
|
13
|
-
|
14
|
-
command = @command_builder.generate(args, kwargs)
|
15
|
-
@pubsub = @router.assign_node(command).pubsub
|
16
|
-
@pubsub.call_v(command)
|
15
|
+
_call(@command_builder.generate(args, kwargs))
|
17
16
|
end
|
18
17
|
|
19
18
|
def call_v(command)
|
20
|
-
|
21
|
-
command = @command_builder.generate(command)
|
22
|
-
@pubsub = @router.assign_node(command).pubsub
|
23
|
-
@pubsub.call_v(command)
|
19
|
+
_call(@command_builder.generate(command))
|
24
20
|
end
|
25
21
|
|
26
22
|
def close
|
27
|
-
@
|
28
|
-
@
|
23
|
+
@pubsub_states.each_value(&:close)
|
24
|
+
@pubsub_states.clear
|
29
25
|
end
|
30
26
|
|
31
27
|
def next_event(timeout = nil)
|
32
|
-
|
28
|
+
msgs = collect_messages(timeout).compact
|
29
|
+
return msgs.first if msgs.size == 1
|
30
|
+
|
31
|
+
msgs
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def _call(command)
|
37
|
+
node_key = @router.find_node_key(command)
|
38
|
+
pubsub = if @pubsub_states.key?(node_key)
|
39
|
+
@pubsub_states[node_key]
|
40
|
+
else
|
41
|
+
@pubsub_states[node_key] = @router.find_node(node_key).pubsub
|
42
|
+
end
|
43
|
+
pubsub.call_v(command)
|
44
|
+
end
|
45
|
+
|
46
|
+
def collect_messages(timeout)
|
47
|
+
@pubsub_states.each_slice(MAX_THREADS).each_with_object([]) do |chuncked_pubsub_states, acc|
|
48
|
+
threads = chuncked_pubsub_states.map do |_, v|
|
49
|
+
Thread.new(v) do |pubsub|
|
50
|
+
Thread.current[:reply] = pubsub.next_event(timeout)
|
51
|
+
rescue StandardError => e
|
52
|
+
Thread.current[:reply] = e
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
threads.each do |t|
|
57
|
+
t.join
|
58
|
+
acc << t[:reply]
|
59
|
+
end
|
60
|
+
end
|
33
61
|
end
|
34
62
|
end
|
35
63
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-cluster-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taishi Kasuga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-client
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
|
-
rubygems_version: 3.4.
|
72
|
+
rubygems_version: 3.4.13
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: A Redis cluster client for Ruby
|