redis-cluster-client 0.13.4 → 0.13.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2879675038f9d7ac3f0857f89fef3929453ae927877cc220f7f488535bbbe8ba
4
- data.tar.gz: 56cbc27612c379f097066e600189aceaa7b9d62b7e0690ffda9b0392e17b0916
3
+ metadata.gz: 3e6204d25c8bc31540498f0fa7e3a8795d1a8ac35b1fe9c429a40512fa1f0702
4
+ data.tar.gz: 0ae970fff2f4b4f76fe72403bf66be39eabf0d5e74186b5093102210d22ab512
5
5
  SHA512:
6
- metadata.gz: dd73c96b5e0fcd5ae239ed8b487c8fa8118eeea9c671a1bf056feaa5832d0ff79230fc23245a319fd1af957d60472c3f891da64f840401b35576f441ded5e90e
7
- data.tar.gz: f17a9bc4c394ae9c691030f55774397fbb22d3008cdb0784003864275cb4184b3a73097d57c396715348fbdfe9d76a44a181395020afa5920540ffaa60cb6328
6
+ metadata.gz: f2ac7ad893b9102168b6a53da0dee3f8bc171240cf3fc98db9e9f99aa49f48b67744c6fac16d7fabed1e1699e86e1386155728ec61b4b5980f4a897826f77ea4
7
+ data.tar.gz: 82c3da07a56c0f2ac56434c982a0e8bb22f129545049bab135849b656c59aa38f3f54f0b1d687df05dcb3a78b544f74f92a91d4cf656c0e481820a8525e5f33a
@@ -10,6 +10,10 @@ class RedisClient
10
10
  # It is a fixed size but we can modify the size with some environment variables.
11
11
  # So it consumes memory 1 MB multiplied a number of workers.
12
12
  class Pooled
13
+ IO_ERROR_NEVER = { IOError => :never }.freeze
14
+ IO_ERROR_IMMEDIATE = { IOError => :immediate }.freeze
15
+ private_constant :IO_ERROR_NEVER, :IO_ERROR_IMMEDIATE
16
+
13
17
  def initialize(size:)
14
18
  raise ArgumentError, "size must be positive: #{size}" unless size.positive?
15
19
 
@@ -33,7 +37,9 @@ class RedisClient
33
37
 
34
38
  def close
35
39
  @q.clear
36
- @workers.each { |t| t&.exit }
40
+ workers = @workers.compact
41
+ workers.each(&:exit)
42
+ workers.each(&:join)
37
43
  @workers.clear
38
44
  @q.close
39
45
  @pid = nil
@@ -65,7 +71,15 @@ class RedisClient
65
71
 
66
72
  def spawn_worker
67
73
  Thread.new(@q) do |q|
68
- loop { q.pop.exec }
74
+ Thread.handle_interrupt(IO_ERROR_NEVER) do
75
+ loop do
76
+ Thread.handle_interrupt(IO_ERROR_IMMEDIATE) do
77
+ q.pop.exec
78
+ end
79
+ end
80
+ end
81
+ rescue IOError
82
+ # stream closed in another thread
69
83
  end
70
84
  end
71
85
  end
@@ -7,6 +7,10 @@ class RedisClient
7
7
  class Cluster
8
8
  class PubSub
9
9
  class State
10
+ IO_ERROR_NEVER = { IOError => :never }.freeze
11
+ IO_ERROR_IMMEDIATE = { IOError => :immediate }.freeze
12
+ private_constant :IO_ERROR_NEVER, :IO_ERROR_IMMEDIATE
13
+
10
14
  def initialize(client, queue)
11
15
  @client = client
12
16
  @worker = nil
@@ -22,7 +26,11 @@ class RedisClient
22
26
  end
23
27
 
24
28
  def close
25
- @worker.exit if @worker&.alive?
29
+ if @worker&.alive?
30
+ @worker.exit
31
+ @worker.join
32
+ end
33
+
26
34
  @client.close
27
35
  rescue ::RedisClient::ConnectionError
28
36
  # ignore
@@ -35,21 +43,24 @@ class RedisClient
35
43
  # It is a fixed size but we can modify the size with some environment variables.
36
44
  # So it consumes memory 1 MB multiplied a number of workers.
37
45
  Thread.new(client, queue, nil) do |pubsub, q, prev_err|
38
- loop do
39
- q << pubsub.next_event
40
- prev_err = nil
41
- rescue StandardError => e
42
- next sleep 0.005 if e.instance_of?(prev_err.class) && e.message == prev_err&.message
43
-
44
- q << e
45
- prev_err = e
46
+ Thread.handle_interrupt(IO_ERROR_NEVER) do
47
+ loop do
48
+ Thread.handle_interrupt(IO_ERROR_IMMEDIATE) { q << pubsub.next_event }
49
+ prev_err = nil
50
+ rescue StandardError => e
51
+ next sleep 0.005 if e.instance_of?(prev_err.class) && e.message == prev_err&.message
52
+
53
+ Thread.handle_interrupt(IO_ERROR_IMMEDIATE) { q << e }
54
+ prev_err = e
55
+ end
46
56
  end
57
+ rescue IOError
58
+ # stream closed in another thread
47
59
  end
48
60
  end
49
61
  end
50
62
 
51
63
  BUF_SIZE = Integer(ENV.fetch('REDIS_CLIENT_PUBSUB_BUF_SIZE', 1024))
52
-
53
64
  private_constant :BUF_SIZE
54
65
 
55
66
  def initialize(router, command_builder)
@@ -69,10 +69,18 @@ class RedisClient
69
69
  "#<#{self.class.name} #{startup_nodes.values.map { |v| v.reject { |k| k == :command_builder } }}>"
70
70
  end
71
71
 
72
+ def connect_timeout
73
+ @client_config[:connect_timeout] || @client_config[:timeout] || ::RedisClient::Config::DEFAULT_TIMEOUT
74
+ end
75
+
72
76
  def read_timeout
73
77
  @client_config[:read_timeout] || @client_config[:timeout] || ::RedisClient::Config::DEFAULT_TIMEOUT
74
78
  end
75
79
 
80
+ def write_timeout
81
+ @client_config[:write_timeout] || @client_config[:timeout] || ::RedisClient::Config::DEFAULT_TIMEOUT
82
+ end
83
+
76
84
  def new_pool(size: 5, timeout: 5, **kwargs)
77
85
  @client_implementation.new(
78
86
  self,
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-cluster-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.4
4
+ version: 0.13.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taishi Kasuga
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: redis-client
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  requirements: []
77
- rubygems_version: 3.6.2
77
+ rubygems_version: 3.6.9
78
78
  specification_version: 4
79
79
  summary: Redis cluster-aware client for Ruby
80
80
  test_files: []