redis 4.2.5 → 5.0.7
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +167 -0
- data/README.md +102 -162
- data/lib/redis/client.rb +84 -589
- data/lib/redis/commands/bitmaps.rb +66 -0
- data/lib/redis/commands/cluster.rb +28 -0
- data/lib/redis/commands/connection.rb +53 -0
- data/lib/redis/commands/geo.rb +84 -0
- data/lib/redis/commands/hashes.rb +254 -0
- data/lib/redis/commands/hyper_log_log.rb +37 -0
- data/lib/redis/commands/keys.rb +437 -0
- data/lib/redis/commands/lists.rb +339 -0
- data/lib/redis/commands/pubsub.rb +54 -0
- data/lib/redis/commands/scripting.rb +114 -0
- data/lib/redis/commands/server.rb +188 -0
- data/lib/redis/commands/sets.rb +214 -0
- data/lib/redis/commands/sorted_sets.rb +884 -0
- data/lib/redis/commands/streams.rb +402 -0
- data/lib/redis/commands/strings.rb +314 -0
- data/lib/redis/commands/transactions.rb +115 -0
- data/lib/redis/commands.rb +237 -0
- data/lib/redis/distributed.rb +220 -75
- data/lib/redis/errors.rb +15 -41
- data/lib/redis/hash_ring.rb +26 -26
- data/lib/redis/pipeline.rb +66 -120
- data/lib/redis/subscribe.rb +23 -15
- data/lib/redis/version.rb +1 -1
- data/lib/redis.rb +110 -3441
- metadata +27 -54
- data/lib/redis/cluster/command.rb +0 -81
- data/lib/redis/cluster/command_loader.rb +0 -34
- data/lib/redis/cluster/key_slot_converter.rb +0 -72
- data/lib/redis/cluster/node.rb +0 -107
- data/lib/redis/cluster/node_key.rb +0 -31
- data/lib/redis/cluster/node_loader.rb +0 -37
- data/lib/redis/cluster/option.rb +0 -90
- data/lib/redis/cluster/slot.rb +0 -86
- data/lib/redis/cluster/slot_loader.rb +0 -49
- data/lib/redis/cluster.rb +0 -295
- data/lib/redis/connection/command_helper.rb +0 -39
- data/lib/redis/connection/hiredis.rb +0 -67
- data/lib/redis/connection/registry.rb +0 -13
- data/lib/redis/connection/ruby.rb +0 -427
- data/lib/redis/connection/synchrony.rb +0 -146
- data/lib/redis/connection.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dde5fad5c2d0c73c390528b059ab36b185dd61a2c32e4f9be9512bb4516977b
|
4
|
+
data.tar.gz: cda581f3f9b0b4238f15b4b3ddf7566fb6ca02b60ee7951b903e8e195bd395cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 122fd647eda1a251370f32dfefb4711411b0ff9b0e9185cdb871c389c99d5b80a80d554a6b7787ed10e515291b1ebed6dceb2364f8c28021ce6fdedd3297d08e
|
7
|
+
data.tar.gz: 13aadc0709a9fc7779ad7ad1f64bb3d3b26da57eb44dd2ebd629d5ed2d34ea17c782337ce92e1047e7ae736df8b90eafb2e935e460f1b1af979621942dad772f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,172 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# 5.0.7
|
4
|
+
|
5
|
+
- Fix compatibility with `redis-client 0.15.0` when using Redis Sentinel. Fix #1209.
|
6
|
+
|
7
|
+
# 5.0.6
|
8
|
+
|
9
|
+
- Wait for an extra `config.read_timeout` in blocking commands rather than an arbitrary 100ms. See #1175.
|
10
|
+
- Treat ReadOnlyError as ConnectionError. See #1168.
|
11
|
+
|
12
|
+
# 5.0.5
|
13
|
+
|
14
|
+
- Fix automatic disconnection when the process was forked. See #1157.
|
15
|
+
|
16
|
+
# 5.0.4
|
17
|
+
|
18
|
+
- Cast `ttl` argument to integer in `expire`, `setex` and a few others.
|
19
|
+
|
20
|
+
# 5.0.3
|
21
|
+
|
22
|
+
- Add `OutOfMemoryError` as a subclass of `CommandError`
|
23
|
+
|
24
|
+
# 5.0.2
|
25
|
+
|
26
|
+
- Fix `Redis#close` to properly reset the fork protection check.
|
27
|
+
|
28
|
+
# 5.0.1
|
29
|
+
|
30
|
+
- Added a fake `Redis::Connections.drivers` method to be compatible with older sidekiq versions.
|
31
|
+
|
32
|
+
# 5.0.0
|
33
|
+
|
34
|
+
- Default client timeout decreased from 5 seconds to 1 second.
|
35
|
+
- Eagerly and strictly cast Integer and Float parameters.
|
36
|
+
- Allow to call `subscribe`, `unsubscribe`, `psubscribe` and `punsubscribe` from a subscribed client. See #1131.
|
37
|
+
- Use `MD5` for hashing server nodes in `Redis::Distributed`. This should improve keys distribution among servers. See #1089.
|
38
|
+
- Changed `sadd` and `srem` to now always return an Integer.
|
39
|
+
- Added `sadd?` and `srem?` which always return a Boolean.
|
40
|
+
- Added support for `IDLE` paramter in `xpending`.
|
41
|
+
- Cluster support has been moved to a `redis-clustering` companion gem.
|
42
|
+
- `select` no longer record the current database. If the client has to reconnect after `select` was used, it will reconnect to the original database.
|
43
|
+
- Better support Float timeout in blocking commands. See #977.
|
44
|
+
- `Redis.new` will now raise an error if provided unknown options.
|
45
|
+
- Removed positional timeout in blocking commands (`BLPOP`, etc). Timeout now must be passed as an option: `r.blpop("key", timeout: 2.5)`
|
46
|
+
- Removed `logger` option.
|
47
|
+
- Removed `reconnect_delay_max` and `reconnect_delay`, you can pass precise sleep durations to `reconnect_attempts` instead.
|
48
|
+
- Require Ruby 2.5+.
|
49
|
+
- Removed the deprecated `queue` and `commit` methods. Use `pipelined` instead.
|
50
|
+
- Removed the deprecated `Redis::Future#==`.
|
51
|
+
- Removed the deprecated `pipelined` and `multi` signature. Commands now MUST be called on the block argument, not the original redis instance.
|
52
|
+
- Removed `Redis.current`. You shouldn't assume there is a single global Redis connection, use a connection pool instead,
|
53
|
+
and libaries using Redis should accept a Redis instance (or connection pool) as a config. E.g. `MyLibrary.redis = Redis.new(...)`.
|
54
|
+
- Removed the `synchrony` driver.
|
55
|
+
- Removed `Redis.exists_returns_integer`, it's now always enabled.
|
56
|
+
|
57
|
+
# 4.8.1
|
58
|
+
|
59
|
+
* Automatically reconnect after fork regardless of `reconnect_attempts`
|
60
|
+
|
61
|
+
# 4.8.0
|
62
|
+
|
63
|
+
* Introduce `sadd?` and `srem?` as boolean returning versions of `sadd` and `srem`.
|
64
|
+
* Deprecate `sadd` and `srem` returning a boolean when called with a single argument.
|
65
|
+
To enable the redis 5.0 behavior you can set `Redis.sadd_returns_boolean = false`.
|
66
|
+
* Deprecate passing `timeout` as a positional argument in blocking commands (`brpop`, `blop`, etc).
|
67
|
+
|
68
|
+
# 4.7.1
|
69
|
+
|
70
|
+
* Gracefully handle OpenSSL 3.0 EOF Errors (`OpenSSL::SSL::SSLError: SSL_read: unexpected eof while reading`). See #1106
|
71
|
+
This happens frequently on heroku-22.
|
72
|
+
|
73
|
+
# 4.7.0
|
74
|
+
|
75
|
+
* Support single endpoint architecture with SSL/TLS in cluster mode. See #1086.
|
76
|
+
* `zrem` and `zadd` act as noop when provided an empty list of keys. See #1097.
|
77
|
+
* Support IPv6 URLs.
|
78
|
+
* Add `Redis#with` for better compatibility with `connection_pool` usage.
|
79
|
+
* Fix the block form of `multi` called inside `pipelined`. Previously the `MUTLI/EXEC` wouldn't be sent. See #1073.
|
80
|
+
|
81
|
+
# 4.6.0
|
82
|
+
|
83
|
+
* Deprecate `Redis.current`.
|
84
|
+
* Deprecate calling commands on `Redis` inside `Redis#pipelined`. See #1059.
|
85
|
+
```ruby
|
86
|
+
redis.pipelined do
|
87
|
+
redis.get("key")
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
should be replaced by:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
redis.pipelined do |pipeline|
|
95
|
+
pipeline.get("key")
|
96
|
+
end
|
97
|
+
```
|
98
|
+
* Deprecate calling commands on `Redis` inside `Redis#multi`. See #1059.
|
99
|
+
```ruby
|
100
|
+
redis.multi do
|
101
|
+
redis.get("key")
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
should be replaced by:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
redis.multi do |transaction|
|
109
|
+
transaction.get("key")
|
110
|
+
end
|
111
|
+
```
|
112
|
+
* Deprecate `Redis#queue` and `Redis#commit`. See #1059.
|
113
|
+
|
114
|
+
* Fix `zpopmax` and `zpopmin` when called inside a pipeline. See #1055.
|
115
|
+
* `Redis#synchronize` is now private like it should always have been.
|
116
|
+
|
117
|
+
* Add `Redis.silence_deprecations=` to turn off deprecation warnings.
|
118
|
+
If you don't wish to see warnings yet, you can set `Redis.silence_deprecations = true`.
|
119
|
+
It is however heavily recommended to fix them instead when possible.
|
120
|
+
* Add `Redis.raise_deprecations=` to turn deprecation warnings into errors.
|
121
|
+
This makes it easier to identitify the source of deprecated APIs usage.
|
122
|
+
It is recommended to set `Redis.raise_deprecations = true` in development and test environments.
|
123
|
+
* Add new options to ZRANGE. See #1053.
|
124
|
+
* Add ZRANGESTORE command. See #1053.
|
125
|
+
* Add SCAN support for `Redis::Cluster`. See #1049.
|
126
|
+
* Add COPY command. See #1053. See #1048.
|
127
|
+
* Add ZDIFFSTORE command. See #1046.
|
128
|
+
* Add ZDIFF command. See #1044.
|
129
|
+
* Add ZUNION command. See #1042.
|
130
|
+
* Add HRANDFIELD command. See #1040.
|
131
|
+
|
132
|
+
# 4.5.1
|
133
|
+
|
134
|
+
* 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,
|
135
|
+
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.
|
136
|
+
This behavior is deprecated and will be removed in Redis 4.6.0. Fix #1038.
|
137
|
+
|
138
|
+
# 4.5.0
|
139
|
+
|
140
|
+
* Handle parts of the command using incompatible encodings. See #1037.
|
141
|
+
* Add GET option to SET command. See #1036.
|
142
|
+
* Add ZRANDMEMBER command. See #1035.
|
143
|
+
* Add LMOVE/BLMOVE commands. See #1034.
|
144
|
+
* Add ZMSCORE command. See #1032.
|
145
|
+
* Add LT/GT options to ZADD. See #1033.
|
146
|
+
* Add SMISMEMBER command. See #1031.
|
147
|
+
* Add EXAT/PXAT options to SET. See #1028.
|
148
|
+
* Add GETDEL/GETEX commands. See #1024.
|
149
|
+
* `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`.
|
150
|
+
* Fix Redis < 6 detection during connect. See #1025.
|
151
|
+
* Fix fetching command details in Redis cluster when the first node is unhealthy. See #1026.
|
152
|
+
|
153
|
+
# 4.4.0
|
154
|
+
|
155
|
+
* Redis cluster: fix cross-slot validation in pipelines. Fix ##1019.
|
156
|
+
* Add support for `XAUTOCLAIM`. See #1018.
|
157
|
+
* Properly issue `READONLY` when reconnecting to replicas. Fix #1017.
|
158
|
+
* Make `del` a noop if passed an empty list of keys. See #998.
|
159
|
+
* Add support for `ZINTER`. See #995.
|
160
|
+
|
161
|
+
# 4.3.1
|
162
|
+
|
163
|
+
* Fix password authentication against redis server 5 and older.
|
164
|
+
|
165
|
+
# 4.3.0
|
166
|
+
|
167
|
+
* Add the TYPE argument to scan and scan_each. See #985.
|
168
|
+
* Support AUTH command for ACL. See #967.
|
169
|
+
|
3
170
|
# 4.2.5
|
4
171
|
|
5
172
|
* Optimize the ruby connector write buffering. See #964.
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
# redis-rb [![Build Status][
|
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
|
|
@@ -38,10 +37,6 @@ redis = Redis.new(url: "redis://:p4ssw0rd@10.0.1.1:6380/15")
|
|
38
37
|
The client expects passwords with special chracters 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
|
@@ -54,6 +49,12 @@ To connect to a password protected Redis instance, use:
|
|
54
49
|
redis = Redis.new(password: "mysecret")
|
55
50
|
```
|
56
51
|
|
52
|
+
To connect a Redis instance using [ACL](https://redis.io/topics/acl), use:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
redis = Redis.new(username: 'myname', password: 'mysecret')
|
56
|
+
```
|
57
|
+
|
57
58
|
The Redis class exports methods that are named identical to the commands
|
58
59
|
they execute. The arguments these methods accept are often identical to
|
59
60
|
the arguments specified on the [Redis website][redis-commands]. For
|
@@ -70,6 +71,26 @@ redis.get("mykey")
|
|
70
71
|
All commands, their arguments, and return values are documented and
|
71
72
|
available on [RubyDoc.info][rubydoc].
|
72
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 heavilly 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
|
+
|
73
94
|
## Sentinel support
|
74
95
|
|
75
96
|
The client is able to perform automatic failover by using [Redis
|
@@ -82,7 +103,7 @@ To connect using Sentinel, use:
|
|
82
103
|
SENTINELS = [{ host: "127.0.0.1", port: 26380 },
|
83
104
|
{ host: "127.0.0.1", port: 26381 }]
|
84
105
|
|
85
|
-
redis = Redis.new(
|
106
|
+
redis = Redis.new(name: "mymaster", sentinels: SENTINELS, role: :master)
|
86
107
|
```
|
87
108
|
|
88
109
|
* The master name identifies a group of Redis instances composed of a master
|
@@ -105,64 +126,18 @@ If you want to [authenticate](https://redis.io/topics/sentinel#configuring-senti
|
|
105
126
|
SENTINELS = [{ host: '127.0.0.1', port: 26380, password: 'mysecret' },
|
106
127
|
{ host: '127.0.0.1', port: 26381, password: 'mysecret' }]
|
107
128
|
|
108
|
-
redis = Redis.new(
|
129
|
+
redis = Redis.new(name: 'mymaster', sentinels: SENTINELS, role: :master)
|
109
130
|
```
|
110
131
|
|
111
|
-
|
112
|
-
|
113
|
-
`redis-rb` supports [clustering](https://redis.io/topics/cluster-spec).
|
132
|
+
Also the name can be passed as an url:
|
114
133
|
|
115
134
|
```ruby
|
116
|
-
|
117
|
-
nodes = (7000..7005).map { |port| "redis://127.0.0.1:#{port}" }
|
118
|
-
redis = Redis.new(cluster: nodes)
|
119
|
-
|
120
|
-
# You can also specify the options as a Hash. The options are the same as for a single server connection.
|
121
|
-
(7000..7005).map { |port| { host: '127.0.0.1', port: port } }
|
122
|
-
```
|
123
|
-
|
124
|
-
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.
|
125
|
-
|
126
|
-
```ruby
|
127
|
-
Redis.new(cluster: %w[redis://127.0.0.1:7000])
|
128
|
-
```
|
129
|
-
|
130
|
-
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.
|
131
|
-
|
132
|
-
```ruby
|
133
|
-
Redis.new(cluster: nodes, replica: true)
|
134
|
-
```
|
135
|
-
|
136
|
-
The calling code is responsible for [avoiding cross slot commands](https://redis.io/topics/cluster-spec#keys-distribution-model).
|
137
|
-
|
138
|
-
```ruby
|
139
|
-
redis = Redis.new(cluster: %w[redis://127.0.0.1:7000])
|
140
|
-
|
141
|
-
redis.mget('key1', 'key2')
|
142
|
-
#=> Redis::CommandError (CROSSSLOT Keys in request don't hash to the same slot)
|
143
|
-
|
144
|
-
redis.mget('{key}1', '{key}2')
|
145
|
-
#=> [nil, nil]
|
135
|
+
redis = Redis.new(name: "redis://mymaster", sentinels: SENTINELS, role: :master)
|
146
136
|
```
|
147
137
|
|
148
|
-
|
149
|
-
* The client support permanent node failures, and will reroute requests to promoted slaves.
|
150
|
-
* The client supports `MOVED` and `ASK` redirections transparently.
|
151
|
-
|
152
|
-
## Storing objects
|
153
|
-
|
154
|
-
Redis "string" types can be used to store serialized Ruby objects, for
|
155
|
-
example with JSON:
|
156
|
-
|
157
|
-
```ruby
|
158
|
-
require "json"
|
159
|
-
|
160
|
-
redis.set "foo", [1, 2, 3].to_json
|
161
|
-
# => OK
|
138
|
+
## Cluster support
|
162
139
|
|
163
|
-
|
164
|
-
# => [1, 2, 3]
|
165
|
-
```
|
140
|
+
[Clustering](https://redis.io/topics/cluster-spec). is supported via the [`redis-clustering` gem](cluster/).
|
166
141
|
|
167
142
|
## Pipelining
|
168
143
|
|
@@ -178,13 +153,24 @@ commands to Redis and gathers their replies. These replies are returned
|
|
178
153
|
by the `#pipelined` method.
|
179
154
|
|
180
155
|
```ruby
|
181
|
-
redis.pipelined do
|
182
|
-
|
183
|
-
|
156
|
+
redis.pipelined do |pipeline|
|
157
|
+
pipeline.set "foo", "bar"
|
158
|
+
pipeline.incr "baz"
|
184
159
|
end
|
185
160
|
# => ["OK", 1]
|
186
161
|
```
|
187
162
|
|
163
|
+
Commands must be called on the yielded objects. If you call methods
|
164
|
+
on the original client objects from inside a pipeline, they will be sent immediately:
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
redis.pipelined do |pipeline|
|
168
|
+
pipeline.set "foo", "bar"
|
169
|
+
redis.incr "baz" # => 1
|
170
|
+
end
|
171
|
+
# => ["OK"]
|
172
|
+
```
|
173
|
+
|
188
174
|
### Executing commands atomically
|
189
175
|
|
190
176
|
You can use `MULTI/EXEC` to run a number of commands in an atomic
|
@@ -194,9 +180,9 @@ the regular pipeline, the replies to the commands are returned by the
|
|
194
180
|
`#multi` method.
|
195
181
|
|
196
182
|
```ruby
|
197
|
-
redis.multi do
|
198
|
-
|
199
|
-
|
183
|
+
redis.multi do |transaction|
|
184
|
+
transaction.set "foo", "bar"
|
185
|
+
transaction.incr "baz"
|
200
186
|
end
|
201
187
|
# => ["OK", 1]
|
202
188
|
```
|
@@ -204,21 +190,22 @@ end
|
|
204
190
|
### Futures
|
205
191
|
|
206
192
|
Replies to commands in a pipeline can be accessed via the *futures* they
|
207
|
-
emit
|
193
|
+
emit. All calls on the pipeline object return a
|
208
194
|
`Future` object, which responds to the `#value` method. When the
|
209
195
|
pipeline has successfully executed, all futures are assigned their
|
210
196
|
respective replies and can be used.
|
211
197
|
|
212
198
|
```ruby
|
213
|
-
|
214
|
-
|
215
|
-
|
199
|
+
set = incr = nil
|
200
|
+
redis.pipelined do |pipeline|
|
201
|
+
set = pipeline.set "foo", "bar"
|
202
|
+
incr = pipeline.incr "baz"
|
216
203
|
end
|
217
204
|
|
218
|
-
|
205
|
+
set.value
|
219
206
|
# => "OK"
|
220
207
|
|
221
|
-
|
208
|
+
incr.value
|
222
209
|
# => 1
|
223
210
|
```
|
224
211
|
|
@@ -230,7 +217,7 @@ it can't connect to the server a `Redis::CannotConnectError` error will be raise
|
|
230
217
|
```ruby
|
231
218
|
begin
|
232
219
|
redis.ping
|
233
|
-
rescue
|
220
|
+
rescue Redis::BaseError => e
|
234
221
|
e.inspect
|
235
222
|
# => #<Redis::CannotConnectError: Timed out connecting to Redis on 10.0.1.1:6380>
|
236
223
|
|
@@ -277,55 +264,37 @@ If no message is received after 5 seconds, the client will unsubscribe.
|
|
277
264
|
|
278
265
|
## Reconnections
|
279
266
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
`reconnect_delay` and `reconnect_delay_max`.
|
267
|
+
**By default**, this gem will only **retry a connection once** and then fail, but
|
268
|
+
the client allows you to configure how many `reconnect_attempts` it should
|
269
|
+
complete before declaring a connection as failed.
|
284
270
|
|
285
271
|
```ruby
|
286
|
-
Redis.new(
|
287
|
-
|
288
|
-
:reconnect_delay => 1.5,
|
289
|
-
:reconnect_delay_max => 10.0,
|
290
|
-
)
|
272
|
+
Redis.new(reconnect_attempts: 0)
|
273
|
+
Redis.new(reconnect_attempts: 3)
|
291
274
|
```
|
292
275
|
|
293
|
-
|
294
|
-
|
295
|
-
between each attempt but it never waits longer than `reconnect_delay_max`.
|
296
|
-
|
297
|
-
This is the retry algorithm:
|
276
|
+
If you wish to wait between reconnection attempts, you can instead pass a list
|
277
|
+
of durations:
|
298
278
|
|
299
279
|
```ruby
|
300
|
-
|
280
|
+
Redis.new(reconnect_attempts: [
|
281
|
+
0, # retry immediately
|
282
|
+
0.25, # retry a second time after 250ms
|
283
|
+
1, # retry a third and final time after another 1s
|
284
|
+
])
|
301
285
|
```
|
302
286
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
#|Attempt wait time|Total wait time
|
307
|
-
:-:|:-:|:-:
|
308
|
-
1|1.5s|1.5s
|
309
|
-
2|3.0s|4.5s
|
310
|
-
3|6.0s|10.5s
|
311
|
-
4|10.0s|20.5s
|
312
|
-
5|10.0s|30.5s
|
313
|
-
6|10.0s|40.5s
|
314
|
-
7|10.0s|50.5s
|
315
|
-
8|10.0s|60.5s
|
316
|
-
9|10.0s|70.5s
|
317
|
-
10|10.0s|80.5s
|
318
|
-
|
319
|
-
So if the reconnection attempt #10 succeeds 70 seconds have elapsed trying
|
320
|
-
to reconnect, this is likely fine in long-running background processes, but if
|
321
|
-
you use Redis to drive your website you might want to have a lower
|
322
|
-
`reconnect_delay_max` or have less `reconnect_attempts`.
|
287
|
+
If you wish to disable reconnection only for some commands, you can use
|
288
|
+
`disable_reconnection`:
|
323
289
|
|
324
|
-
|
290
|
+
```ruby
|
291
|
+
redis.get("some-key") # this may be retried
|
292
|
+
redis.disable_reconnection do
|
293
|
+
redis.incr("some-counter") # this won't be retried.
|
294
|
+
end
|
295
|
+
```
|
325
296
|
|
326
|
-
|
327
|
-
when talking to Redis via a server-side proxy such as [stunnel], [hitch],
|
328
|
-
or [ghostunnel].
|
297
|
+
## SSL/TLS Support
|
329
298
|
|
330
299
|
To enable SSL support, pass the `:ssl => true` option when configuring the
|
331
300
|
Redis client, or pass in `:url => "rediss://..."` (like HTTPS for Redis).
|
@@ -360,13 +329,7 @@ redis = Redis.new(
|
|
360
329
|
)
|
361
330
|
```
|
362
331
|
|
363
|
-
[
|
364
|
-
[hitch]: https://hitch-tls.org/
|
365
|
-
[ghostunnel]: https://github.com/square/ghostunnel
|
366
|
-
[OpenSSL::SSL::SSLContext documentation]: http://ruby-doc.org/stdlib-2.3.0/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html
|
367
|
-
|
368
|
-
*NOTE:* SSL is only supported by the default "Ruby" driver
|
369
|
-
|
332
|
+
[OpenSSL::SSL::SSLContext documentation]: http://ruby-doc.org/stdlib-2.5.0/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html
|
370
333
|
|
371
334
|
## Expert-Mode Options
|
372
335
|
|
@@ -380,17 +343,9 @@ redis = Redis.new(
|
|
380
343
|
Improper use of `inherit_socket` will result in corrupted and/or incorrect
|
381
344
|
responses.
|
382
345
|
|
383
|
-
##
|
346
|
+
## hiredis binding
|
384
347
|
|
385
348
|
By default, redis-rb uses Ruby's socket library to talk with Redis.
|
386
|
-
To use an alternative connection driver it should be specified as option
|
387
|
-
when instantiating the client object. These instructions are only valid
|
388
|
-
for **redis-rb 3.0**. For instructions on how to use alternate drivers from
|
389
|
-
**redis-rb 2.2**, please refer to an [older README][readme-2.2.2].
|
390
|
-
|
391
|
-
[readme-2.2.2]: https://github.com/redis/redis-rb/blob/v2.2.2/README.md
|
392
|
-
|
393
|
-
### hiredis
|
394
349
|
|
395
350
|
The hiredis driver uses the connection facility of hiredis-rb. In turn,
|
396
351
|
hiredis-rb is a binding to the official hiredis client library. It
|
@@ -400,47 +355,33 @@ extension, JRuby is not supported (by default).
|
|
400
355
|
It is best to use hiredis when you have large replies (for example:
|
401
356
|
`LRANGE`, `SMEMBERS`, `ZRANGE`, etc.) and/or use big pipelines.
|
402
357
|
|
403
|
-
In your Gemfile, include hiredis
|
358
|
+
In your Gemfile, include `hiredis-client`:
|
404
359
|
|
405
360
|
```ruby
|
406
|
-
gem "redis"
|
407
|
-
gem "hiredis"
|
361
|
+
gem "redis"
|
362
|
+
gem "hiredis-client"
|
408
363
|
```
|
409
364
|
|
410
|
-
|
365
|
+
If your application doesn't call `Bundler.require`, you may have
|
366
|
+
to require it explictly:
|
411
367
|
|
412
368
|
```ruby
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
### synchrony
|
417
|
-
|
418
|
-
The synchrony driver adds support for [em-synchrony][em-synchrony].
|
419
|
-
This makes redis-rb work with EventMachine's asynchronous I/O, while not
|
420
|
-
changing the exposed API. The hiredis gem needs to be available as
|
421
|
-
well, because the synchrony driver uses hiredis for parsing the Redis
|
422
|
-
protocol.
|
423
|
-
|
424
|
-
[em-synchrony]: https://github.com/igrigorik/em-synchrony
|
369
|
+
require "hiredis-client"
|
370
|
+
````
|
425
371
|
|
426
|
-
|
427
|
-
|
428
|
-
```ruby
|
429
|
-
gem "redis", "~> 3.0.1"
|
430
|
-
gem "hiredis", "~> 0.4.5"
|
431
|
-
gem "em-synchrony"
|
432
|
-
```
|
372
|
+
This makes the hiredis driver the default.
|
433
373
|
|
434
|
-
|
374
|
+
If you want to be certain hiredis is being used, when instantiating
|
375
|
+
the client object, specify hiredis:
|
435
376
|
|
436
377
|
```ruby
|
437
|
-
redis = Redis.new(:
|
378
|
+
redis = Redis.new(driver: :hiredis)
|
438
379
|
```
|
439
380
|
|
440
381
|
## Testing
|
441
382
|
|
442
383
|
This library is tested against recent Ruby and Redis versions.
|
443
|
-
Check [
|
384
|
+
Check [Github Actions][gh-actions-link] for the exact versions supported.
|
444
385
|
|
445
386
|
## See Also
|
446
387
|
|
@@ -459,12 +400,11 @@ client and evangelized Redis in Rubyland. Thank you, Ezra.
|
|
459
400
|
requests.
|
460
401
|
|
461
402
|
|
462
|
-
[
|
463
|
-
[
|
464
|
-
[redis-commands]:
|
465
|
-
[redis-home]:
|
466
|
-
[redis-url]:
|
467
|
-
[
|
468
|
-
[
|
469
|
-
[
|
470
|
-
[rubydoc]: http://www.rubydoc.info/gems/redis
|
403
|
+
[rdoc-master-image]: https://img.shields.io/badge/docs-rdoc.info-blue.svg
|
404
|
+
[rdoc-master-link]: https://rubydoc.info/github/redis/redis-rb
|
405
|
+
[redis-commands]: https://redis.io/commands
|
406
|
+
[redis-home]: https://redis.io
|
407
|
+
[redis-url]: https://www.iana.org/assignments/uri-schemes/prov/redis
|
408
|
+
[gh-actions-image]: https://github.com/redis/redis-rb/workflows/Test/badge.svg
|
409
|
+
[gh-actions-link]: https://github.com/redis/redis-rb/actions
|
410
|
+
[rubydoc]: https://rubydoc.info/gems/redis
|