redis-cluster-client 0.4.3 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redis_client/cluster/node/latency_replica.rb +3 -3
- data/lib/redis_client/cluster/pub_sub.rb +42 -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: be67f7c4a1a9e75573c957233bc9381745fc143b483583a4abb02b6b794bf49a
|
4
|
+
data.tar.gz: b12b518ba293af7e8f84e9a8c4770c5d5e8d776e213af30db94bcba753612802
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa19e009a6af98f69b797a88fd0ce3e09c9cd74d0bed99fdcabf4c15e78435179736e66d5d18e0e2c66c44d6343ab75e443b3d8577b37beb91ed13065f00bf4c
|
7
|
+
data.tar.gz: e055226106abe328b92d84da1f63e2d3e3ef22168cf3716837e96a7491249862894d98fa49edd92681083d6617787701411e51dab391322f1259af86a730149f
|
@@ -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,63 @@
|
|
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
|
+
return if @pubsub_states.empty?
|
29
|
+
|
30
|
+
msgs = collect_messages(timeout).compact
|
31
|
+
return msgs.first if msgs.size < 2
|
32
|
+
|
33
|
+
msgs
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def _call(command)
|
39
|
+
node_key = @router.find_node_key(command)
|
40
|
+
pubsub = if @pubsub_states.key?(node_key)
|
41
|
+
@pubsub_states[node_key]
|
42
|
+
else
|
43
|
+
@pubsub_states[node_key] = @router.find_node(node_key).pubsub
|
44
|
+
end
|
45
|
+
pubsub.call_v(command)
|
46
|
+
end
|
47
|
+
|
48
|
+
def collect_messages(timeout) # rubocop:disable Metrics/AbcSize
|
49
|
+
@pubsub_states.each_slice(MAX_THREADS).each_with_object([]) do |chuncked_pubsub_states, acc|
|
50
|
+
threads = chuncked_pubsub_states.map do |_, v|
|
51
|
+
Thread.new(v) do |pubsub|
|
52
|
+
Thread.current[:reply] = pubsub.next_event(timeout)
|
53
|
+
rescue StandardError => e
|
54
|
+
Thread.current[:reply] = e
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
threads.each do |t|
|
59
|
+
t.join
|
60
|
+
acc << t[:reply] unless t[:reply].nil?
|
61
|
+
end
|
62
|
+
end
|
33
63
|
end
|
34
64
|
end
|
35
65
|
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.5
|
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
|