redis 5.1.0 → 5.3.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: ab20cee7f44b7d5f2736e1fbc7073cb950f52ceefc3dc1ff0edf9b4b778c7d8d
4
- data.tar.gz: 76b0b6169311906b2ee634f9314c74052a1612245d7e33220aab5cb2c617af8a
3
+ metadata.gz: 175cb33b8059b353221168931b076c107b96cb4136a2b169e7dd2674b9a82259
4
+ data.tar.gz: 4c1fd79ea3974799be65c3d269ada25539045e7c265ccfda8b8be21647a9b1f7
5
5
  SHA512:
6
- metadata.gz: 220927cf03b0ad6ab0c7340d9b32ed073e379974d054eba12cf966ad65837eba00f114d1fdeb166780ead645befcc3ee9fb3a83aab8e8cb0b1661370f401f8cb
7
- data.tar.gz: 8f9476be4c7d4a3dd8dc1f29265b184932f67b49d524a0c79865dc95eee3ba165e9d24cb3f699ce287b886cc4f38b88574a5b33b1bab48f2fe9971597b7d2c5c
6
+ metadata.gz: 8881d1fecbb0755865094498cf43994c77d82492cdb88916aeb66cf675629cd85cd9e47a35d62b3a790b0efef78df843d32d9f73ccbec6104658368d48509d09
7
+ data.tar.gz: 3334c1a5f7174ad18e36c5d6ddab3c00c433648d38b9db7210935750d18f144acdf535c5a6d4ac16360fd6c77a4efa5196d4b585332c77e4e5e51e1d41b71691
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Unreleased
2
2
 
3
+ # 5.3.0
4
+
5
+ - Fix the return type of `hgetall` when used inside a `multi` transaction which is itself inside a pipeline.
6
+
7
+ # 5.2.0
8
+
9
+ - Now require Ruby 2.6 because `redis-client` does.
10
+ - Eagerly close subscribed connection when using `subscribe_with_timeout`. See #1259.
11
+ - Add `exception` flag in `pipelined` allowing failed commands to be returned in the result array when set to `false`.
12
+
3
13
  # 5.1.0
4
14
 
5
15
  - `multi` now accept a `watch` keyword argument like `redis-client`. See #1236.
data/README.md CHANGED
@@ -191,6 +191,28 @@ end
191
191
  # => ["OK"]
192
192
  ```
193
193
 
194
+ ### Exception management
195
+
196
+ The `exception` flag in the `#pipelined` is a feature that modifies the pipeline execution behavior. When set
197
+ to `false`, it doesn't raise an exception when a command error occurs. Instead, it allows the pipeline to execute all
198
+ commands, and any failed command will be available in the returned array. (Defaults to `true`)
199
+
200
+ ```ruby
201
+ results = redis.pipelined(exception: false) do |pipeline|
202
+ pipeline.set('key1', 'value1')
203
+ pipeline.lpush('key1', 'something') # This will fail
204
+ pipeline.set('key2', 'value2')
205
+ end
206
+ # results => ["OK", #<RedisClient::WrongTypeError: WRONGTYPE Operation against a key holding the wrong kind of value>, "OK"]
207
+
208
+ results.each do |result|
209
+ if result.is_a?(Redis::CommandError)
210
+ # Do something with the failed result
211
+ end
212
+ end
213
+ ```
214
+
215
+
194
216
  ### Executing commands atomically
195
217
 
196
218
  You can use `MULTI/EXEC` to run a number of commands in an atomic
@@ -251,6 +273,7 @@ See lib/redis/errors.rb for information about what exceptions are possible.
251
273
  ## Timeouts
252
274
 
253
275
  The client allows you to configure connect, read, and write timeouts.
276
+ Starting in version 5.0, the default for each is 1. Before that, it was 5.
254
277
  Passing a single `timeout` option will set all three values:
255
278
 
256
279
  ```ruby
data/lib/redis/client.rb CHANGED
@@ -105,7 +105,7 @@ class Redis
105
105
  Client.translate_error!(error)
106
106
  end
107
107
 
108
- def pipelined
108
+ def pipelined(exception: true)
109
109
  super
110
110
  rescue ::RedisClient::Error => error
111
111
  Client.translate_error!(error)
@@ -222,6 +222,8 @@ class Redis
222
222
  # - `:count => Integer`: return count keys at most per iteration
223
223
  #
224
224
  # @return [String, Array<[String, String]>] the next cursor and all found keys
225
+ #
226
+ # See the [Redis Server HSCAN documentation](https://redis.io/docs/latest/commands/hscan/) for further details
225
227
  def hscan(key, cursor, **options)
226
228
  _scan(:hscan, cursor, [key], **options) do |reply|
227
229
  [reply[0], reply[1].each_slice(2).to_a]
@@ -239,6 +241,8 @@ class Redis
239
241
  # - `:count => Integer`: return count keys at most per iteration
240
242
  #
241
243
  # @return [Enumerator] an enumerator for all found keys
244
+ #
245
+ # See the [Redis Server HSCAN documentation](https://redis.io/docs/latest/commands/hscan/) for further details
242
246
  def hscan_each(key, **options, &block)
243
247
  return to_enum(:hscan_each, key, **options) unless block_given?
244
248
 
@@ -22,6 +22,8 @@ class Redis
22
22
  # - `:type => String`: return keys only of the given type
23
23
  #
24
24
  # @return [String, Array<String>] the next cursor and all found keys
25
+ #
26
+ # See the [Redis Server SCAN documentation](https://redis.io/docs/latest/commands/scan/) for further details
25
27
  def scan(cursor, **options)
26
28
  _scan(:scan, cursor, [], **options)
27
29
  end
@@ -46,6 +48,8 @@ class Redis
46
48
  # - `:type => String`: return keys only of the given type
47
49
  #
48
50
  # @return [Enumerator] an enumerator for all found keys
51
+ #
52
+ # See the [Redis Server SCAN documentation](https://redis.io/docs/latest/commands/scan/) for further details
49
53
  def scan_each(**options, &block)
50
54
  return to_enum(:scan_each, **options) unless block_given?
51
55
 
@@ -282,6 +286,8 @@ class Redis
282
286
  #
283
287
  # @param [String] pattern
284
288
  # @return [Array<String>]
289
+ #
290
+ # See the [Redis Server KEYS documentation](https://redis.io/docs/latest/commands/keys/) for further details
285
291
  def keys(pattern = "*")
286
292
  send_command([:keys, pattern]) do |reply|
287
293
  if reply.is_a?(String)
@@ -29,17 +29,23 @@ class Redis
29
29
  end
30
30
 
31
31
  # Listen for messages published to channels matching the given patterns.
32
+ # See the [Redis Server PSUBSCRIBE documentation](https://redis.io/docs/latest/commands/psubscribe/)
33
+ # for further details
32
34
  def psubscribe(*channels, &block)
33
35
  _subscription(:psubscribe, 0, channels, block)
34
36
  end
35
37
 
36
38
  # Listen for messages published to channels matching the given patterns.
37
39
  # Throw a timeout error if there is no messages for a timeout period.
40
+ # See the [Redis Server PSUBSCRIBE documentation](https://redis.io/docs/latest/commands/psubscribe/)
41
+ # for further details
38
42
  def psubscribe_with_timeout(timeout, *channels, &block)
39
43
  _subscription(:psubscribe_with_timeout, timeout, channels, block)
40
44
  end
41
45
 
42
46
  # Stop listening for messages posted to channels matching the given patterns.
47
+ # See the [Redis Server PUNSUBSCRIBE documentation](https://redis.io/docs/latest/commands/punsubscribe/)
48
+ # for further details
43
49
  def punsubscribe(*channels)
44
50
  _subscription(:punsubscribe, 0, channels, nil)
45
51
  end
@@ -184,6 +184,8 @@ class Redis
184
184
  # - `:count => Integer`: return count keys at most per iteration
185
185
  #
186
186
  # @return [String, Array<String>] the next cursor and all found members
187
+ #
188
+ # See the [Redis Server SSCAN documentation](https://redis.io/docs/latest/commands/sscan/) for further details
187
189
  def sscan(key, cursor, **options)
188
190
  _scan(:sscan, cursor, [key], **options)
189
191
  end
@@ -199,6 +201,8 @@ class Redis
199
201
  # - `:count => Integer`: return count keys at most per iteration
200
202
  #
201
203
  # @return [Enumerator] an enumerator for all keys in the set
204
+ #
205
+ # See the [Redis Server SSCAN documentation](https://redis.io/docs/latest/commands/sscan/) for further details
202
206
  def sscan_each(key, **options, &block)
203
207
  return to_enum(:sscan_each, key, **options) unless block_given?
204
208
 
@@ -817,6 +817,8 @@ class Redis
817
817
  #
818
818
  # @return [String, Array<[String, Float]>] the next cursor and all found
819
819
  # members and scores
820
+ #
821
+ # See the [Redis Server ZSCAN documentation](https://redis.io/docs/latest/commands/zscan/) for further details
820
822
  def zscan(key, cursor, **options)
821
823
  _scan(:zscan, cursor, [key], **options) do |reply|
822
824
  [reply[0], FloatifyPairs.call(reply[1])]
@@ -834,6 +836,8 @@ class Redis
834
836
  # - `:count => Integer`: return count keys at most per iteration
835
837
  #
836
838
  # @return [Enumerator] an enumerator for all found scores and members
839
+ #
840
+ # See the [Redis Server ZSCAN documentation](https://redis.io/docs/latest/commands/zscan/) for further details
837
841
  def zscan_each(key, **options, &block)
838
842
  return to_enum(:zscan_each, key, **options) unless block_given?
839
843
 
@@ -948,12 +948,16 @@ class Redis
948
948
  end
949
949
 
950
950
  # Listen for messages published to channels matching the given patterns.
951
+ # See the [Redis Server PSUBSCRIBE documentation](https://redis.io/docs/latest/commands/psubscribe/)
952
+ # for further details
951
953
  def psubscribe(*channels, &block)
952
954
  raise NotImplementedError
953
955
  end
954
956
 
955
957
  # Stop listening for messages posted to channels matching the given
956
958
  # patterns.
959
+ # See the [Redis Server PUNSUBSCRIBE documentation](https://redis.io/docs/latest/commands/punsubscribe/)
960
+ # for further details
957
961
  def punsubscribe(*channels)
958
962
  raise NotImplementedError
959
963
  end
@@ -6,9 +6,10 @@ class Redis
6
6
  class PipelinedConnection
7
7
  attr_accessor :db
8
8
 
9
- def initialize(pipeline, futures = [])
9
+ def initialize(pipeline, futures = [], exception: true)
10
10
  @pipeline = pipeline
11
11
  @futures = futures
12
+ @exception = exception
12
13
  end
13
14
 
14
15
  include Commands
@@ -37,7 +38,7 @@ class Redis
37
38
  end
38
39
 
39
40
  def send_command(command, &block)
40
- future = Future.new(command, block)
41
+ future = Future.new(command, block, @exception)
41
42
  @pipeline.call_v(command) do |result|
42
43
  future._set(result)
43
44
  end
@@ -46,7 +47,7 @@ class Redis
46
47
  end
47
48
 
48
49
  def send_blocking_command(command, timeout, &block)
49
- future = Future.new(command, block)
50
+ future = Future.new(command, block, @exception)
50
51
  @pipeline.blocking_call_v(timeout, command) do |result|
51
52
  future._set(result)
52
53
  end
@@ -57,7 +58,7 @@ class Redis
57
58
 
58
59
  class MultiConnection < PipelinedConnection
59
60
  def multi
60
- raise Redis::Error, "Can't nest multi transaction"
61
+ raise Redis::BaseError, "Can't nest multi transaction"
61
62
  end
62
63
 
63
64
  private
@@ -79,10 +80,11 @@ class Redis
79
80
  class Future < BasicObject
80
81
  FutureNotReady = ::Redis::FutureNotReady.new
81
82
 
82
- def initialize(command, coerce)
83
+ def initialize(command, coerce, exception)
83
84
  @command = command
84
85
  @object = FutureNotReady
85
86
  @coerce = coerce
87
+ @exception = exception
86
88
  end
87
89
 
88
90
  def inspect
@@ -95,7 +97,7 @@ class Redis
95
97
  end
96
98
 
97
99
  def value
98
- ::Kernel.raise(@object) if @object.is_a?(::StandardError)
100
+ ::Kernel.raise(@object) if @exception && @object.is_a?(::StandardError)
99
101
  @object
100
102
  end
101
103
 
@@ -116,12 +118,14 @@ class Redis
116
118
  end
117
119
 
118
120
  def _set(replies)
119
- if replies
120
- @futures.each_with_index do |future, index|
121
+ @object = if replies
122
+ @futures.map.with_index do |future, index|
121
123
  future._set(replies[index])
124
+ future.value
122
125
  end
126
+ else
127
+ replies
123
128
  end
124
- @object = replies
125
129
  end
126
130
  end
127
131
  end
data/lib/redis/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Redis
4
- VERSION = '5.1.0'
4
+ VERSION = '5.3.0'
5
5
  end
data/lib/redis.rb CHANGED
@@ -99,10 +99,10 @@ class Redis
99
99
  @client
100
100
  end
101
101
 
102
- def pipelined
102
+ def pipelined(exception: true)
103
103
  synchronize do |client|
104
- client.pipelined do |raw_pipeline|
105
- yield PipelinedConnection.new(raw_pipeline)
104
+ client.pipelined(exception: exception) do |raw_pipeline|
105
+ yield PipelinedConnection.new(raw_pipeline, exception: exception)
106
106
  end
107
107
  end
108
108
  end
@@ -175,6 +175,7 @@ class Redis
175
175
  @subscription_client.send(method, *channels, &block)
176
176
  end
177
177
  ensure
178
+ @subscription_client&.close
178
179
  @subscription_client = nil
179
180
  end
180
181
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -16,7 +16,7 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2024-02-09 00:00:00.000000000 Z
19
+ date: 2024-08-21 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: redis-client
@@ -24,14 +24,14 @@ dependencies:
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 0.17.0
27
+ version: 0.22.0
28
28
  type: :runtime
29
29
  prerelease: false
30
30
  version_requirements: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 0.17.0
34
+ version: 0.22.0
35
35
  description: |2
36
36
  A Ruby client that tries to match Redis' API one-to-one, while still
37
37
  providing an idiomatic interface.
@@ -75,9 +75,9 @@ licenses:
75
75
  metadata:
76
76
  bug_tracker_uri: https://github.com/redis/redis-rb/issues
77
77
  changelog_uri: https://github.com/redis/redis-rb/blob/master/CHANGELOG.md
78
- documentation_uri: https://www.rubydoc.info/gems/redis/5.1.0
78
+ documentation_uri: https://www.rubydoc.info/gems/redis/5.3.0
79
79
  homepage_uri: https://github.com/redis/redis-rb
80
- source_code_uri: https://github.com/redis/redis-rb/tree/v5.1.0
80
+ source_code_uri: https://github.com/redis/redis-rb/tree/v5.3.0
81
81
  post_install_message:
82
82
  rdoc_options: []
83
83
  require_paths:
@@ -86,14 +86,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 2.5.0
89
+ version: 2.6.0
90
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 3.3.7
96
+ rubygems_version: 3.5.11
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: A Ruby client library for Redis