redis 4.8.1 → 5.4.0
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 +82 -0
- data/README.md +125 -162
- data/lib/redis/client.rb +82 -616
- data/lib/redis/commands/bitmaps.rb +14 -4
- data/lib/redis/commands/cluster.rb +1 -18
- data/lib/redis/commands/connection.rb +5 -10
- data/lib/redis/commands/geo.rb +3 -3
- data/lib/redis/commands/hashes.rb +13 -6
- data/lib/redis/commands/hyper_log_log.rb +1 -1
- data/lib/redis/commands/keys.rb +27 -23
- data/lib/redis/commands/lists.rb +74 -25
- data/lib/redis/commands/pubsub.rb +34 -25
- data/lib/redis/commands/server.rb +15 -15
- data/lib/redis/commands/sets.rb +35 -40
- data/lib/redis/commands/sorted_sets.rb +128 -18
- data/lib/redis/commands/streams.rb +48 -21
- data/lib/redis/commands/strings.rb +18 -17
- data/lib/redis/commands/transactions.rb +7 -31
- data/lib/redis/commands.rb +11 -12
- data/lib/redis/distributed.rb +136 -72
- data/lib/redis/errors.rb +15 -50
- data/lib/redis/hash_ring.rb +26 -26
- data/lib/redis/pipeline.rb +47 -222
- data/lib/redis/subscribe.rb +50 -14
- data/lib/redis/version.rb +1 -1
- data/lib/redis.rb +77 -184
- metadata +10 -57
- data/lib/redis/cluster/command.rb +0 -79
- data/lib/redis/cluster/command_loader.rb +0 -33
- data/lib/redis/cluster/key_slot_converter.rb +0 -72
- data/lib/redis/cluster/node.rb +0 -120
- data/lib/redis/cluster/node_key.rb +0 -31
- data/lib/redis/cluster/node_loader.rb +0 -34
- data/lib/redis/cluster/option.rb +0 -100
- data/lib/redis/cluster/slot.rb +0 -86
- data/lib/redis/cluster/slot_loader.rb +0 -46
- data/lib/redis/cluster.rb +0 -315
- data/lib/redis/connection/command_helper.rb +0 -41
- data/lib/redis/connection/hiredis.rb +0 -68
- data/lib/redis/connection/registry.rb +0 -13
- data/lib/redis/connection/ruby.rb +0 -437
- data/lib/redis/connection/synchrony.rb +0 -148
- 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: 485e29928983863d4725f47cf52718493c36724b1b736951603fb81648fd1ffb
|
4
|
+
data.tar.gz: 17663d08f23fe1106e89f3b06805402f5f1ff7b5bcee2e4bb9593cc3329646f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71bed198d46e435677b3ebf725ba65a55af5d5d7a73ff1593d2ac7044972d2898f7c5503fc69d3aa202d8a00781174e0c7348cefa06102c948b9df19cd22d81c
|
7
|
+
data.tar.gz: 607288d9a58459346db9c6e79041d35c98cc2c3268c74ffceecd395799833b9ba8e0f1c29c236d6c5afdc917bd66089721fdf5977efcab0799f46cfedb18e826
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,87 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# 5.4.0
|
4
|
+
|
5
|
+
- Fix `blmpop` method to actually use `BLMPOP`, it was mistakenly issuing `LMPOP` commands.
|
6
|
+
- `xadd` now accepts a `minid:` argument.
|
7
|
+
- `zrank` and `zrevrank` now accepts `with_score:` argument.
|
8
|
+
- `Redis#call` now accept a block, allowing to use `Redis` instances where `RedisClient` is expected.
|
9
|
+
|
10
|
+
# 5.3.0
|
11
|
+
|
12
|
+
- Fix the return type of `hgetall` when used inside a `multi` transaction which is itself inside a pipeline.
|
13
|
+
|
14
|
+
# 5.2.0
|
15
|
+
|
16
|
+
- Now require Ruby 2.6 because `redis-client` does.
|
17
|
+
- Eagerly close subscribed connection when using `subscribe_with_timeout`. See #1259.
|
18
|
+
- Add `exception` flag in `pipelined` allowing failed commands to be returned in the result array when set to `false`.
|
19
|
+
|
20
|
+
# 5.1.0
|
21
|
+
|
22
|
+
- `multi` now accept a `watch` keyword argument like `redis-client`. See #1236.
|
23
|
+
- `bitcount` and `bitpos` now accept a `scale:` argument on Redis 7+. See #1242
|
24
|
+
- Added `expiretime` and `pexpiretime`. See #1248.
|
25
|
+
|
26
|
+
# 5.0.8
|
27
|
+
|
28
|
+
- Fix `Redis#without_reconnect` for sentinel clients. Fix #1212.
|
29
|
+
- Add `sentinel_username`, `sentinel_password` for sentinel clients. Bump `redis-client` to `>=0.17.0`. See #1213
|
30
|
+
|
31
|
+
# 5.0.7
|
32
|
+
|
33
|
+
- Fix compatibility with `redis-client 0.15.0` when using Redis Sentinel. Fix #1209.
|
34
|
+
|
35
|
+
# 5.0.6
|
36
|
+
|
37
|
+
- Wait for an extra `config.read_timeout` in blocking commands rather than an arbitrary 100ms. See #1175.
|
38
|
+
- Treat ReadOnlyError as ConnectionError. See #1168.
|
39
|
+
|
40
|
+
# 5.0.5
|
41
|
+
|
42
|
+
- Fix automatic disconnection when the process was forked. See #1157.
|
43
|
+
|
44
|
+
# 5.0.4
|
45
|
+
|
46
|
+
- Cast `ttl` argument to integer in `expire`, `setex` and a few others.
|
47
|
+
|
48
|
+
# 5.0.3
|
49
|
+
|
50
|
+
- Add `OutOfMemoryError` as a subclass of `CommandError`
|
51
|
+
|
52
|
+
# 5.0.2
|
53
|
+
|
54
|
+
- Fix `Redis#close` to properly reset the fork protection check.
|
55
|
+
|
56
|
+
# 5.0.1
|
57
|
+
|
58
|
+
- Added a fake `Redis::Connections.drivers` method to be compatible with older sidekiq versions.
|
59
|
+
|
60
|
+
# 5.0.0
|
61
|
+
|
62
|
+
- Default client timeout decreased from 5 seconds to 1 second.
|
63
|
+
- Eagerly and strictly cast Integer and Float parameters.
|
64
|
+
- Allow to call `subscribe`, `unsubscribe`, `psubscribe` and `punsubscribe` from a subscribed client. See #1131.
|
65
|
+
- Use `MD5` for hashing server nodes in `Redis::Distributed`. This should improve keys distribution among servers. See #1089.
|
66
|
+
- Changed `sadd` and `srem` to now always return an Integer.
|
67
|
+
- Added `sadd?` and `srem?` which always return a Boolean.
|
68
|
+
- Added support for `IDLE` paramter in `xpending`.
|
69
|
+
- Cluster support has been moved to a `redis-clustering` companion gem.
|
70
|
+
- `select` no longer record the current database. If the client has to reconnect after `select` was used, it will reconnect to the original database.
|
71
|
+
- Better support Float timeout in blocking commands. See #977.
|
72
|
+
- `Redis.new` will now raise an error if provided unknown options.
|
73
|
+
- Removed positional timeout in blocking commands (`BLPOP`, etc). Timeout now must be passed as an option: `r.blpop("key", timeout: 2.5)`
|
74
|
+
- Removed `logger` option.
|
75
|
+
- Removed `reconnect_delay_max` and `reconnect_delay`, you can pass precise sleep durations to `reconnect_attempts` instead.
|
76
|
+
- Require Ruby 2.5+.
|
77
|
+
- Removed the deprecated `queue` and `commit` methods. Use `pipelined` instead.
|
78
|
+
- Removed the deprecated `Redis::Future#==`.
|
79
|
+
- Removed the deprecated `pipelined` and `multi` signature. Commands now MUST be called on the block argument, not the original redis instance.
|
80
|
+
- Removed `Redis.current`. You shouldn't assume there is a single global Redis connection, use a connection pool instead,
|
81
|
+
and libaries using Redis should accept a Redis instance (or connection pool) as a config. E.g. `MyLibrary.redis = Redis.new(...)`.
|
82
|
+
- Removed the `synchrony` driver.
|
83
|
+
- Removed `Redis.exists_returns_integer`, it's now always enabled.
|
84
|
+
|
3
85
|
# 4.8.1
|
4
86
|
|
5
87
|
* Automatically reconnect after fork regardless of `reconnect_attempts`
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
# redis-rb [![Build Status][gh-actions-image]][gh-actions-link] [![Inline docs][
|
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
|
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(
|
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,85 +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
|
-
|
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
|
112
|
-
{ host: '127.0.0.1', port: 26381
|
126
|
+
SENTINELS = [{ host: '127.0.0.1', port: 26380},
|
127
|
+
{ host: '127.0.0.1', port: 26381}]
|
113
128
|
|
114
|
-
redis = Redis.new(
|
129
|
+
redis = Redis.new(name: 'mymaster', sentinels: SENTINELS, sentinel_username: 'appuser', sentinel_password: 'mysecret', role: :master)
|
115
130
|
```
|
116
131
|
|
117
|
-
|
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
|
-
#
|
123
|
-
|
124
|
-
|
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
|
-
|
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
|
-
|
142
|
+
So you have to provide Sentinel credential and Redis explicitly even they are the same
|
131
143
|
|
132
144
|
```ruby
|
133
|
-
|
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
|
-
|
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
|
-
|
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(
|
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
|
-
|
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
|
-
## Cluster mode with SSL/TLS
|
159
|
-
Since Redis can return FQDN of nodes in reply to client since `7.*` with CLUSTER commands, we can use cluster feature with SSL/TLS connection like this:
|
160
|
-
|
161
|
-
```ruby
|
162
|
-
Redis.new(cluster: %w[rediss://foo.example.com:6379])
|
163
|
-
```
|
164
|
-
|
165
|
-
On the other hand, in Redis versions prior to `6.*`, you can specify options like the following if cluster mode is enabled and client has to connect to nodes via single endpoint with SSL/TLS.
|
166
|
-
|
167
|
-
```ruby
|
168
|
-
Redis.new(cluster: %w[rediss://foo-endpoint.example.com:6379], fixed_hostname: 'foo-endpoint.example.com')
|
169
|
-
```
|
170
|
-
|
171
|
-
In case of the above architecture, if you don't pass the `fixed_hostname` option to the client and servers return IP addresses of nodes, the client may fail to verify certificates.
|
172
|
-
|
173
|
-
## Storing objects
|
174
|
-
|
175
|
-
Redis "string" types can be used to store serialized Ruby objects, for
|
176
|
-
example with JSON:
|
177
|
-
|
178
|
-
```ruby
|
179
|
-
require "json"
|
180
|
-
|
181
|
-
redis.set "foo", [1, 2, 3].to_json
|
182
|
-
# => OK
|
158
|
+
## Cluster support
|
183
159
|
|
184
|
-
|
185
|
-
# => [1, 2, 3]
|
186
|
-
```
|
160
|
+
[Clustering](https://redis.io/topics/cluster-spec). is supported via the [`redis-clustering` gem](cluster/).
|
187
161
|
|
188
162
|
## Pipelining
|
189
163
|
|
@@ -206,6 +180,39 @@ end
|
|
206
180
|
# => ["OK", 1]
|
207
181
|
```
|
208
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
|
+
|
209
216
|
### Executing commands atomically
|
210
217
|
|
211
218
|
You can use `MULTI/EXEC` to run a number of commands in an atomic
|
@@ -225,21 +232,22 @@ end
|
|
225
232
|
### Futures
|
226
233
|
|
227
234
|
Replies to commands in a pipeline can be accessed via the *futures* they
|
228
|
-
emit
|
235
|
+
emit. All calls on the pipeline object return a
|
229
236
|
`Future` object, which responds to the `#value` method. When the
|
230
237
|
pipeline has successfully executed, all futures are assigned their
|
231
238
|
respective replies and can be used.
|
232
239
|
|
233
240
|
```ruby
|
241
|
+
set = incr = nil
|
234
242
|
redis.pipelined do |pipeline|
|
235
|
-
|
236
|
-
|
243
|
+
set = pipeline.set "foo", "bar"
|
244
|
+
incr = pipeline.incr "baz"
|
237
245
|
end
|
238
246
|
|
239
|
-
|
247
|
+
set.value
|
240
248
|
# => "OK"
|
241
249
|
|
242
|
-
|
250
|
+
incr.value
|
243
251
|
# => 1
|
244
252
|
```
|
245
253
|
|
@@ -251,7 +259,7 @@ it can't connect to the server a `Redis::CannotConnectError` error will be raise
|
|
251
259
|
```ruby
|
252
260
|
begin
|
253
261
|
redis.ping
|
254
|
-
rescue
|
262
|
+
rescue Redis::BaseError => e
|
255
263
|
e.inspect
|
256
264
|
# => #<Redis::CannotConnectError: Timed out connecting to Redis on 10.0.1.1:6380>
|
257
265
|
|
@@ -265,6 +273,7 @@ See lib/redis/errors.rb for information about what exceptions are possible.
|
|
265
273
|
## Timeouts
|
266
274
|
|
267
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.
|
268
277
|
Passing a single `timeout` option will set all three values:
|
269
278
|
|
270
279
|
```ruby
|
@@ -298,55 +307,37 @@ If no message is received after 5 seconds, the client will unsubscribe.
|
|
298
307
|
|
299
308
|
## Reconnections
|
300
309
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
`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.
|
305
313
|
|
306
314
|
```ruby
|
307
|
-
Redis.new(
|
308
|
-
|
309
|
-
:reconnect_delay => 1.5,
|
310
|
-
:reconnect_delay_max => 10.0,
|
311
|
-
)
|
315
|
+
Redis.new(reconnect_attempts: 0)
|
316
|
+
Redis.new(reconnect_attempts: 3)
|
312
317
|
```
|
313
318
|
|
314
|
-
|
315
|
-
|
316
|
-
between each attempt but it never waits longer than `reconnect_delay_max`.
|
317
|
-
|
318
|
-
This is the retry algorithm:
|
319
|
+
If you wish to wait between reconnection attempts, you can instead pass a list
|
320
|
+
of durations:
|
319
321
|
|
320
322
|
```ruby
|
321
|
-
|
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
|
+
])
|
322
328
|
```
|
323
329
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
#|Attempt wait time|Total wait time
|
328
|
-
:-:|:-:|:-:
|
329
|
-
1|1.5s|1.5s
|
330
|
-
2|3.0s|4.5s
|
331
|
-
3|6.0s|10.5s
|
332
|
-
4|10.0s|20.5s
|
333
|
-
5|10.0s|30.5s
|
334
|
-
6|10.0s|40.5s
|
335
|
-
7|10.0s|50.5s
|
336
|
-
8|10.0s|60.5s
|
337
|
-
9|10.0s|70.5s
|
338
|
-
10|10.0s|80.5s
|
339
|
-
|
340
|
-
So if the reconnection attempt #10 succeeds 70 seconds have elapsed trying
|
341
|
-
to reconnect, this is likely fine in long-running background processes, but if
|
342
|
-
you use Redis to drive your website you might want to have a lower
|
343
|
-
`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`:
|
344
332
|
|
345
|
-
|
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
|
+
```
|
346
339
|
|
347
|
-
|
348
|
-
when talking to Redis via a server-side proxy such as [stunnel], [hitch],
|
349
|
-
or [ghostunnel].
|
340
|
+
## SSL/TLS Support
|
350
341
|
|
351
342
|
To enable SSL support, pass the `:ssl => true` option when configuring the
|
352
343
|
Redis client, or pass in `:url => "rediss://..."` (like HTTPS for Redis).
|
@@ -381,13 +372,7 @@ redis = Redis.new(
|
|
381
372
|
)
|
382
373
|
```
|
383
374
|
|
384
|
-
[
|
385
|
-
[hitch]: https://hitch-tls.org/
|
386
|
-
[ghostunnel]: https://github.com/square/ghostunnel
|
387
|
-
[OpenSSL::SSL::SSLContext documentation]: http://ruby-doc.org/stdlib-2.3.0/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html
|
388
|
-
|
389
|
-
*NOTE:* SSL is only supported by the default "Ruby" driver
|
390
|
-
|
375
|
+
[OpenSSL::SSL::SSLContext documentation]: http://ruby-doc.org/stdlib-2.5.0/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html
|
391
376
|
|
392
377
|
## Expert-Mode Options
|
393
378
|
|
@@ -401,17 +386,9 @@ redis = Redis.new(
|
|
401
386
|
Improper use of `inherit_socket` will result in corrupted and/or incorrect
|
402
387
|
responses.
|
403
388
|
|
404
|
-
##
|
389
|
+
## hiredis binding
|
405
390
|
|
406
391
|
By default, redis-rb uses Ruby's socket library to talk with Redis.
|
407
|
-
To use an alternative connection driver it should be specified as option
|
408
|
-
when instantiating the client object. These instructions are only valid
|
409
|
-
for **redis-rb 3.0**. For instructions on how to use alternate drivers from
|
410
|
-
**redis-rb 2.2**, please refer to an [older README][readme-2.2.2].
|
411
|
-
|
412
|
-
[readme-2.2.2]: https://github.com/redis/redis-rb/blob/v2.2.2/README.md
|
413
|
-
|
414
|
-
### hiredis
|
415
392
|
|
416
393
|
The hiredis driver uses the connection facility of hiredis-rb. In turn,
|
417
394
|
hiredis-rb is a binding to the official hiredis client library. It
|
@@ -421,41 +398,27 @@ extension, JRuby is not supported (by default).
|
|
421
398
|
It is best to use hiredis when you have large replies (for example:
|
422
399
|
`LRANGE`, `SMEMBERS`, `ZRANGE`, etc.) and/or use big pipelines.
|
423
400
|
|
424
|
-
In your Gemfile, include hiredis
|
401
|
+
In your Gemfile, include `hiredis-client`:
|
425
402
|
|
426
403
|
```ruby
|
427
|
-
gem "redis"
|
428
|
-
gem "hiredis"
|
404
|
+
gem "redis"
|
405
|
+
gem "hiredis-client"
|
429
406
|
```
|
430
407
|
|
431
|
-
|
408
|
+
If your application doesn't call `Bundler.require`, you may have
|
409
|
+
to require it explicitly:
|
432
410
|
|
433
411
|
```ruby
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
### synchrony
|
438
|
-
|
439
|
-
The synchrony driver adds support for [em-synchrony][em-synchrony].
|
440
|
-
This makes redis-rb work with EventMachine's asynchronous I/O, while not
|
441
|
-
changing the exposed API. The hiredis gem needs to be available as
|
442
|
-
well, because the synchrony driver uses hiredis for parsing the Redis
|
443
|
-
protocol.
|
412
|
+
require "hiredis-client"
|
413
|
+
````
|
444
414
|
|
445
|
-
|
446
|
-
|
447
|
-
In your Gemfile, include em-synchrony and hiredis:
|
448
|
-
|
449
|
-
```ruby
|
450
|
-
gem "redis", "~> 3.0.1"
|
451
|
-
gem "hiredis", "~> 0.4.5"
|
452
|
-
gem "em-synchrony"
|
453
|
-
```
|
415
|
+
This makes the hiredis driver the default.
|
454
416
|
|
455
|
-
|
417
|
+
If you want to be certain hiredis is being used, when instantiating
|
418
|
+
the client object, specify hiredis:
|
456
419
|
|
457
420
|
```ruby
|
458
|
-
redis = Redis.new(:
|
421
|
+
redis = Redis.new(driver: :hiredis)
|
459
422
|
```
|
460
423
|
|
461
424
|
## Testing
|
@@ -480,11 +443,11 @@ client and evangelized Redis in Rubyland. Thank you, Ezra.
|
|
480
443
|
requests.
|
481
444
|
|
482
445
|
|
483
|
-
[
|
484
|
-
[
|
485
|
-
[redis-commands]:
|
486
|
-
[redis-home]:
|
487
|
-
[redis-url]:
|
488
|
-
[gh-actions-image]:
|
489
|
-
[gh-actions-link]:
|
490
|
-
[rubydoc]:
|
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
|