redis-cluster-client 0.4.5 → 0.4.7
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/pub_sub.rb +54 -28
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b894248e71e984932e9d2f177640c86a7f7d08cb57d3bf43bb91603ffe737003
|
4
|
+
data.tar.gz: e1ca295dc2a19a4c16ecb2b69ef3ad28cd353c5f5b17db90749d29c8b9eb3f79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88f12ba8750400ac78ae399d0b1f1301a7d12626286d780a04268af16bc1fab58f2da168b8802766f631fb09327518ca0f6927e2b57f6c03a79b3ec4439b9033
|
7
|
+
data.tar.gz: f721594b1cf537dc05f7d999f99626814f88f3488bf8f2c3c67fa197214f24a1b5513a25e616666c2c8a840cd3b33c616517e8eb35eee9c169a21a3e63ad86ea
|
@@ -3,12 +3,45 @@
|
|
3
3
|
class RedisClient
|
4
4
|
class Cluster
|
5
5
|
class PubSub
|
6
|
-
|
6
|
+
class State
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
@worker = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(command)
|
13
|
+
@client.call_v(command)
|
14
|
+
end
|
15
|
+
|
16
|
+
def close
|
17
|
+
@worker.exit if @worker&.alive?
|
18
|
+
@client.close
|
19
|
+
end
|
20
|
+
|
21
|
+
def take_message(timeout)
|
22
|
+
@worker = subscribe(@client, timeout) if @worker.nil?
|
23
|
+
return if @worker.join(0.01).nil?
|
24
|
+
|
25
|
+
message = @worker[:reply]
|
26
|
+
@worker = nil
|
27
|
+
message
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def subscribe(client, timeout)
|
33
|
+
Thread.new(client, timeout) do |pubsub, to|
|
34
|
+
Thread.current[:reply] = pubsub.next_event(to)
|
35
|
+
rescue StandardError => e
|
36
|
+
Thread.current[:reply] = e
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
7
40
|
|
8
41
|
def initialize(router, command_builder)
|
9
42
|
@router = router
|
10
43
|
@command_builder = command_builder
|
11
|
-
@
|
44
|
+
@states = {}
|
12
45
|
end
|
13
46
|
|
14
47
|
def call(*args, **kwargs)
|
@@ -20,46 +53,39 @@ class RedisClient
|
|
20
53
|
end
|
21
54
|
|
22
55
|
def close
|
23
|
-
@
|
24
|
-
@
|
56
|
+
@states.each_value(&:close)
|
57
|
+
@states.clear
|
25
58
|
end
|
26
59
|
|
27
60
|
def next_event(timeout = nil)
|
28
|
-
return if @
|
61
|
+
return if @states.empty?
|
29
62
|
|
30
|
-
|
31
|
-
|
63
|
+
max_duration = calc_max_duration(timeout)
|
64
|
+
starting = obtain_current_time
|
65
|
+
loop do
|
66
|
+
break if max_duration > 0 && obtain_current_time - starting > max_duration
|
32
67
|
|
33
|
-
|
68
|
+
@states.each_value do |pubsub|
|
69
|
+
message = pubsub.take_message(timeout)
|
70
|
+
return message if message
|
71
|
+
end
|
72
|
+
end
|
34
73
|
end
|
35
74
|
|
36
75
|
private
|
37
76
|
|
38
77
|
def _call(command)
|
39
78
|
node_key = @router.find_node_key(command)
|
40
|
-
|
41
|
-
|
42
|
-
else
|
43
|
-
@pubsub_states[node_key] = @router.find_node(node_key).pubsub
|
44
|
-
end
|
45
|
-
pubsub.call_v(command)
|
79
|
+
@states[node_key] = State.new(@router.find_node(node_key).pubsub) unless @states.key?(node_key)
|
80
|
+
@states[node_key].call(command)
|
46
81
|
end
|
47
82
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
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
|
83
|
+
def obtain_current_time
|
84
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
|
85
|
+
end
|
57
86
|
|
58
|
-
|
59
|
-
|
60
|
-
acc << t[:reply] unless t[:reply].nil?
|
61
|
-
end
|
62
|
-
end
|
87
|
+
def calc_max_duration(timeout)
|
88
|
+
timeout.nil? || timeout < 0 ? 0 : timeout * 1_000_000
|
63
89
|
end
|
64
90
|
end
|
65
91
|
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.7
|
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-08-
|
11
|
+
date: 2023-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-client
|