redis-client 0.7.4 → 0.8.1

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: e6fbe9260e43212ff9c501d95cf262f0c34e4db3cbc4dc6bebef3e8d2f98fc52
4
- data.tar.gz: d8356c2d342ae51f70e33b28f5e5679bea021ed31240b35c055ea5ad5625e9a4
3
+ metadata.gz: e4699c416da87ac3ed64b078ac60643a3baaa7fc2e3884feb58cc86aeb619083
4
+ data.tar.gz: 5305b72684041089b57c12f493b16e81901718654058e2a5f920b18bb2b83792
5
5
  SHA512:
6
- metadata.gz: 7ad5fdf44a060e90f3d9a4b350733d208a745e625fa95764c7288047bfa4138e9e882a6608634374c66b3fa595037d8603eb902f431603c8c94048bacfbf8184
7
- data.tar.gz: c09bea07473c08a6d67b0615811484e50199da37ceb25a977129f616595fc7692d24aa46851272129b4a41c735f83a22dae0922a09bc74f6be72fe28dda2576d
6
+ metadata.gz: 119c4cf4e1a0eed4f9e67ad2be84fc6a63404cde61519a697efd85b643779cb41b30b32f765ec3308ccaf7fa4903684c9dab1ecb86b1289db2566b1943ac7010
7
+ data.tar.gz: dbcba8c22c20d4ac33d1e7a495bf95cb30bca7a8b63d98d8944f2c61abfefbf4a40fc3d3222591a85ab8936c5b9e83c946095458b9b31748fe3e3e4e4e37db9e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Unreleased
2
2
 
3
+ # 0.8.1
4
+
5
+ - Make the client resilient to `Timeout.timeout` or `Thread#kill` use (it still still very much discouraged to use).
6
+ Use of async interrupts could cause responses to be interleaved.
7
+ - hiredis: handle commands returning a top-level `false` (no command does this today, but some extensions might).
8
+ - Workaround a bug in Ruby 2.6 causing a crash if the `debug` gem is enabled when `redis-client` is being required. Fix: #48
9
+
10
+ # 0.8.0
11
+
12
+ - Add a `connect` interface to the instrumentation API.
13
+
3
14
  # 0.7.4
4
15
 
5
16
  - Properly parse script errors on pre 7.0 redis server.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redis-client (0.7.4)
4
+ redis-client (0.8.1)
5
5
  connection_pool
6
6
 
7
7
  GEM
@@ -10,7 +10,7 @@ GEM
10
10
  ast (2.4.2)
11
11
  benchmark-ips (2.10.0)
12
12
  byebug (11.1.3)
13
- connection_pool (2.2.5)
13
+ connection_pool (2.3.0)
14
14
  hiredis (0.6.3)
15
15
  hiredis (0.6.3-java)
16
16
  minitest (5.15.0)
data/README.md CHANGED
@@ -349,6 +349,10 @@ end
349
349
 
350
350
  ```ruby
351
351
  module MyRedisInstrumentation
352
+ def connect(redis_config)
353
+ MyMonitoringService.instrument("redis.connect") { super }
354
+ end
355
+
352
356
  def call(command, redis_config)
353
357
  MyMonitoringService.instrument("redis.query") { super }
354
358
  end
@@ -2,9 +2,21 @@
2
2
 
3
3
  class RedisClient
4
4
  module ConnectionMixin
5
+ def initialize
6
+ @pending_reads = 0
7
+ end
8
+
9
+ def revalidate
10
+ if @pending_reads == 0 && connected?
11
+ self
12
+ end
13
+ end
14
+
5
15
  def call(command, timeout)
16
+ @pending_reads += 1
6
17
  write(command)
7
18
  result = read(timeout)
19
+ @pending_reads -= 1
8
20
  if result.is_a?(CommandError)
9
21
  result._set_command(command)
10
22
  raise result
@@ -18,11 +30,13 @@ class RedisClient
18
30
 
19
31
  size = commands.size
20
32
  results = Array.new(commands.size)
33
+ @pending_reads += size
21
34
  write_multi(commands)
22
35
 
23
36
  size.times do |index|
24
37
  timeout = timeouts && timeouts[index]
25
38
  result = read(timeout)
39
+ @pending_reads -= 1
26
40
  if result.is_a?(CommandError)
27
41
  result._set_command(commands[index])
28
42
  exception ||= result
@@ -4,6 +4,10 @@ class RedisClient
4
4
  module Middlewares
5
5
  extend self
6
6
 
7
+ def connect(_config)
8
+ yield
9
+ end
10
+
7
11
  def call(command, _config)
8
12
  yield command
9
13
  end
@@ -51,46 +51,26 @@ class RedisClient
51
51
 
52
52
  methods = %w(pipelined multi pubsub call call_v call_once call_once_v blocking_call blocking_call_v)
53
53
  iterable_methods = %w(scan sscan hscan zscan)
54
- begin
55
- methods.each do |method|
56
- class_eval <<~RUBY, __FILE__, __LINE__ + 1
57
- def #{method}(...)
58
- with { |r| r.#{method}(...) }
59
- end
60
- RUBY
61
- end
62
-
63
- iterable_methods.each do |method|
64
- class_eval <<~RUBY, __FILE__, __LINE__ + 1
65
- def #{method}(...)
66
- unless block_given?
67
- return to_enum(__callee__, ...)
68
- end
54
+ methods.each do |method|
55
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
56
+ def #{method}(*args, &block)
57
+ with { |r| r.#{method}(*args, &block) }
58
+ end
59
+ ruby2_keywords :#{method} if respond_to?(:ruby2_keywords, true)
60
+ RUBY
61
+ end
69
62
 
70
- with { |r| r.#{method}(...) }
71
- end
72
- RUBY
73
- end
74
- rescue SyntaxError
75
- methods.each do |method|
76
- class_eval <<~RUBY, __FILE__, __LINE__ + 1
77
- def #{method}(*args, &block)
78
- with { |r| r.#{method}(*args, &block) }
63
+ iterable_methods.each do |method|
64
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
65
+ def #{method}(*args, &block)
66
+ unless block_given?
67
+ return to_enum(__callee__, *args)
79
68
  end
80
- RUBY
81
- end
82
-
83
- iterable_methods.each do |method|
84
- class_eval <<~RUBY, __FILE__, __LINE__ + 1
85
- def #{method}(*args, &block)
86
- unless block_given?
87
- return to_enum(__callee__, *args)
88
- end
89
69
 
90
- with { |r| r.#{method}(*args, &block) }
91
- end
92
- RUBY
93
- end
70
+ with { |r| r.#{method}(*args, &block) }
71
+ end
72
+ ruby2_keywords :#{method} if respond_to?(:ruby2_keywords, true)
73
+ RUBY
94
74
  end
95
75
 
96
76
  private
@@ -41,6 +41,7 @@ class RedisClient
41
41
  SUPPORTS_RESOLV_TIMEOUT = Socket.method(:tcp).parameters.any? { |p| p.last == :resolv_timeout }
42
42
 
43
43
  def initialize(config, connect_timeout:, read_timeout:, write_timeout:)
44
+ super()
44
45
  socket = if config.path
45
46
  UNIXSocket.new(config.path)
46
47
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RedisClient
4
- VERSION = "0.7.4"
4
+ VERSION = "0.8.1"
5
5
  end
data/lib/redis_client.rb CHANGED
@@ -641,16 +641,19 @@ class RedisClient
641
641
  end
642
642
 
643
643
  def raw_connection
644
+ @raw_connection = @raw_connection&.revalidate
644
645
  @raw_connection ||= connect
645
646
  end
646
647
 
647
648
  def connect
648
- connection = config.driver.new(
649
- config,
650
- connect_timeout: connect_timeout,
651
- read_timeout: read_timeout,
652
- write_timeout: write_timeout,
653
- )
649
+ connection = Middlewares.connect(config) do
650
+ config.driver.new(
651
+ config,
652
+ connect_timeout: connect_timeout,
653
+ read_timeout: read_timeout,
654
+ write_timeout: write_timeout,
655
+ )
656
+ end
654
657
 
655
658
  prelude = config.connection_prelude.dup
656
659
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-06 00:00:00.000000000 Z
11
+ date: 2022-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool