duel-redis 0.1.8 → 0.2.0

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: 45efac2222121eaab68097eb7417f757d7ccd9c15fb0515ae69ae439d875f3ec
4
- data.tar.gz: c3441c2a292cc613babc14506f85d9aadc93bbe227ea650be4a8255920251034
3
+ metadata.gz: 3d76de3bfdeda533e73e809a0ea72f4d1fbd57057de54235f1608d0cc139b2b0
4
+ data.tar.gz: 70518ca16c1ce0832d4f9d09538ce3d64fcec7ac8f36b0f007f945eb98e61051
5
5
  SHA512:
6
- metadata.gz: d30322adb4c52f965983d870d6618d75e4f9a18a8002369e2f4e74a1ade0bf1507d19b29d2698e466b448153b7c5a530efcb32d9928aef873be3e3a44641e9cd
7
- data.tar.gz: '09fef03403ebedb023a7f28dcb48e0d8335f8c2484ca1de69182eaac7fa63b133886d712172e0b2dcaf77def6b0e097a889a0e218afc22561941427a4ab44d56'
6
+ metadata.gz: c5104bbaa0634bfa797df55cd01c817d3238cc73689f9f9a5eea7d9b4fdf98003ec0d648180728e01253311f2f5ad93aa1b359450f6b4b597aa161a77932a5d0
7
+ data.tar.gz: 2b1f9110e428afae36778b84ccabcb810feed7d8487d4bb2a0f0cb8b8aee108c63cc88688586ff71004d1a1f8c18968712aef8a7072a85903ba07d93c0b9238d
data/CHANGELOG.md CHANGED
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.0] - 2026-11-16
11
+
12
+ ### Added
13
+
14
+ - `tcp: true` starts each worker's server on a port of 127.0.0.1's
15
+ alone, its URL `redis://127.0.0.1:PORT`, rather than a Unix socket:
16
+ the default on Windows, whose builds of Redis (Cygwin's, MSYS2's)
17
+ have Unix sockets of their own, which Windows's Ruby can't reach.
18
+
19
+ ### Fixed
20
+
21
+ - On JRuby, a worker that found its server's Unix socket before the
22
+ server listened on it failed, rather than waiting: JRuby's refusal
23
+ there is an `IOError` (CRuby's an `Errno::ECONNREFUSED`), which the
24
+ plugin now takes for a server not ready yet, as duel-memcached does.
25
+
10
26
  ## [0.1.8] - 2026-11-12
11
27
 
12
28
  No changes of its own: released in step with the other Duel gems.
@@ -77,7 +93,8 @@ license. It needs Ruby 3.4 or later, Duel 0.1, and `redis-server`
77
93
  read the next reply out of step.
78
94
 
79
95
 
80
- [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.8...HEAD
96
+ [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.2.0...HEAD
97
+ [0.2.0]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.8...duel-redis-v0.2.0
81
98
  [0.1.8]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.7...duel-redis-v0.1.8
82
99
  [0.1.7]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.6...duel-redis-v0.1.7
83
100
  [0.1.6]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.5...duel-redis-v0.1.6
data/README.md CHANGED
@@ -37,7 +37,10 @@ Duel.configure { |c| c.use :redis }
37
37
  ```
38
38
 
39
39
  Each worker's server listens only on a Unix socket in the worker's own
40
- directory, with persistence off, and works in that directory too
40
+ directory (or with `tcp: true`, on a port of 127.0.0.1's alone, as it
41
+ does by default on Windows, whose builds of Redis have Unix sockets
42
+ Windows's Ruby can't reach), with persistence off, and works in that
43
+ directory too
41
44
  (`--dir`): if your `args:` turn persistence on, its snapshots and
42
45
  append-only files go there, never in your project. Its URL is in
43
46
  `DUEL_REDIS_URL`, and in `REDIS_URL` too, so a client that reads that
@@ -67,7 +70,8 @@ Options:
67
70
  c.use :redis,
68
71
  server: "valkey-server", # the program (default: DUEL_REDIS_SERVER, or redis-server)
69
72
  args: ["--maxmemory", "64mb"], # more of its options
70
- env: %w[CACHE_URL] # variables given its URL besides DUEL_REDIS_URL (default: REDIS_URL)
73
+ env: %w[CACHE_URL], # variables given its URL besides DUEL_REDIS_URL (default: REDIS_URL)
74
+ tcp: true # on a port of 127.0.0.1's, its URL redis://127.0.0.1:PORT (default: on Windows only)
71
75
  ```
72
76
 
73
77
  The metrics come from the server's `INFO` (command statistics and
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Duel
4
4
  module Redis
5
- VERSION = "0.1.8"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
data/lib/duel/redis.rb CHANGED
@@ -18,9 +18,12 @@ module Duel
18
18
  #
19
19
  # Benchmarks can call Duel::Redis.url and Duel::Redis.flush.
20
20
  #
21
- # The server listens only on a Unix socket in the worker's directory,
22
- # and works there too (--dir): what its options make it write, a
23
- # snapshot or an append-only file, goes there, never in the project.
21
+ # The server listens only on a Unix socket in the worker's directory
22
+ # (or with +tcp+, on a port of 127.0.0.1's alone: by default on Windows,
23
+ # whose builds of Redis, Cygwin's or MSYS2's, have Unix sockets of their
24
+ # own, which Windows's Ruby can't reach), and works there too (--dir):
25
+ # what its options make it write, a snapshot or an append-only file,
26
+ # goes there, never in the project.
24
27
  # Its URL is in DUEL_REDIS_URL, and in REDIS_URL too (unless +env+
25
28
  # names others), so a client that reads that finds it.
26
29
  module Redis
@@ -35,12 +38,20 @@ module Duel
35
38
  # (+server+ is the program, +args+ more of its options) and its
36
39
  # metrics. Returns the plugin's own connection to it, a worker's
37
40
  # (see Config#in_worker, and in tests, Duel::Testing.in_worker).
38
- def self.configure(config, server: ENV.fetch("DUEL_REDIS_SERVER", "redis-server"), args: [], env: %w[REDIS_URL])
41
+ def self.configure(config, server: ENV.fetch("DUEL_REDIS_SERVER", "redis-server"), args: [], env: %w[REDIS_URL],
42
+ tcp: !Duel.unix_sockets?)
39
43
  config.prepare(:worker) do |w|
40
- socket = w.path("redis.sock")
41
- w.spawn(*[server, "--unixsocket", socket, "--dir", w.dir, *OPTIONS] + args)
42
- w.wait_until { Connection.ping(socket) }
43
- url = "unix://#{socket}"
44
+ if tcp
45
+ # (Its port after OPTIONS' 0, which it takes the place of.)
46
+ port = w.port
47
+ w.spawn(*[server, "--dir", w.dir, *OPTIONS, "--port", port.to_s, "--bind", "127.0.0.1"] + args)
48
+ url = "redis://127.0.0.1:#{port}"
49
+ else
50
+ socket = w.path("redis.sock")
51
+ w.spawn(*[server, "--unixsocket", socket, "--dir", w.dir, *OPTIONS] + args)
52
+ url = "unix://#{socket}"
53
+ end
54
+ w.wait_until { Connection.ping(url) }
44
55
  ([URL] + env).to_h { |name| [name, url] }
45
56
  end
46
57
  connection = config.in_worker { |w| Connection.new(url).tap { |redis| w.at_stop { redis.close } } }
@@ -94,20 +105,39 @@ module Duel
94
105
  # The first byte of a reply: its type, one of RESP2's.
95
106
  STATUS, ERROR, INTEGER, BULK, ARRAY = "+-:$*".bytes
96
107
 
97
- def self.ping(path)
98
- socket = UNIXSocket.new(path)
108
+ # A socket to the server at +url+: unix://PATH (or PATH alone), or
109
+ # redis://HOST:PORT, without TCP's delay before a small write (a
110
+ # command), whose reply would wait for it.
111
+ def self.socket(url)
112
+ address = address(url)
113
+ return UNIXSocket.new(url.delete_prefix("unix://")) unless address
114
+
115
+ host, port = address
116
+ # (RBS's setsockopt takes an Integer for the value, but Ruby's
117
+ # takes true too.)
118
+ TCPSocket.new(host, port).tap { |socket| socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true) } # steep:ignore ArgumentTypeMismatch
119
+ end
120
+
121
+ # The host and port of a redis:// URL, or nil (a Unix socket's).
122
+ def self.address(url)
123
+ match = %r{\Aredis://([^:/]+):(\d+)\z}.match(url) or return
124
+ [match[1], Integer(match[2])]
125
+ end
126
+
127
+ def self.ping(url)
128
+ connection = socket(url)
99
129
  begin
100
- socket.write("PING\r\n")
101
- socket.gets == "+PONG\r\n"
130
+ connection.write("PING\r\n")
131
+ connection.gets == "+PONG\r\n"
102
132
  ensure
103
- socket.close
133
+ connection.close
104
134
  end
105
- rescue SystemCallError
135
+ rescue SystemCallError, IOError # (JRuby's refusal on a Unix socket is an IOError)
106
136
  false
107
137
  end
108
138
 
109
139
  def initialize(url)
110
- @socket = UNIXSocket.new(url.delete_prefix("unix://"))
140
+ @socket = Connection.socket(url)
111
141
  end
112
142
 
113
143
  # Sends a command; returns its reply, read whole (every type RESP2
data/sig/duel/redis.rbs CHANGED
@@ -15,7 +15,9 @@ module Duel
15
15
  # is the program, +args+ more of its options, +env+ the variables
16
16
  # besides DUEL_REDIS_URL given its URL) and its metrics. Returns the
17
17
  # plugin's own connection to it, a worker's.
18
- def self.configure: (Config config, ?server: String, ?args: Array[String], ?env: Array[String]) -> InWorker[Connection]
18
+ # +tcp+: on a port of 127.0.0.1's, not a Unix socket (by default on
19
+ # Windows).
20
+ def self.configure: (Config config, ?server: String, ?args: Array[String], ?env: Array[String], ?tcp: bool) -> InWorker[Connection]
19
21
 
20
22
  # What the worker's server has done so far, read over +connection+.
21
23
  def self.stats: (Connection connection) -> Hash[String, Integer]
@@ -42,9 +44,16 @@ module Duel
42
44
  BULK: Integer
43
45
  ARRAY: Integer
44
46
 
45
- @socket: UNIXSocket
47
+ @socket: UNIXSocket | TCPSocket
46
48
 
47
- def self.ping: (String path) -> bool
49
+ # A socket to the server at +url+ (unix://PATH, PATH, or
50
+ # redis://HOST:PORT).
51
+ def self.socket: (String url) -> (UNIXSocket | TCPSocket)
52
+
53
+ # The host and port of a redis:// URL, or nil.
54
+ def self.address: (String url) -> [String, Integer]?
55
+
56
+ def self.ping: (String url) -> bool
48
57
 
49
58
  def initialize: (String url) -> void
50
59
 
metadata CHANGED
@@ -1,65 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duel-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Erik Berlin
7
+ - Erik Berlin
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: duel
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - "~>"
17
- - !ruby/object:Gem::Version
18
- version: '0.1'
19
- type: :runtime
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - "~>"
24
- - !ruby/object:Gem::Version
25
- version: '0.1'
26
- description: 'A Duel plugin: each worker gets a Redis server of its own, and every
27
- benchmark is judged on the Redis CPU time, commands and round trips it took too.'
12
+ - !ruby/object:Gem::Dependency
13
+ name: duel
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: "0.2"
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: "0.2"
28
+ description: "A Duel plugin: each worker gets a Redis server of its own, and every benchmark is judged on the Redis CPU time, commands and round trips it took too."
28
29
  email:
29
- - sferik@gmail.com
30
+ - sferik@gmail.com
30
31
  executables: []
31
32
  extensions: []
32
33
  extra_rdoc_files: []
33
34
  files:
34
- - CHANGELOG.md
35
- - LICENSE
36
- - README.md
37
- - lib/duel/redis.rb
38
- - lib/duel/redis/version.rb
39
- - sig/duel/redis.rbs
40
- homepage: https://github.com/sferik/duel-ruby/tree/main/plugins/redis
35
+ - CHANGELOG.md
36
+ - LICENSE
37
+ - README.md
38
+ - lib/duel/redis.rb
39
+ - lib/duel/redis/version.rb
40
+ - sig/duel/redis.rbs
41
+ homepage: "https://github.com/sferik/duel-ruby/tree/main/plugins/redis"
41
42
  licenses:
42
- - MIT
43
+ - MIT
43
44
  metadata:
44
- source_code_uri: https://github.com/sferik/duel-ruby/tree/main/plugins/redis
45
- changelog_uri: https://github.com/sferik/duel-ruby/blob/main/plugins/redis/CHANGELOG.md
46
- bug_tracker_uri: https://github.com/sferik/duel-ruby/issues
47
- rubygems_mfa_required: 'true'
45
+ source_code_uri: "https://github.com/sferik/duel-ruby/tree/main/plugins/redis"
46
+ changelog_uri: "https://github.com/sferik/duel-ruby/blob/main/plugins/redis/CHANGELOG.md"
47
+ bug_tracker_uri: "https://github.com/sferik/duel-ruby/issues"
48
+ rubygems_mfa_required: "true"
48
49
  rdoc_options: []
49
50
  require_paths:
50
- - lib
51
+ - lib
51
52
  required_ruby_version: !ruby/object:Gem::Requirement
52
53
  requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '3.4'
54
+ -
55
+ - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "3.4"
56
58
  required_rubygems_version: !ruby/object:Gem::Requirement
57
59
  requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '0'
60
+ -
61
+ - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
61
64
  requirements: []
62
- rubygems_version: 4.0.24
65
+ rubygems_version: 4.1.0
63
66
  specification_version: 4
64
- summary: A Redis server for each Duel worker, and what it did for each benchmark
67
+ summary: "A Redis server for each Duel worker, and what it did for each benchmark"
65
68
  test_files: []