redis-client 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +2 -2
- data/lib/redis_client/pid_cache.rb +34 -0
- data/lib/redis_client/ruby_connection.rb +32 -0
- data/lib/redis_client/version.rb +1 -1
- data/lib/redis_client.rb +4 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e12fdb44add8ecb747b797c75a5991c973cb78519bbbce1f15a68bb80d1e2bb9
|
4
|
+
data.tar.gz: 0def4c2cc5a2f55ec9e9eb48a4ce5bfeadbef889c9695642126c011aebcd83b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b242cf54b503ae90c4642acdd8d59d8022639cb97de09a664afcbaec8730269fab79e298b0e4e2f74fe54f14ecc36e54adbb65b508d9aead715d0758921a2bd
|
7
|
+
data.tar.gz: e8b33e77e568ad63150b40e5a17d5ef528346868d802be80b4953d68986a89b93eaa1d24dcd80368c7b73bcab4ee9428d6d0ad99f300eb18ef43502783649686
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# 0.13.0
|
4
|
+
|
5
|
+
- Enable TCP keepalive on redis sockets. It sends a keep alive probe every 15 seconds for 2 minutes. #94.
|
6
|
+
|
7
|
+
# 0.12.2
|
8
|
+
|
9
|
+
- Cache calls to `Process.pid` on Ruby 3.1+. #91.
|
10
|
+
|
3
11
|
# 0.12.1
|
4
12
|
|
5
13
|
- Improve compatibility with `uri 0.12.0` (default in Ruby 3.2.0).
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
redis-client (0.
|
4
|
+
redis-client (0.13.0)
|
5
5
|
connection_pool
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ast (2.4.2)
|
11
|
-
benchmark-ips (2.
|
11
|
+
benchmark-ips (2.11.0)
|
12
12
|
byebug (11.1.3)
|
13
13
|
connection_pool (2.3.0)
|
14
14
|
hiredis (0.6.3)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class RedisClient
|
4
|
+
module PIDCache
|
5
|
+
if !Process.respond_to?(:fork) # JRuby or TruffleRuby
|
6
|
+
@pid = Process.pid
|
7
|
+
singleton_class.attr_reader(:pid)
|
8
|
+
elsif Process.respond_to?(:_fork) # Ruby 3.1+
|
9
|
+
class << self
|
10
|
+
attr_reader :pid
|
11
|
+
|
12
|
+
def update!
|
13
|
+
@pid = Process.pid
|
14
|
+
end
|
15
|
+
end
|
16
|
+
update!
|
17
|
+
|
18
|
+
module CoreExt
|
19
|
+
def _fork
|
20
|
+
child_pid = super
|
21
|
+
PIDCache.update! if child_pid == 0
|
22
|
+
child_pid
|
23
|
+
end
|
24
|
+
end
|
25
|
+
Process.singleton_class.prepend(CoreExt)
|
26
|
+
else # Ruby 3.0 or older
|
27
|
+
class << self
|
28
|
+
def pid
|
29
|
+
Process.pid
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -52,6 +52,7 @@ class RedisClient
|
|
52
52
|
end
|
53
53
|
# disables Nagle's Algorithm, prevents multiple round trips with MULTI
|
54
54
|
sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
55
|
+
enable_socket_keep_alive(sock)
|
55
56
|
sock
|
56
57
|
end
|
57
58
|
|
@@ -129,5 +130,36 @@ class RedisClient
|
|
129
130
|
rescue SystemCallError, IOError, OpenSSL::SSL::SSLError => error
|
130
131
|
raise ConnectionError, error.message
|
131
132
|
end
|
133
|
+
|
134
|
+
private
|
135
|
+
|
136
|
+
KEEP_ALIVE_INTERVAL = 15 # Same as hiredis defaults
|
137
|
+
KEEP_ALIVE_TTL = 120 # Longer than hiredis defaults
|
138
|
+
KEEP_ALIVE_PROBES = (KEEP_ALIVE_TTL / KEEP_ALIVE_INTERVAL) - 1
|
139
|
+
private_constant :KEEP_ALIVE_INTERVAL
|
140
|
+
private_constant :KEEP_ALIVE_TTL
|
141
|
+
private_constant :KEEP_ALIVE_PROBES
|
142
|
+
|
143
|
+
if %i[SOL_SOCKET TCP_KEEPIDLE TCP_KEEPINTVL TCP_KEEPCNT].all? { |c| Socket.const_defined? c } # Linux
|
144
|
+
def enable_socket_keep_alive(socket)
|
145
|
+
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
|
146
|
+
socket.setsockopt(Socket::SOL_TCP, Socket::TCP_KEEPIDLE, KEEP_ALIVE_INTERVAL)
|
147
|
+
socket.setsockopt(Socket::SOL_TCP, Socket::TCP_KEEPINTVL, KEEP_ALIVE_INTERVAL)
|
148
|
+
socket.setsockopt(Socket::SOL_TCP, Socket::TCP_KEEPCNT, KEEP_ALIVE_PROBES)
|
149
|
+
end
|
150
|
+
elsif %i[IPPROTO_TCP TCP_KEEPINTVL TCP_KEEPCNT].all? { |c| Socket.const_defined? c } # macOS
|
151
|
+
def enable_socket_keep_alive(socket)
|
152
|
+
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
|
153
|
+
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPINTVL, KEEP_ALIVE_INTERVAL)
|
154
|
+
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPCNT, KEEP_ALIVE_PROBES)
|
155
|
+
end
|
156
|
+
elsif %i[SOL_SOCKET SO_KEEPALIVE].all? { |c| Socket.const_defined? c } # unknown POSIX
|
157
|
+
def enable_socket_keep_alive(socket)
|
158
|
+
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
|
159
|
+
end
|
160
|
+
else # unknown
|
161
|
+
def enable_socket_keep_alive(_socket)
|
162
|
+
end
|
163
|
+
end
|
132
164
|
end
|
133
165
|
end
|
data/lib/redis_client/version.rb
CHANGED
data/lib/redis_client.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "redis_client/version"
|
4
4
|
require "redis_client/command_builder"
|
5
5
|
require "redis_client/config"
|
6
|
+
require "redis_client/pid_cache"
|
6
7
|
require "redis_client/sentinel_config"
|
7
8
|
require "redis_client/middlewares"
|
8
9
|
|
@@ -67,7 +68,7 @@ class RedisClient
|
|
67
68
|
@read_timeout = read_timeout
|
68
69
|
@write_timeout = write_timeout
|
69
70
|
@command_builder = config.command_builder
|
70
|
-
@pid =
|
71
|
+
@pid = PIDCache.pid
|
71
72
|
end
|
72
73
|
|
73
74
|
def timeout=(timeout)
|
@@ -609,7 +610,7 @@ class RedisClient
|
|
609
610
|
end
|
610
611
|
|
611
612
|
def ensure_connected(retryable: true)
|
612
|
-
close if !config.inherit_socket && @pid !=
|
613
|
+
close if !config.inherit_socket && @pid != PIDCache.pid
|
613
614
|
|
614
615
|
if @disable_reconnection
|
615
616
|
if block_given?
|
@@ -658,7 +659,7 @@ class RedisClient
|
|
658
659
|
end
|
659
660
|
|
660
661
|
def connect
|
661
|
-
@pid =
|
662
|
+
@pid = PIDCache.pid
|
662
663
|
|
663
664
|
connection = @middlewares.connect(config) do
|
664
665
|
config.driver.new(
|
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.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/redis_client/connection_mixin.rb
|
46
46
|
- lib/redis_client/decorator.rb
|
47
47
|
- lib/redis_client/middlewares.rb
|
48
|
+
- lib/redis_client/pid_cache.rb
|
48
49
|
- lib/redis_client/pooled.rb
|
49
50
|
- lib/redis_client/ruby_connection.rb
|
50
51
|
- lib/redis_client/ruby_connection/buffered_io.rb
|
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
76
|
- !ruby/object:Gem::Version
|
76
77
|
version: '0'
|
77
78
|
requirements: []
|
78
|
-
rubygems_version: 3.4.
|
79
|
+
rubygems_version: 3.4.6
|
79
80
|
signing_key:
|
80
81
|
specification_version: 4
|
81
82
|
summary: Simple low-level client for Redis 6+
|