redis-client 0.19.1 → 0.20.0

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: 920d97dcf258796ba88bb2f087fa89c1595dd245f67292c7432893848baacd0b
4
- data.tar.gz: 07151d3aa036f7c513e7baa2cc94c22a7f9b4af8a09e132b1943716cd458c408
3
+ metadata.gz: 154db13231ff43137f013f9ef224846201eabf5fef93059a5ed48206e558f238
4
+ data.tar.gz: 882208c7ad423619cc19cdc3c0b9ae02bd75e425bd702e29b1f2104896a4e0cc
5
5
  SHA512:
6
- metadata.gz: a6f664cf2c5fe77115606dc15e031e6bccc55c440b55d521ef5429653acb89bf55597dd4e5cd4892fb61f9452790a2ca41e32e72c6f824c7da9609987b14ff42
7
- data.tar.gz: c6a34fe93aac6d5ae5c8995881e17581e64a762d0fdc3d3fe1772b07b1759196b2ca5a27e14e00c826399d03a1259f799c816ac1ca1ee001314d9b32f341ecb8
6
+ metadata.gz: 6e3d3fa8d9684387519cdcc90a7c43319678defa957087902fdb2297ada820cbe746c7821126bcfbdc1f35877bb642382c7b5abebd4a227b2b60a24b8944b4f8
7
+ data.tar.gz: 40ceb06e68a8fabd9dd067ab177f5e6ca83b9af04e04b8f166bdc36e33ddd642190c400446e029c91b8416eb44f17aeb5cea950b06b7afc2daf6fa5514bef3f3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Unreleased
2
2
 
3
+ # 0.20.0
4
+
5
+ - Accept `unix://` schemes as well as simple paths in the `url:` config parameter. #170.
6
+ - Make basic usage Ractor compatible.
7
+
3
8
  # 0.19.1
4
9
 
5
10
  - Fixed a bug in `hiredis-client` that could cause a crash if interrupted by `Timeout.timeout` or other `Thread#raise` based mecanism.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redis-client (0.19.1)
4
+ redis-client (0.20.0)
5
5
  connection_pool
6
6
 
7
7
  GEM
@@ -13,34 +13,40 @@ GEM
13
13
  connection_pool (2.4.1)
14
14
  hiredis (0.6.3)
15
15
  hiredis (0.6.3-java)
16
- minitest (5.15.0)
17
- parallel (1.22.1)
18
- parser (3.1.2.1)
16
+ json (2.7.1)
17
+ json (2.7.1-java)
18
+ minitest (5.22.0)
19
+ parallel (1.24.0)
20
+ parser (3.3.0.5)
19
21
  ast (~> 2.4.1)
22
+ racc
23
+ racc (1.7.3)
24
+ racc (1.7.3-java)
20
25
  rainbow (3.1.1)
21
26
  rake (13.1.0)
22
- rake-compiler (1.2.5)
27
+ rake-compiler (1.2.7)
23
28
  rake
24
29
  redis (4.6.0)
25
- regexp_parser (2.5.0)
26
- rexml (3.2.5)
27
- rubocop (1.28.2)
30
+ regexp_parser (2.9.0)
31
+ rexml (3.2.6)
32
+ rubocop (1.50.2)
33
+ json (~> 2.3)
28
34
  parallel (~> 1.10)
29
- parser (>= 3.1.0.0)
35
+ parser (>= 3.2.0.0)
30
36
  rainbow (>= 2.2.2, < 4.0)
31
37
  regexp_parser (>= 1.8, < 3.0)
32
- rexml
33
- rubocop-ast (>= 1.17.0, < 2.0)
38
+ rexml (>= 3.2.5, < 4.0)
39
+ rubocop-ast (>= 1.28.0, < 2.0)
34
40
  ruby-progressbar (~> 1.7)
35
- unicode-display_width (>= 1.4.0, < 3.0)
36
- rubocop-ast (1.17.0)
37
- parser (>= 3.1.1.0)
38
- rubocop-minitest (0.19.1)
39
- rubocop (>= 0.90, < 2.0)
40
- ruby-progressbar (1.11.0)
41
- stackprof (0.2.25)
41
+ unicode-display_width (>= 2.4.0, < 3.0)
42
+ rubocop-ast (1.30.0)
43
+ parser (>= 3.2.1.0)
44
+ rubocop-minitest (0.30.0)
45
+ rubocop (>= 1.39, < 2.0)
46
+ ruby-progressbar (1.13.0)
47
+ stackprof (0.2.26)
42
48
  toxiproxy (2.0.2)
43
- unicode-display_width (2.2.0)
49
+ unicode-display_width (2.5.0)
44
50
 
45
51
  PLATFORMS
46
52
  ruby
data/README.md CHANGED
@@ -62,7 +62,9 @@ redis.call("GET", "mykey")
62
62
 
63
63
  ### Configuration
64
64
 
65
- - `url`: A Redis connection URL, e.g. `redis://example.com:6379/5`, a `rediss://` scheme enable SSL, and the path is interpreted as a database number.
65
+ - `url`: A Redis connection URL, e.g. `redis://example.com:6379/5` - a `rediss://` scheme enables SSL, and the path is interpreted as a database number.
66
+ To connect to UNIX domain sockets, the `url` can also just be a path, and the database specified as query parameter: `/run/redis/foo.sock?db=5`, or optionally
67
+ have a `unix://` scheme: `unix:///run/redis/foo.sock?db=5`
66
68
  Note that all other configurations take precedence, e.g. `RedisClient.config(url: "redis://localhost:3000", port: 6380)` will connect on port `6380`.
67
69
  - `host`: The server hostname or IP address. Defaults to `"localhost"`.
68
70
  - `port`: The server port. Defaults to `6379`.
@@ -151,6 +151,12 @@ class RedisClient
151
151
  if @db && @db != 0
152
152
  prelude << ["SELECT", @db.to_s]
153
153
  end
154
+
155
+ # Deep freeze all the strings and commands
156
+ prelude.map! do |commands|
157
+ commands = commands.map { |str| str.frozen? ? str : str.dup.freeze }
158
+ commands.freeze
159
+ end
154
160
  prelude.freeze
155
161
  end
156
162
  end
@@ -176,15 +182,20 @@ class RedisClient
176
182
  }.compact.merge(kwargs)
177
183
  host ||= url_config.host
178
184
  port ||= url_config.port
185
+ path ||= url_config.path
179
186
  username ||= url_config.username
180
187
  password ||= url_config.password
181
188
  end
182
189
 
183
190
  super(username: username, password: password, **kwargs)
184
191
 
185
- @host = host || DEFAULT_HOST
186
- @port = Integer(port || DEFAULT_PORT)
187
- @path = path
192
+ if @path = path
193
+ @host = nil
194
+ @port = nil
195
+ else
196
+ @host = host || DEFAULT_HOST
197
+ @port = Integer(port || DEFAULT_PORT)
198
+ end
188
199
  end
189
200
  end
190
201
  end
@@ -10,12 +10,12 @@ class RedisClient
10
10
 
11
11
  EOL = "\r\n".b.freeze
12
12
  EOL_SIZE = EOL.bytesize
13
- DUMP_TYPES = { # rubocop:disable Style/MutableConstant
13
+ DUMP_TYPES = {
14
14
  String => :dump_string,
15
15
  Symbol => :dump_symbol,
16
16
  Integer => :dump_numeric,
17
17
  Float => :dump_numeric,
18
- }
18
+ }.freeze
19
19
  PARSER_TYPES = {
20
20
  '#' => :parse_boolean,
21
21
  '$' => :parse_blob,
@@ -57,7 +57,7 @@ class RedisClient
57
57
  def dump_any(object, buffer)
58
58
  method = DUMP_TYPES.fetch(object.class) do |unexpected_class|
59
59
  if superclass = DUMP_TYPES.keys.find { |t| t > unexpected_class }
60
- DUMP_TYPES[unexpected_class] = DUMP_TYPES[superclass]
60
+ DUMP_TYPES[superclass]
61
61
  else
62
62
  raise TypeError, "Unsupported command argument type: #{unexpected_class}"
63
63
  end
@@ -4,26 +4,41 @@ require "uri"
4
4
 
5
5
  class RedisClient
6
6
  class URLConfig
7
- DEFAULT_SCHEMA = "redis"
8
- SSL_SCHEMA = "rediss"
9
-
10
7
  attr_reader :url, :uri
11
8
 
12
9
  def initialize(url)
13
10
  @url = url
14
11
  @uri = URI(url)
15
- unless uri.scheme == DEFAULT_SCHEMA || uri.scheme == SSL_SCHEMA
16
- raise ArgumentError, "Invalid URL: #{url.inspect}"
12
+ @unix = false
13
+ @ssl = false
14
+ case uri.scheme
15
+ when "redis"
16
+ # expected
17
+ when "rediss"
18
+ @ssl = true
19
+ when "unix", nil
20
+ @unix = true
21
+ else
22
+ raise ArgumentError, "Unknown URL scheme: #{url.inspect}"
17
23
  end
18
24
  end
19
25
 
20
26
  def ssl?
21
- @uri.scheme == SSL_SCHEMA
27
+ @ssl
22
28
  end
23
29
 
24
30
  def db
25
- db_path = uri.path&.delete_prefix("/")
26
- Integer(db_path) if db_path && !db_path.empty?
31
+ unless @unix
32
+ db_path = uri.path&.delete_prefix("/")
33
+ return Integer(db_path) if db_path && !db_path.empty?
34
+ end
35
+
36
+ unless uri.query.nil? || uri.query.empty?
37
+ _, db_query = URI.decode_www_form(uri.query).find do |key, _|
38
+ key == "db"
39
+ end
40
+ return Integer(db_query) if db_query && !db_query.empty?
41
+ end
27
42
  end
28
43
 
29
44
  def username
@@ -44,6 +59,12 @@ class RedisClient
44
59
  uri.host.sub(/\A\[(.*)\]\z/, '\1')
45
60
  end
46
61
 
62
+ def path
63
+ if @unix
64
+ File.join(*[uri.host, uri.path].compact)
65
+ end
66
+ end
67
+
47
68
  def port
48
69
  return unless uri.port
49
70
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RedisClient
4
- VERSION = "0.19.1"
4
+ VERSION = "0.20.0"
5
5
  end
data/redis-client.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "Simple low-level client for Redis 6+"
12
12
  spec.homepage = "https://github.com/redis-rb/redis-client"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = ">= 2.5.0"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
15
 
16
16
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
17
 
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.19.1
4
+ version: 0.20.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-12-21 00:00:00.000000000 Z
11
+ date: 2024-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -70,14 +70,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: 2.5.0
73
+ version: 2.6.0
74
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 3.4.10
80
+ rubygems_version: 3.5.5
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: Simple low-level client for Redis 6+