redis 4.3.1 → 5.4.1

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +190 -0
  3. data/README.md +132 -154
  4. data/lib/redis/client.rb +81 -600
  5. data/lib/redis/commands/bitmaps.rb +73 -0
  6. data/lib/redis/commands/cluster.rb +28 -0
  7. data/lib/redis/commands/connection.rb +53 -0
  8. data/lib/redis/commands/geo.rb +84 -0
  9. data/lib/redis/commands/hashes.rb +258 -0
  10. data/lib/redis/commands/hyper_log_log.rb +37 -0
  11. data/lib/redis/commands/keys.rb +459 -0
  12. data/lib/redis/commands/lists.rb +339 -0
  13. data/lib/redis/commands/pubsub.rb +81 -0
  14. data/lib/redis/commands/scripting.rb +114 -0
  15. data/lib/redis/commands/server.rb +188 -0
  16. data/lib/redis/commands/sets.rb +218 -0
  17. data/lib/redis/commands/sorted_sets.rb +922 -0
  18. data/lib/redis/commands/streams.rb +409 -0
  19. data/lib/redis/commands/strings.rb +314 -0
  20. data/lib/redis/commands/transactions.rb +115 -0
  21. data/lib/redis/commands.rb +239 -0
  22. data/lib/redis/distributed.rb +236 -77
  23. data/lib/redis/errors.rb +20 -41
  24. data/lib/redis/hash_ring.rb +26 -26
  25. data/lib/redis/pipeline.rb +70 -120
  26. data/lib/redis/subscribe.rb +50 -14
  27. data/lib/redis/version.rb +1 -1
  28. data/lib/redis.rb +104 -3465
  29. metadata +27 -57
  30. data/lib/redis/cluster/command.rb +0 -81
  31. data/lib/redis/cluster/command_loader.rb +0 -34
  32. data/lib/redis/cluster/key_slot_converter.rb +0 -72
  33. data/lib/redis/cluster/node.rb +0 -107
  34. data/lib/redis/cluster/node_key.rb +0 -31
  35. data/lib/redis/cluster/node_loader.rb +0 -37
  36. data/lib/redis/cluster/option.rb +0 -93
  37. data/lib/redis/cluster/slot.rb +0 -86
  38. data/lib/redis/cluster/slot_loader.rb +0 -49
  39. data/lib/redis/cluster.rb +0 -295
  40. data/lib/redis/connection/command_helper.rb +0 -39
  41. data/lib/redis/connection/hiredis.rb +0 -67
  42. data/lib/redis/connection/registry.rb +0 -13
  43. data/lib/redis/connection/ruby.rb +0 -427
  44. data/lib/redis/connection/synchrony.rb +0 -146
  45. data/lib/redis/connection.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 416a2f007042c19453c13361aa4440a507e47fb32c28adc68e7c574c6651f5b4
4
- data.tar.gz: 1a845f2af649d64f8b274962c9d5d10e6eb5d046474b6e44288676432fe8a98b
3
+ metadata.gz: 5d76a0d8a8a0361f991dc110219ffc77c12503148f9ece9586dd274321283265
4
+ data.tar.gz: fab1b1d4d3a5e22d2d952c98648a1412239f117a2c53bcbdf20ea7c43f456faa
5
5
  SHA512:
6
- metadata.gz: 3766992242ae284ca474bc8564c6760de88e635a8c3bc3c80da08062d698cc891bf00455b5d98768709ecc766f8ad305fe03cc5806f03fda3ebb93049e0a1cce
7
- data.tar.gz: f440c984ec58ff091a6a696952239cb04cf145752b485543e5da7215a327b40be4391b3fe6ca67753f84ec43913b9d90ec0b6f812e1696890a7c17cbf3aa3630
6
+ metadata.gz: 042f0aa785647bb0e6f73ff50722ba5dcf440e3f5e817c7eec030b876b7d34ca8be42a7a5a5a1767eba66b7424a8d2e74fe8e7b9e0362eedefe4fb58878cdb57
7
+ data.tar.gz: 5bc22d99f3a77929f35c02072be18d663ca127c77055afadd55455d3f571f61bbd70853d6fd4414e0e11f601c20d68872e8f097fce109341e5bda39f6aadb9fe
data/CHANGELOG.md CHANGED
@@ -1,5 +1,195 @@
1
1
  # Unreleased
2
2
 
3
+ # 5.4.1
4
+
5
+ - Properly handle NOSCRIPT errors.
6
+
7
+ # 5.4.0
8
+
9
+ - Fix `blmpop` method to actually use `BLMPOP`, it was mistakenly issuing `LMPOP` commands.
10
+ - `xadd` now accepts a `minid:` argument.
11
+ - `zrank` and `zrevrank` now accepts `with_score:` argument.
12
+ - `Redis#call` now accept a block, allowing to use `Redis` instances where `RedisClient` is expected.
13
+
14
+ # 5.3.0
15
+
16
+ - Fix the return type of `hgetall` when used inside a `multi` transaction which is itself inside a pipeline.
17
+
18
+ # 5.2.0
19
+
20
+ - Now require Ruby 2.6 because `redis-client` does.
21
+ - Eagerly close subscribed connection when using `subscribe_with_timeout`. See #1259.
22
+ - Add `exception` flag in `pipelined` allowing failed commands to be returned in the result array when set to `false`.
23
+
24
+ # 5.1.0
25
+
26
+ - `multi` now accept a `watch` keyword argument like `redis-client`. See #1236.
27
+ - `bitcount` and `bitpos` now accept a `scale:` argument on Redis 7+. See #1242
28
+ - Added `expiretime` and `pexpiretime`. See #1248.
29
+
30
+ # 5.0.8
31
+
32
+ - Fix `Redis#without_reconnect` for sentinel clients. Fix #1212.
33
+ - Add `sentinel_username`, `sentinel_password` for sentinel clients. Bump `redis-client` to `>=0.17.0`. See #1213
34
+
35
+ # 5.0.7
36
+
37
+ - Fix compatibility with `redis-client 0.15.0` when using Redis Sentinel. Fix #1209.
38
+
39
+ # 5.0.6
40
+
41
+ - Wait for an extra `config.read_timeout` in blocking commands rather than an arbitrary 100ms. See #1175.
42
+ - Treat ReadOnlyError as ConnectionError. See #1168.
43
+
44
+ # 5.0.5
45
+
46
+ - Fix automatic disconnection when the process was forked. See #1157.
47
+
48
+ # 5.0.4
49
+
50
+ - Cast `ttl` argument to integer in `expire`, `setex` and a few others.
51
+
52
+ # 5.0.3
53
+
54
+ - Add `OutOfMemoryError` as a subclass of `CommandError`
55
+
56
+ # 5.0.2
57
+
58
+ - Fix `Redis#close` to properly reset the fork protection check.
59
+
60
+ # 5.0.1
61
+
62
+ - Added a fake `Redis::Connections.drivers` method to be compatible with older sidekiq versions.
63
+
64
+ # 5.0.0
65
+
66
+ - Default client timeout decreased from 5 seconds to 1 second.
67
+ - Eagerly and strictly cast Integer and Float parameters.
68
+ - Allow to call `subscribe`, `unsubscribe`, `psubscribe` and `punsubscribe` from a subscribed client. See #1131.
69
+ - Use `MD5` for hashing server nodes in `Redis::Distributed`. This should improve keys distribution among servers. See #1089.
70
+ - Changed `sadd` and `srem` to now always return an Integer.
71
+ - Added `sadd?` and `srem?` which always return a Boolean.
72
+ - Added support for `IDLE` paramter in `xpending`.
73
+ - Cluster support has been moved to a `redis-clustering` companion gem.
74
+ - `select` no longer record the current database. If the client has to reconnect after `select` was used, it will reconnect to the original database.
75
+ - Better support Float timeout in blocking commands. See #977.
76
+ - `Redis.new` will now raise an error if provided unknown options.
77
+ - Removed positional timeout in blocking commands (`BLPOP`, etc). Timeout now must be passed as an option: `r.blpop("key", timeout: 2.5)`
78
+ - Removed `logger` option.
79
+ - Removed `reconnect_delay_max` and `reconnect_delay`, you can pass precise sleep durations to `reconnect_attempts` instead.
80
+ - Require Ruby 2.5+.
81
+ - Removed the deprecated `queue` and `commit` methods. Use `pipelined` instead.
82
+ - Removed the deprecated `Redis::Future#==`.
83
+ - Removed the deprecated `pipelined` and `multi` signature. Commands now MUST be called on the block argument, not the original redis instance.
84
+ - Removed `Redis.current`. You shouldn't assume there is a single global Redis connection, use a connection pool instead,
85
+ and libaries using Redis should accept a Redis instance (or connection pool) as a config. E.g. `MyLibrary.redis = Redis.new(...)`.
86
+ - Removed the `synchrony` driver.
87
+ - Removed `Redis.exists_returns_integer`, it's now always enabled.
88
+
89
+ # 4.8.1
90
+
91
+ * Automatically reconnect after fork regardless of `reconnect_attempts`
92
+
93
+ # 4.8.0
94
+
95
+ * Introduce `sadd?` and `srem?` as boolean returning versions of `sadd` and `srem`.
96
+ * Deprecate `sadd` and `srem` returning a boolean when called with a single argument.
97
+ To enable the redis 5.0 behavior you can set `Redis.sadd_returns_boolean = false`.
98
+ * Deprecate passing `timeout` as a positional argument in blocking commands (`brpop`, `blop`, etc).
99
+
100
+ # 4.7.1
101
+
102
+ * Gracefully handle OpenSSL 3.0 EOF Errors (`OpenSSL::SSL::SSLError: SSL_read: unexpected eof while reading`). See #1106
103
+ This happens frequently on heroku-22.
104
+
105
+ # 4.7.0
106
+
107
+ * Support single endpoint architecture with SSL/TLS in cluster mode. See #1086.
108
+ * `zrem` and `zadd` act as noop when provided an empty list of keys. See #1097.
109
+ * Support IPv6 URLs.
110
+ * Add `Redis#with` for better compatibility with `connection_pool` usage.
111
+ * Fix the block form of `multi` called inside `pipelined`. Previously the `MUTLI/EXEC` wouldn't be sent. See #1073.
112
+
113
+ # 4.6.0
114
+
115
+ * Deprecate `Redis.current`.
116
+ * Deprecate calling commands on `Redis` inside `Redis#pipelined`. See #1059.
117
+ ```ruby
118
+ redis.pipelined do
119
+ redis.get("key")
120
+ end
121
+ ```
122
+
123
+ should be replaced by:
124
+
125
+ ```ruby
126
+ redis.pipelined do |pipeline|
127
+ pipeline.get("key")
128
+ end
129
+ ```
130
+ * Deprecate calling commands on `Redis` inside `Redis#multi`. See #1059.
131
+ ```ruby
132
+ redis.multi do
133
+ redis.get("key")
134
+ end
135
+ ```
136
+
137
+ should be replaced by:
138
+
139
+ ```ruby
140
+ redis.multi do |transaction|
141
+ transaction.get("key")
142
+ end
143
+ ```
144
+ * Deprecate `Redis#queue` and `Redis#commit`. See #1059.
145
+
146
+ * Fix `zpopmax` and `zpopmin` when called inside a pipeline. See #1055.
147
+ * `Redis#synchronize` is now private like it should always have been.
148
+
149
+ * Add `Redis.silence_deprecations=` to turn off deprecation warnings.
150
+ If you don't wish to see warnings yet, you can set `Redis.silence_deprecations = true`.
151
+ It is however heavily recommended to fix them instead when possible.
152
+ * Add `Redis.raise_deprecations=` to turn deprecation warnings into errors.
153
+ This makes it easier to identitify the source of deprecated APIs usage.
154
+ It is recommended to set `Redis.raise_deprecations = true` in development and test environments.
155
+ * Add new options to ZRANGE. See #1053.
156
+ * Add ZRANGESTORE command. See #1053.
157
+ * Add SCAN support for `Redis::Cluster`. See #1049.
158
+ * Add COPY command. See #1053. See #1048.
159
+ * Add ZDIFFSTORE command. See #1046.
160
+ * Add ZDIFF command. See #1044.
161
+ * Add ZUNION command. See #1042.
162
+ * Add HRANDFIELD command. See #1040.
163
+
164
+ # 4.5.1
165
+
166
+ * Restore the accidential auth behavior of redis-rb 4.3.0 with a warning. If provided with the `default` user's password, but a wrong username,
167
+ redis-rb will first try to connect as the provided user, but then will fallback to connect as the `default` user with the provided password.
168
+ This behavior is deprecated and will be removed in Redis 4.6.0. Fix #1038.
169
+
170
+ # 4.5.0
171
+
172
+ * Handle parts of the command using incompatible encodings. See #1037.
173
+ * Add GET option to SET command. See #1036.
174
+ * Add ZRANDMEMBER command. See #1035.
175
+ * Add LMOVE/BLMOVE commands. See #1034.
176
+ * Add ZMSCORE command. See #1032.
177
+ * Add LT/GT options to ZADD. See #1033.
178
+ * Add SMISMEMBER command. See #1031.
179
+ * Add EXAT/PXAT options to SET. See #1028.
180
+ * Add GETDEL/GETEX commands. See #1024.
181
+ * `Redis#exists` now returns an Integer by default, as warned since 4.2.0. The old behavior can be restored with `Redis.exists_returns_integer = false`.
182
+ * Fix Redis < 6 detection during connect. See #1025.
183
+ * Fix fetching command details in Redis cluster when the first node is unhealthy. See #1026.
184
+
185
+ # 4.4.0
186
+
187
+ * Redis cluster: fix cross-slot validation in pipelines. Fix ##1019.
188
+ * Add support for `XAUTOCLAIM`. See #1018.
189
+ * Properly issue `READONLY` when reconnecting to replicas. Fix #1017.
190
+ * Make `del` a noop if passed an empty list of keys. See #998.
191
+ * Add support for `ZINTER`. See #995.
192
+
3
193
  # 4.3.1
4
194
 
5
195
  * Fix password authentication against redis server 5 and older.
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
- # redis-rb [![Build Status][gh-actions-image]][gh-actions-link] [![Inline docs][inchpages-image]][inchpages-link]
1
+ # redis-rb [![Build Status][gh-actions-image]][gh-actions-link] [![Inline docs][rdoc-master-image]][rdoc-master-link]
2
2
 
3
- A Ruby client that tries to match [Redis][redis-home]' API one-to-one, while still
4
- providing an idiomatic interface.
3
+ A Ruby client that tries to match [Redis][redis-home]' API one-to-one, while still providing an idiomatic interface.
5
4
 
6
5
  See [RubyDoc.info][rubydoc] for the API docs of the latest published gem.
7
6
 
@@ -35,13 +34,9 @@ You can also specify connection options as a [`redis://` URL][redis-url]:
35
34
  redis = Redis.new(url: "redis://:p4ssw0rd@10.0.1.1:6380/15")
36
35
  ```
37
36
 
38
- The client expects passwords with special chracters to be URL-encoded (i.e.
37
+ The client expects passwords with special characters to be URL-encoded (i.e.
39
38
  `CGI.escape(password)`).
40
39
 
41
- By default, the client will try to read the `REDIS_URL` environment variable
42
- and use that as URL to connect to. The above statement is therefore equivalent
43
- to setting this environment variable and calling `Redis.new` without arguments.
44
-
45
40
  To connect to Redis listening on a Unix socket, try:
46
41
 
47
42
  ```ruby
@@ -76,6 +71,26 @@ redis.get("mykey")
76
71
  All commands, their arguments, and return values are documented and
77
72
  available on [RubyDoc.info][rubydoc].
78
73
 
74
+ ## Connection Pooling and Thread safety
75
+
76
+ The client does not provide connection pooling. Each `Redis` instance
77
+ has one and only one connection to the server, and use of this connection
78
+ is protected by a mutex.
79
+
80
+ As such it is heavily recommended to use the [`connection_pool` gem](https://github.com/mperham/connection_pool), e.g.:
81
+
82
+ ```ruby
83
+ module MyApp
84
+ def self.redis
85
+ @redis ||= ConnectionPool::Wrapper.new do
86
+ Redis.new(url: ENV["REDIS_URL"])
87
+ end
88
+ end
89
+ end
90
+
91
+ MyApp.redis.incr("some-counter")
92
+ ```
93
+
79
94
  ## Sentinel support
80
95
 
81
96
  The client is able to perform automatic failover by using [Redis
@@ -88,7 +103,7 @@ To connect using Sentinel, use:
88
103
  SENTINELS = [{ host: "127.0.0.1", port: 26380 },
89
104
  { host: "127.0.0.1", port: 26381 }]
90
105
 
91
- redis = Redis.new(url: "redis://mymaster", sentinels: SENTINELS, role: :master)
106
+ redis = Redis.new(name: "mymaster", sentinels: SENTINELS, role: :master)
92
107
  ```
93
108
 
94
109
  * The master name identifies a group of Redis instances composed of a master
@@ -105,70 +120,44 @@ but a few so that if one is down the client will try the next one. The client
105
120
  is able to remember the last Sentinel that was able to reply correctly and will
106
121
  use it for the next requests.
107
122
 
108
- If you want to [authenticate](https://redis.io/topics/sentinel#configuring-sentinel-instances-with-authentication) Sentinel itself, you must specify the `password` option per instance.
123
+ To [authenticate](https://redis.io/docs/management/sentinel/#configuring-sentinel-instances-with-authentication) Sentinel itself, you can specify the `sentinel_username` and `sentinel_password`. Exclude the `sentinel_username` option if you're using password-only authentication.
109
124
 
110
125
  ```ruby
111
- SENTINELS = [{ host: '127.0.0.1', port: 26380, password: 'mysecret' },
112
- { host: '127.0.0.1', port: 26381, password: 'mysecret' }]
126
+ SENTINELS = [{ host: '127.0.0.1', port: 26380},
127
+ { host: '127.0.0.1', port: 26381}]
113
128
 
114
- redis = Redis.new(host: 'mymaster', sentinels: SENTINELS, role: :master)
129
+ redis = Redis.new(name: 'mymaster', sentinels: SENTINELS, sentinel_username: 'appuser', sentinel_password: 'mysecret', role: :master)
115
130
  ```
116
131
 
117
- ## Cluster support
118
-
119
- `redis-rb` supports [clustering](https://redis.io/topics/cluster-spec).
132
+ If you specify a username and/or password at the top level for your main Redis instance, Sentinel *will not* using thouse credentials
120
133
 
121
134
  ```ruby
122
- # Nodes can be passed to the client as an array of connection URLs.
123
- nodes = (7000..7005).map { |port| "redis://127.0.0.1:#{port}" }
124
- redis = Redis.new(cluster: nodes)
135
+ # Use 'mysecret' to authenticate against the mymaster instance, but skip authentication for the sentinels:
136
+ SENTINELS = [{ host: '127.0.0.1', port: 26380 },
137
+ { host: '127.0.0.1', port: 26381 }]
125
138
 
126
- # You can also specify the options as a Hash. The options are the same as for a single server connection.
127
- (7000..7005).map { |port| { host: '127.0.0.1', port: port } }
139
+ redis = Redis.new(name: 'mymaster', sentinels: SENTINELS, role: :master, password: 'mysecret')
128
140
  ```
129
141
 
130
- You can also specify only a subset of the nodes, and the client will discover the missing ones using the [CLUSTER NODES](https://redis.io/commands/cluster-nodes) command.
142
+ So you have to provide Sentinel credential and Redis explicitly even they are the same
131
143
 
132
144
  ```ruby
133
- Redis.new(cluster: %w[redis://127.0.0.1:7000])
134
- ```
135
-
136
- If you want [the connection to be able to read from any replica](https://redis.io/commands/readonly), you must pass the `replica: true`. Note that this connection won't be usable to write keys.
145
+ # Use 'mysecret' to authenticate against the mymaster instance and sentinel
146
+ SENTINELS = [{ host: '127.0.0.1', port: 26380 },
147
+ { host: '127.0.0.1', port: 26381 }]
137
148
 
138
- ```ruby
139
- Redis.new(cluster: nodes, replica: true)
149
+ redis = Redis.new(name: 'mymaster', sentinels: SENTINELS, role: :master, password: 'mysecret', sentinel_password: 'mysecret')
140
150
  ```
141
151
 
142
- The calling code is responsible for [avoiding cross slot commands](https://redis.io/topics/cluster-spec#keys-distribution-model).
152
+ Also the `name`, `password`, `username` and `db` for Redis instance can be passed as an url:
143
153
 
144
154
  ```ruby
145
- redis = Redis.new(cluster: %w[redis://127.0.0.1:7000])
146
-
147
- redis.mget('key1', 'key2')
148
- #=> Redis::CommandError (CROSSSLOT Keys in request don't hash to the same slot)
149
-
150
- redis.mget('{key}1', '{key}2')
151
- #=> [nil, nil]
155
+ redis = Redis.new(url: "redis://appuser:mysecret@mymaster/10", sentinels: SENTINELS, role: :master)
152
156
  ```
153
157
 
154
- * The client automatically reconnects after a failover occurred, but the caller is responsible for handling errors while it is happening.
155
- * The client support permanent node failures, and will reroute requests to promoted slaves.
156
- * The client supports `MOVED` and `ASK` redirections transparently.
157
-
158
- ## Storing objects
159
-
160
- Redis "string" types can be used to store serialized Ruby objects, for
161
- example with JSON:
162
-
163
- ```ruby
164
- require "json"
165
-
166
- redis.set "foo", [1, 2, 3].to_json
167
- # => OK
158
+ ## Cluster support
168
159
 
169
- JSON.parse(redis.get("foo"))
170
- # => [1, 2, 3]
171
- ```
160
+ [Clustering](https://redis.io/topics/cluster-spec). is supported via the [`redis-clustering` gem](cluster/).
172
161
 
173
162
  ## Pipelining
174
163
 
@@ -184,13 +173,46 @@ commands to Redis and gathers their replies. These replies are returned
184
173
  by the `#pipelined` method.
185
174
 
186
175
  ```ruby
187
- redis.pipelined do
188
- redis.set "foo", "bar"
189
- redis.incr "baz"
176
+ redis.pipelined do |pipeline|
177
+ pipeline.set "foo", "bar"
178
+ pipeline.incr "baz"
190
179
  end
191
180
  # => ["OK", 1]
192
181
  ```
193
182
 
183
+ Commands must be called on the yielded objects. If you call methods
184
+ on the original client objects from inside a pipeline, they will be sent immediately:
185
+
186
+ ```ruby
187
+ redis.pipelined do |pipeline|
188
+ pipeline.set "foo", "bar"
189
+ redis.incr "baz" # => 1
190
+ end
191
+ # => ["OK"]
192
+ ```
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
@@ -200,9 +222,9 @@ the regular pipeline, the replies to the commands are returned by the
200
222
  `#multi` method.
201
223
 
202
224
  ```ruby
203
- redis.multi do
204
- redis.set "foo", "bar"
205
- redis.incr "baz"
225
+ redis.multi do |transaction|
226
+ transaction.set "foo", "bar"
227
+ transaction.incr "baz"
206
228
  end
207
229
  # => ["OK", 1]
208
230
  ```
@@ -210,21 +232,22 @@ end
210
232
  ### Futures
211
233
 
212
234
  Replies to commands in a pipeline can be accessed via the *futures* they
213
- emit (since redis-rb 3.0). All calls inside a pipeline block return a
235
+ emit. All calls on the pipeline object return a
214
236
  `Future` object, which responds to the `#value` method. When the
215
237
  pipeline has successfully executed, all futures are assigned their
216
238
  respective replies and can be used.
217
239
 
218
240
  ```ruby
219
- redis.pipelined do
220
- @set = redis.set "foo", "bar"
221
- @incr = redis.incr "baz"
241
+ set = incr = nil
242
+ redis.pipelined do |pipeline|
243
+ set = pipeline.set "foo", "bar"
244
+ incr = pipeline.incr "baz"
222
245
  end
223
246
 
224
- @set.value
247
+ set.value
225
248
  # => "OK"
226
249
 
227
- @incr.value
250
+ incr.value
228
251
  # => 1
229
252
  ```
230
253
 
@@ -236,7 +259,7 @@ it can't connect to the server a `Redis::CannotConnectError` error will be raise
236
259
  ```ruby
237
260
  begin
238
261
  redis.ping
239
- rescue StandardError => e
262
+ rescue Redis::BaseError => e
240
263
  e.inspect
241
264
  # => #<Redis::CannotConnectError: Timed out connecting to Redis on 10.0.1.1:6380>
242
265
 
@@ -250,6 +273,7 @@ See lib/redis/errors.rb for information about what exceptions are possible.
250
273
  ## Timeouts
251
274
 
252
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.
253
277
  Passing a single `timeout` option will set all three values:
254
278
 
255
279
  ```ruby
@@ -283,55 +307,37 @@ If no message is received after 5 seconds, the client will unsubscribe.
283
307
 
284
308
  ## Reconnections
285
309
 
286
- The client allows you to configure how many `reconnect_attempts` it should
287
- complete before declaring a connection as failed. Furthermore, you may want
288
- to control the maximum duration between reconnection attempts with
289
- `reconnect_delay` and `reconnect_delay_max`.
310
+ **By default**, this gem will only **retry a connection once** and then fail, but
311
+ the client allows you to configure how many `reconnect_attempts` it should
312
+ complete before declaring a connection as failed.
290
313
 
291
314
  ```ruby
292
- Redis.new(
293
- :reconnect_attempts => 10,
294
- :reconnect_delay => 1.5,
295
- :reconnect_delay_max => 10.0,
296
- )
315
+ Redis.new(reconnect_attempts: 0)
316
+ Redis.new(reconnect_attempts: 3)
297
317
  ```
298
318
 
299
- The delay values are specified in seconds. With the above configuration, the
300
- client would attempt 10 reconnections, exponentially increasing the duration
301
- between each attempt but it never waits longer than `reconnect_delay_max`.
302
-
303
- This is the retry algorithm:
319
+ If you wish to wait between reconnection attempts, you can instead pass a list
320
+ of durations:
304
321
 
305
322
  ```ruby
306
- attempt_wait_time = [(reconnect_delay * 2**(attempt-1)), reconnect_delay_max].min
323
+ Redis.new(reconnect_attempts: [
324
+ 0, # retry immediately
325
+ 0.25, # retry a second time after 250ms
326
+ 1, # retry a third and final time after another 1s
327
+ ])
307
328
  ```
308
329
 
309
- **By default**, this gem will only **retry a connection once** and then fail, but with the
310
- above configuration the reconnection attempt would look like this:
311
-
312
- #|Attempt wait time|Total wait time
313
- :-:|:-:|:-:
314
- 1|1.5s|1.5s
315
- 2|3.0s|4.5s
316
- 3|6.0s|10.5s
317
- 4|10.0s|20.5s
318
- 5|10.0s|30.5s
319
- 6|10.0s|40.5s
320
- 7|10.0s|50.5s
321
- 8|10.0s|60.5s
322
- 9|10.0s|70.5s
323
- 10|10.0s|80.5s
324
-
325
- So if the reconnection attempt #10 succeeds 70 seconds have elapsed trying
326
- to reconnect, this is likely fine in long-running background processes, but if
327
- you use Redis to drive your website you might want to have a lower
328
- `reconnect_delay_max` or have less `reconnect_attempts`.
330
+ If you wish to disable reconnection only for some commands, you can use
331
+ `disable_reconnection`:
329
332
 
330
- ## SSL/TLS Support
333
+ ```ruby
334
+ redis.get("some-key") # this may be retried
335
+ redis.disable_reconnection do
336
+ redis.incr("some-counter") # this won't be retried.
337
+ end
338
+ ```
331
339
 
332
- This library supports natively terminating client side SSL/TLS connections
333
- when talking to Redis via a server-side proxy such as [stunnel], [hitch],
334
- or [ghostunnel].
340
+ ## SSL/TLS Support
335
341
 
336
342
  To enable SSL support, pass the `:ssl => true` option when configuring the
337
343
  Redis client, or pass in `:url => "rediss://..."` (like HTTPS for Redis).
@@ -366,13 +372,7 @@ redis = Redis.new(
366
372
  )
367
373
  ```
368
374
 
369
- [stunnel]: https://www.stunnel.org/
370
- [hitch]: https://hitch-tls.org/
371
- [ghostunnel]: https://github.com/square/ghostunnel
372
- [OpenSSL::SSL::SSLContext documentation]: http://ruby-doc.org/stdlib-2.3.0/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html
373
-
374
- *NOTE:* SSL is only supported by the default "Ruby" driver
375
-
375
+ [OpenSSL::SSL::SSLContext documentation]: http://ruby-doc.org/stdlib-2.5.0/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html
376
376
 
377
377
  ## Expert-Mode Options
378
378
 
@@ -386,17 +386,9 @@ redis = Redis.new(
386
386
  Improper use of `inherit_socket` will result in corrupted and/or incorrect
387
387
  responses.
388
388
 
389
- ## Alternate drivers
389
+ ## hiredis binding
390
390
 
391
391
  By default, redis-rb uses Ruby's socket library to talk with Redis.
392
- To use an alternative connection driver it should be specified as option
393
- when instantiating the client object. These instructions are only valid
394
- for **redis-rb 3.0**. For instructions on how to use alternate drivers from
395
- **redis-rb 2.2**, please refer to an [older README][readme-2.2.2].
396
-
397
- [readme-2.2.2]: https://github.com/redis/redis-rb/blob/v2.2.2/README.md
398
-
399
- ### hiredis
400
392
 
401
393
  The hiredis driver uses the connection facility of hiredis-rb. In turn,
402
394
  hiredis-rb is a binding to the official hiredis client library. It
@@ -406,41 +398,27 @@ extension, JRuby is not supported (by default).
406
398
  It is best to use hiredis when you have large replies (for example:
407
399
  `LRANGE`, `SMEMBERS`, `ZRANGE`, etc.) and/or use big pipelines.
408
400
 
409
- In your Gemfile, include hiredis:
401
+ In your Gemfile, include `hiredis-client`:
410
402
 
411
403
  ```ruby
412
- gem "redis", "~> 3.0.1"
413
- gem "hiredis", "~> 0.4.5"
404
+ gem "redis"
405
+ gem "hiredis-client"
414
406
  ```
415
407
 
416
- When instantiating the client object, specify hiredis:
408
+ If your application doesn't call `Bundler.require`, you may have
409
+ to require it explicitly:
417
410
 
418
411
  ```ruby
419
- redis = Redis.new(:driver => :hiredis)
420
- ```
421
-
422
- ### synchrony
423
-
424
- The synchrony driver adds support for [em-synchrony][em-synchrony].
425
- This makes redis-rb work with EventMachine's asynchronous I/O, while not
426
- changing the exposed API. The hiredis gem needs to be available as
427
- well, because the synchrony driver uses hiredis for parsing the Redis
428
- protocol.
429
-
430
- [em-synchrony]: https://github.com/igrigorik/em-synchrony
412
+ require "hiredis-client"
413
+ ````
431
414
 
432
- In your Gemfile, include em-synchrony and hiredis:
433
-
434
- ```ruby
435
- gem "redis", "~> 3.0.1"
436
- gem "hiredis", "~> 0.4.5"
437
- gem "em-synchrony"
438
- ```
415
+ This makes the hiredis driver the default.
439
416
 
440
- When instantiating the client object, specify synchrony:
417
+ If you want to be certain hiredis is being used, when instantiating
418
+ the client object, specify hiredis:
441
419
 
442
420
  ```ruby
443
- redis = Redis.new(:driver => :synchrony)
421
+ redis = Redis.new(driver: :hiredis)
444
422
  ```
445
423
 
446
424
  ## Testing
@@ -465,11 +443,11 @@ client and evangelized Redis in Rubyland. Thank you, Ezra.
465
443
  requests.
466
444
 
467
445
 
468
- [inchpages-image]: https://inch-ci.org/github/redis/redis-rb.svg
469
- [inchpages-link]: https://inch-ci.org/github/redis/redis-rb
470
- [redis-commands]: https://redis.io/commands
471
- [redis-home]: https://redis.io
472
- [redis-url]: http://www.iana.org/assignments/uri-schemes/prov/redis
473
- [gh-actions-image]: https://github.com/redis/redis-rb/workflows/Test/badge.svg
474
- [gh-actions-link]: https://github.com/redis/redis-rb/actions
475
- [rubydoc]: http://www.rubydoc.info/gems/redis
446
+ [rdoc-master-image]: https://img.shields.io/badge/docs-rdoc.info-blue.svg
447
+ [rdoc-master-link]: https://rubydoc.info/github/redis/redis-rb
448
+ [redis-commands]: https://redis.io/commands
449
+ [redis-home]: https://redis.io
450
+ [redis-url]: https://www.iana.org/assignments/uri-schemes/prov/redis
451
+ [gh-actions-image]: https://github.com/redis/redis-rb/workflows/Test/badge.svg
452
+ [gh-actions-link]: https://github.com/redis/redis-rb/actions
453
+ [rubydoc]: https://rubydoc.info/gems/redis