154
154
# => ["OK", 1]
155
155
```
156
156
157
+ Commands must be called on the yielded objects. If you call methods
158
+ on the original client objects from inside a pipeline, they willb e sent immediately:
159
+
160
+ ``` ruby
161
+ redis.pipelined do |pipeline |
162
+ pipeline.set " foo" , " bar"
163
+ redis.incr " baz" # => 1
164
+ end
165
+ # => ["OK"]
166
+ ```
167
+
157
168
### Executing commands atomically
158
169
159
170
You can use ` MULTI/EXEC ` to run a number of commands in an atomic
173
184
### Futures
174
185
175
186
Replies to commands in a pipeline can be accessed via the * futures* they
176
- emit (since redis-rb 3.0) . All calls on the pipeline object return a
187
+ emit. All calls on the pipeline object return a
177
188
` Future ` object, which responds to the ` #value ` method. When the
178
189
pipeline has successfully executed, all futures are assigned their
179
190
respective replies and can be used.
@@ -199,7 +210,7 @@ it can't connect to the server a `Redis::CannotConnectError` error will be raise
199
210
``` ruby
200
211
begin
201
212
redis.ping
202
- rescue StandardError => e
213
+ rescue Redis :: BaseError => e
203
214
e.inspect
204
215
# => #<Redis::CannotConnectError: Timed out connecting to Redis on 10.0.1.1:6380>
205
216
@@ -246,56 +257,28 @@ If no message is received after 5 seconds, the client will unsubscribe.
246
257
247
258
## Reconnections
248
259
249
- The client allows you to configure how many ` reconnect_attempts ` it should
250
- complete before declaring a connection as failed. Furthermore, you may want
251
- to control the maximum duration between reconnection attempts with
252
- ` reconnect_delay ` and ` reconnect_delay_max ` .
260
+ ** By default** , this gem will only ** retry a connection once** and then fail, but
261
+ the client allows you to configure how many ` reconnect_attempts ` it should
262
+ complete before declaring a connection as failed.
253
263
254
264
``` ruby
255
- Redis .new (
256
- :reconnect_attempts => 10 ,
257
- :reconnect_delay => 1.5 ,
258
- :reconnect_delay_max => 10.0 ,
259
- )
265
+ Redis .new (reconnect_attempts: 0 )
266
+ Redis .new (reconnect_attempts: 3 )
260
267
```
261
268
262
- The delay values are specified in seconds. With the above configuration, the
263
- client would attempt 10 reconnections, exponentially increasing the duration
264
- between each attempt but it never waits longer than ` reconnect_delay_max ` .
265
-
266
- This is the retry algorithm:
269
+ If you wish to wait between reconnection attempts, you can instead pass a list
270
+ of durations:
267
271
268
272
``` ruby
269
- attempt_wait_time = [(reconnect_delay * 2 ** (attempt- 1 )), reconnect_delay_max].min
273
+ Redis .new (reconnect_attempts: [
274
+ 0 , # retry immediately
275
+ 0.25 # retry a second time after 250ms
276
+ 1 # retry a third and final time after another 1s
277
+ ])
270
278
```
271
279
272
- ** By default** , this gem will only ** retry a connection once** and then fail, but with the
273
- above configuration the reconnection attempt would look like this:
274
-
275
- #|Attempt wait time|Total wait time
276
- :-:|:-:|:-:
277
- 1|1.5s|1.5s
278
- 2|3.0s|4.5s
279
- 3|6.0s|10.5s
280
- 4|10.0s|20.5s
281
- 5|10.0s|30.5s
282
- 6|10.0s|40.5s
283
- 7|10.0s|50.5s
284
- 8|10.0s|60.5s
285
- 9|10.0s|70.5s
286
- 10|10.0s|80.5s
287
-
288
- So if the reconnection attempt #10 succeeds 70 seconds have elapsed trying
289
- to reconnect, this is likely fine in long-running background processes, but if
290
- you use Redis to drive your website you might want to have a lower
291
- ` reconnect_delay_max ` or have less ` reconnect_attempts ` .
292
-
293
280
## SSL/TLS Support
294
281
295
- This library supports natively terminating client side SSL/TLS connections
296
- when talking to Redis via a server-side proxy such as [ stunnel] , [ hitch] ,
297
- or [ ghostunnel] .
298
-
299
282
To enable SSL support, pass the ` :ssl => true ` option when configuring the
300
283
Redis client, or pass in ` :url => "rediss://..." ` (like HTTPS for Redis).
301
284
You will also need to pass in an ` :ssl_params => { ... } ` hash used to
@@ -349,17 +332,9 @@ redis = Redis.new(
349
332
Improper use of ` inherit_socket ` will result in corrupted and/or incorrect
350
333
responses.
351
334
352
- ## Alternate drivers
335
+ ## hiredis binding
353
336
354
337
By default, redis-rb uses Ruby's socket library to talk with Redis.
355
- To use an alternative connection driver it should be specified as option
356
- when instantiating the client object. These instructions are only valid
357
- for ** redis-rb 3.0** . For instructions on how to use alternate drivers from
358
- ** redis-rb 2.2** , please refer to an [ older README] [ readme-2.2.2 ] .
359
-
360
- [ readme-2.2.2 ] : https://github.com/redis/redis-rb/blob/v2.2.2/README.md
361
-
362
- ### hiredis
363
338
364
339
The hiredis driver uses the connection facility of hiredis-rb. In turn,
365
340
hiredis-rb is a binding to the official hiredis client library. It
@@ -369,17 +344,17 @@ extension, JRuby is not supported (by default).
369
344
It is best to use hiredis when you have large replies (for example:
370
345
` LRANGE ` , ` SMEMBERS ` , ` ZRANGE ` , etc.) and/or use big pipelines.
371
346
372
- In your Gemfile, include hiredis:
347
+ In your Gemfile, include ` hiredis-client ` :
373
348
374
349
``` ruby
375
- gem " redis" , " ~> 3.0.1 "
376
- gem " hiredis" , " ~> 0.4.5 "
350
+ gem " redis"
351
+ gem " hiredis-client "
377
352
```
378
353
379
354
When instantiating the client object, specify hiredis:
380
355
381
356
``` ruby
382
- redis = Redis .new (: driver => :hiredis )
357
+ redis = Redis .new (driver: :hiredis )
383
358
```
384
359
385
360
## Testing
0 commit comments