redis-cluster-client 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e29792dd4eb3b7609baa8943b25a385c87dd36767ba679e9c9209be765a670b
4
- data.tar.gz: 367d7cb722ef026b76c7f200237c1c64a0dced84026c78a43feb55a72eb7accb
3
+ metadata.gz: 16cd5b517f21a96b53fcaa47eb44e28b0c8d12aef23e3d2d239b2568d5ba61cd
4
+ data.tar.gz: ec4a1ebf3e548fdd7bfb184a910511f98919eecda1987674bef8d135bfc8b9da
5
5
  SHA512:
6
- metadata.gz: c3b7eb12f99b928072eeb00f4465afc5be3a3cb07aeabfc821369151f94ebbf12029409317c21b57cb628710e786e1e423b84f543b7430c23d89f71e9fe9339b
7
- data.tar.gz: c317f99c5bb51be184f4aab415017260237e3614e535565649bb90d79a2b47c7b9edfb07c83b3a96ead85849c7bd97639ce6d60eb1f957df351908ae098f6795
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
- DUMMY_LATENCY_NSEC = 100 * 1000 * 1000 * 1000
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 = DUMMY_LATENCY_NSEC
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] = DUMMY_LATENCY_NSEC
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
- @pubsub = nil
11
+ @pubsub_states = {}
10
12
  end
11
13
 
12
14
  def call(*args, **kwargs)
13
- close
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
- close
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
- @pubsub&.close
28
- @pubsub = nil
23
+ @pubsub_states.each_value(&:close)
24
+ @pubsub_states.clear
29
25
  end
30
26
 
31
27
  def next_event(timeout = nil)
32
- @pubsub&.next_event(timeout)
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.3
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-03-08 00:00:00.000000000 Z
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.6
72
+ rubygems_version: 3.4.13
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: A Redis cluster client for Ruby