redis-cluster-client 0.4.6 → 0.4.8
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 +55 -30
- 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: eab80ca6b1a69e3c45bc0dd59f9dd05189559907e0976a534ddc5dc0de26527b
|
4
|
+
data.tar.gz: 90aa485da1918f0a46f36964ff7ede3c775dcf90ebf0477df0a6d5f2cc3846f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 101ec6c98f8f2164b4c8da1a497ca31ca456d7c567ac9c96e8ac3220b37be96160ad558111c19e92d67c1947c29523463011c073016158a2930c7462231f3bc8
|
7
|
+
data.tar.gz: 72067a86f5fb1839bab4766dad20e5157932238c1a6237c9de805cf7dbd77e784b5b1b47e560f3585550521b36632dd7e9a094ccecad0e4ee893eb27bfc1f342
|
@@ -3,13 +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
|
-
@
|
12
|
-
@messages = []
|
44
|
+
@states = {}
|
13
45
|
end
|
14
46
|
|
15
47
|
def call(*args, **kwargs)
|
@@ -21,46 +53,39 @@ class RedisClient
|
|
21
53
|
end
|
22
54
|
|
23
55
|
def close
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@messages.clear
|
56
|
+
@states.each_value(&:close)
|
57
|
+
@states.clear
|
27
58
|
end
|
28
59
|
|
29
60
|
def next_event(timeout = nil)
|
30
|
-
return if @
|
31
|
-
return @messages.shift unless @messages.empty?
|
61
|
+
return if @states.empty?
|
32
62
|
|
33
|
-
|
34
|
-
|
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
|
67
|
+
|
68
|
+
@states.values.shuffle.each do |pubsub|
|
69
|
+
message = pubsub.take_message(timeout)
|
70
|
+
return message if message
|
71
|
+
end
|
72
|
+
end
|
35
73
|
end
|
36
74
|
|
37
75
|
private
|
38
76
|
|
39
77
|
def _call(command)
|
40
78
|
node_key = @router.find_node_key(command)
|
41
|
-
|
42
|
-
|
43
|
-
else
|
44
|
-
@pubsub_states[node_key] = @router.find_node(node_key).pubsub
|
45
|
-
end
|
46
|
-
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)
|
47
81
|
end
|
48
82
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
Thread.new(v) do |pubsub|
|
53
|
-
Thread.current[:reply] = pubsub.next_event(timeout)
|
54
|
-
rescue StandardError => e
|
55
|
-
Thread.current[:reply] = e
|
56
|
-
end
|
57
|
-
end
|
83
|
+
def obtain_current_time
|
84
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
|
85
|
+
end
|
58
86
|
|
59
|
-
|
60
|
-
|
61
|
-
@messages << t[:reply] unless t[:reply].nil?
|
62
|
-
end
|
63
|
-
end
|
87
|
+
def calc_max_duration(timeout)
|
88
|
+
timeout.nil? || timeout < 0 ? 0 : timeout * 1_000_000
|
64
89
|
end
|
65
90
|
end
|
66
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.8
|
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
|