Skip to content

Commit 6455441

Browse files
committed
Update README
1 parent c58215c commit 6455441

File tree

3 files changed

+32
-57
lines changed

3 files changed

+32
-57
lines changed

README.md

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ end
154154
# => ["OK", 1]
155155
```
156156

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+
157168
### Executing commands atomically
158169

159170
You can use `MULTI/EXEC` to run a number of commands in an atomic
@@ -173,7 +184,7 @@ end
173184
### Futures
174185

175186
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
177188
`Future` object, which responds to the `#value` method. When the
178189
pipeline has successfully executed, all futures are assigned their
179190
respective replies and can be used.
@@ -199,7 +210,7 @@ it can't connect to the server a `Redis::CannotConnectError` error will be raise
199210
```ruby
200211
begin
201212
redis.ping
202-
rescue StandardError => e
213+
rescue Redis::BaseError => e
203214
e.inspect
204215
# => #<Redis::CannotConnectError: Timed out connecting to Redis on 10.0.1.1:6380>
205216

@@ -246,56 +257,28 @@ If no message is received after 5 seconds, the client will unsubscribe.
246257

247258
## Reconnections
248259

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.
253263

254264
```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)
260267
```
261268

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:
267271

268272
```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+
])
270278
```
271279

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-
293280
## SSL/TLS Support
294281

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-
299282
To enable SSL support, pass the `:ssl => true` option when configuring the
300283
Redis client, or pass in `:url => "rediss://..."` (like HTTPS for Redis).
301284
You will also need to pass in an `:ssl_params => { ... }` hash used to
@@ -349,17 +332,9 @@ redis = Redis.new(
349332
Improper use of `inherit_socket` will result in corrupted and/or incorrect
350333
responses.
351334

352-
## Alternate drivers
335+
## hiredis binding
353336

354337
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
363338

364339
The hiredis driver uses the connection facility of hiredis-rb. In turn,
365340
hiredis-rb is a binding to the official hiredis client library. It
@@ -369,17 +344,17 @@ extension, JRuby is not supported (by default).
369344
It is best to use hiredis when you have large replies (for example:
370345
`LRANGE`, `SMEMBERS`, `ZRANGE`, etc.) and/or use big pipelines.
371346

372-
In your Gemfile, include hiredis:
347+
In your Gemfile, include `hiredis-client`:
373348

374349
```ruby
375-
gem "redis", "~> 3.0.1"
376-
gem "hiredis", "~> 0.4.5"
350+
gem "redis"
351+
gem "hiredis-client"
377352
```
378353

379354
When instantiating the client object, specify hiredis:
380355

381356
```ruby
382-
redis = Redis.new(:driver => :hiredis)
357+
redis = Redis.new(driver: :hiredis)
383358
```
384359

385360
## Testing

lib/redis/errors.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class Redis
44
# Base error for all redis-rb errors.
5-
class BaseError < RuntimeError
5+
class BaseError < StandardError
66
end
77

88
# Raised by the connection when a protocol error occurs.

lib/redis/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
class Redis
4-
VERSION = '4.7.1'
4+
VERSION = '5.0.0.alpha1'
55
end

0 commit comments

Comments
 (0)