redis 4.1.0 → 4.6.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 +5 -5
- data/CHANGELOG.md +158 -0
- data/README.md +91 -27
- data/lib/redis/client.rb +148 -92
- data/lib/redis/cluster/command.rb +4 -6
- data/lib/redis/cluster/command_loader.rb +6 -7
- data/lib/redis/cluster/node.rb +17 -1
- data/lib/redis/cluster/node_key.rb +3 -7
- data/lib/redis/cluster/option.rb +30 -14
- data/lib/redis/cluster/slot.rb +30 -13
- data/lib/redis/cluster/slot_loader.rb +4 -4
- data/lib/redis/cluster.rb +46 -17
- data/lib/redis/commands/bitmaps.rb +63 -0
- data/lib/redis/commands/cluster.rb +45 -0
- data/lib/redis/commands/connection.rb +58 -0
- data/lib/redis/commands/geo.rb +84 -0
- data/lib/redis/commands/hashes.rb +251 -0
- data/lib/redis/commands/hyper_log_log.rb +37 -0
- data/lib/redis/commands/keys.rb +411 -0
- data/lib/redis/commands/lists.rb +289 -0
- data/lib/redis/commands/pubsub.rb +72 -0
- data/lib/redis/commands/scripting.rb +114 -0
- data/lib/redis/commands/server.rb +188 -0
- data/lib/redis/commands/sets.rb +207 -0
- data/lib/redis/commands/sorted_sets.rb +804 -0
- data/lib/redis/commands/streams.rb +382 -0
- data/lib/redis/commands/strings.rb +313 -0
- data/lib/redis/commands/transactions.rb +92 -0
- data/lib/redis/commands.rb +242 -0
- data/lib/redis/connection/command_helper.rb +5 -2
- data/lib/redis/connection/hiredis.rb +7 -5
- data/lib/redis/connection/registry.rb +2 -1
- data/lib/redis/connection/ruby.rb +129 -110
- data/lib/redis/connection/synchrony.rb +17 -10
- data/lib/redis/connection.rb +3 -1
- data/lib/redis/distributed.rb +209 -70
- data/lib/redis/errors.rb +2 -0
- data/lib/redis/hash_ring.rb +15 -14
- data/lib/redis/pipeline.rb +139 -8
- data/lib/redis/subscribe.rb +11 -12
- data/lib/redis/version.rb +3 -1
- data/lib/redis.rb +167 -3377
- metadata +32 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7e99f4e628112a227719d2000dc5b081893273cfbd51ae25bf00a8f6b6594061
|
4
|
+
data.tar.gz: 42a8e0cf75aebbc14cdf680b4bc1f7bbdec9e20b53f150c6443c01126960a959
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bc57fe306c601f27d32df4940d5632e9e7d75529f6ac5d42732b21fe04452a4a1ab89567492c6fb7249ef4d69ebb2c0b7c985e18b0ef4f9ee6fb816c31bcbda
|
7
|
+
data.tar.gz: 42b2f8c584d6f96d0fc783d0b36af0fd9415d1dbd43ad8fe7a980688e52fbdb51645a07960d9cb3faacf6696c460cf38a013e290d0b58d4bbbb07626f18f15c7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,163 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# 4.6.0
|
4
|
+
|
5
|
+
* Deprecate `Redis.current`.
|
6
|
+
* Deprecate calling commands on `Redis` inside `Redis#pipelined`. See #1059.
|
7
|
+
```ruby
|
8
|
+
redis.pipelined do
|
9
|
+
redis.get("key")
|
10
|
+
end
|
11
|
+
```
|
12
|
+
|
13
|
+
should be replaced by:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
redis.pipelined do |pipeline|
|
17
|
+
pipeline.get("key")
|
18
|
+
end
|
19
|
+
```
|
20
|
+
* Deprecate calling commands on `Redis` inside `Redis#multi`. See #1059.
|
21
|
+
```ruby
|
22
|
+
redis.multi do
|
23
|
+
redis.get("key")
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
should be replaced by:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
redis.multi do |transaction|
|
31
|
+
transaction.get("key")
|
32
|
+
end
|
33
|
+
```
|
34
|
+
* Deprecate `Redis#queue` and `Redis#commit`. See #1059.
|
35
|
+
|
36
|
+
* Fix `zpopmax` and `zpopmin` when called inside a pipeline. See #1055.
|
37
|
+
* `Redis#synchronize` is now private like it should always have been.
|
38
|
+
|
39
|
+
* Add `Redis.silence_deprecations=` to turn off deprecation warnings.
|
40
|
+
If you don't wish to see warnings yet, you can set `Redis.silence_deprecations = false`.
|
41
|
+
It is however heavily recommended to fix them instead when possible.
|
42
|
+
* Add `Redis.raise_deprecations=` to turn deprecation warnings into errors.
|
43
|
+
This makes it easier to identitify the source of deprecated APIs usage.
|
44
|
+
It is recommended to set `Redis.raise_deprecations = true` in development and test environments.
|
45
|
+
* Add new options to ZRANGE. See #1053.
|
46
|
+
* Add ZRANGESTORE command. See #1053.
|
47
|
+
* Add SCAN support for `Redis::Cluster`. See #1049.
|
48
|
+
* Add COPY command. See #1053. See #1048.
|
49
|
+
* Add ZDIFFSTORE command. See #1046.
|
50
|
+
* Add ZDIFF command. See #1044.
|
51
|
+
* Add ZUNION command. See #1042.
|
52
|
+
* Add HRANDFIELD command. See #1040.
|
53
|
+
|
54
|
+
# 4.5.1
|
55
|
+
|
56
|
+
* 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,
|
57
|
+
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.
|
58
|
+
This behavior is deprecated and will be removed in Redis 4.6.0. Fix #1038.
|
59
|
+
|
60
|
+
# 4.5.0
|
61
|
+
|
62
|
+
* Handle parts of the command using incompatible encodings. See #1037.
|
63
|
+
* Add GET option to SET command. See #1036.
|
64
|
+
* Add ZRANDMEMBER command. See #1035.
|
65
|
+
* Add LMOVE/BLMOVE commands. See #1034.
|
66
|
+
* Add ZMSCORE command. See #1032.
|
67
|
+
* Add LT/GT options to ZADD. See #1033.
|
68
|
+
* Add SMISMEMBER command. See #1031.
|
69
|
+
* Add EXAT/PXAT options to SET. See #1028.
|
70
|
+
* Add GETDEL/GETEX commands. See #1024.
|
71
|
+
* `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`.
|
72
|
+
* Fix Redis < 6 detection during connect. See #1025.
|
73
|
+
* Fix fetching command details in Redis cluster when the first node is unhealthy. See #1026.
|
74
|
+
|
75
|
+
# 4.4.0
|
76
|
+
|
77
|
+
* Redis cluster: fix cross-slot validation in pipelines. Fix ##1019.
|
78
|
+
* Add support for `XAUTOCLAIM`. See #1018.
|
79
|
+
* Properly issue `READONLY` when reconnecting to replicas. Fix #1017.
|
80
|
+
* Make `del` a noop if passed an empty list of keys. See #998.
|
81
|
+
* Add support for `ZINTER`. See #995.
|
82
|
+
|
83
|
+
# 4.3.1
|
84
|
+
|
85
|
+
* Fix password authentication against redis server 5 and older.
|
86
|
+
|
87
|
+
# 4.3.0
|
88
|
+
|
89
|
+
* Add the TYPE argument to scan and scan_each. See #985.
|
90
|
+
* Support AUTH command for ACL. See #967.
|
91
|
+
|
92
|
+
# 4.2.5
|
93
|
+
|
94
|
+
* Optimize the ruby connector write buffering. See #964.
|
95
|
+
|
96
|
+
# 4.2.4
|
97
|
+
|
98
|
+
* Fix bytesize calculations in the ruby connector, and work on a copy of the buffer. Fix #961, #962.
|
99
|
+
|
100
|
+
# 4.2.3
|
101
|
+
|
102
|
+
* Use io/wait instead of IO.select in the ruby connector. See #960.
|
103
|
+
* Use exception free non blocking IOs in the ruby connector. See #926.
|
104
|
+
* Prevent corruption of the client when an interrupt happen during inside a pipeline block. See #945.
|
105
|
+
|
106
|
+
# 4.2.2
|
107
|
+
|
108
|
+
* Fix `WATCH` support for `Redis::Distributed`. See #941.
|
109
|
+
* Fix handling of empty stream responses. See #905, #929.
|
110
|
+
|
111
|
+
# 4.2.1
|
112
|
+
|
113
|
+
* Fix `exists?` returning an actual boolean when called with multiple keys. See #918.
|
114
|
+
* Setting `Redis.exists_returns_integer = false` disables warning message about new behaviour. See #920.
|
115
|
+
|
116
|
+
# 4.2.0
|
117
|
+
|
118
|
+
* Convert commands to accept keyword arguments rather than option hashes. This both help catching typos, and reduce needless allocations.
|
119
|
+
* Deprecate the synchrony driver. It will be removed in 5.0 and hopefully maintained as a separate gem. See #915.
|
120
|
+
* Make `Redis#exists` variadic, will return an Integer if called with multiple keys.
|
121
|
+
* Add `Redis#exists?` to get a Boolean if any of the keys exists.
|
122
|
+
* `Redis#exists` when called with a single key will warn that future versions will return an Integer.
|
123
|
+
Set `Redis.exists_returns_integer = true` to opt-in to the new behavior.
|
124
|
+
* Support `keepttl` ooption in `set`. See #913.
|
125
|
+
* Optimized initialization of Redis::Cluster. See #912.
|
126
|
+
* Accept sentinel options even with string key. See #599.
|
127
|
+
* Verify TLS connections by default. See #900.
|
128
|
+
* Make `Redis#hset` variadic. It now returns an integer, not a boolean. See #910.
|
129
|
+
|
130
|
+
# 4.1.4
|
131
|
+
|
132
|
+
* Alias `Redis#disconnect` as `#close`. See #901.
|
133
|
+
* Handle clusters with multiple slot ranges. See #894.
|
134
|
+
* Fix password authentication to a redis cluster. See #889.
|
135
|
+
* Handle recursive MOVED responses. See #882.
|
136
|
+
* Increase buffer size in the ruby connector. See #880.
|
137
|
+
* Fix thread safety of `Redis.queue`. See #878.
|
138
|
+
* Deprecate `Redis::Future#==` as it's likely to be a mistake. See #876.
|
139
|
+
* Support `KEEPTTL` option for SET command. See #913.
|
140
|
+
|
141
|
+
# 4.1.3
|
142
|
+
|
143
|
+
* Fix the client hanging forever when connecting with SSL to a non-SSL server. See #835.
|
144
|
+
|
145
|
+
# 4.1.2
|
146
|
+
|
147
|
+
* Fix several authentication problems with sentinel. See #850 and #856.
|
148
|
+
* Explicitly drop Ruby 2.2 support.
|
149
|
+
|
150
|
+
|
151
|
+
# 4.1.1
|
152
|
+
|
153
|
+
* Fix error handling in multi blocks. See #754.
|
154
|
+
* Fix geoadd to accept arrays like georadius and georadiusbymember. See #841.
|
155
|
+
* Fix georadius command failing when long == lat. See #841.
|
156
|
+
* Fix timeout error in xread block: 0. See #837.
|
157
|
+
* Fix incompatibility issue with redis-objects. See #834.
|
158
|
+
* Properly handle Errno::EADDRNOTAVAIL on connect.
|
159
|
+
* Fix password authentication to sentinel instances. See #813.
|
160
|
+
|
3
161
|
# 4.1.0
|
4
162
|
|
5
163
|
* Add Redis Cluster support. See #716.
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
# redis-rb [![Build Status][
|
1
|
+
# redis-rb [![Build Status][gh-actions-image]][gh-actions-link] [![Inline docs][inchpages-image]][inchpages-link]
|
2
2
|
|
3
3
|
A Ruby client that tries to match [Redis][redis-home]' API one-to-one, while still
|
4
4
|
providing an idiomatic interface.
|
5
5
|
|
6
|
+
See [RubyDoc.info][rubydoc] for the API docs of the latest published gem.
|
6
7
|
|
7
8
|
## Getting started
|
8
9
|
|
@@ -34,6 +35,9 @@ You can also specify connection options as a [`redis://` URL][redis-url]:
|
|
34
35
|
redis = Redis.new(url: "redis://:p4ssw0rd@10.0.1.1:6380/15")
|
35
36
|
```
|
36
37
|
|
38
|
+
The client expects passwords with special chracters to be URL-encoded (i.e.
|
39
|
+
`CGI.escape(password)`).
|
40
|
+
|
37
41
|
By default, the client will try to read the `REDIS_URL` environment variable
|
38
42
|
and use that as URL to connect to. The above statement is therefore equivalent
|
39
43
|
to setting this environment variable and calling `Redis.new` without arguments.
|
@@ -50,6 +54,12 @@ To connect to a password protected Redis instance, use:
|
|
50
54
|
redis = Redis.new(password: "mysecret")
|
51
55
|
```
|
52
56
|
|
57
|
+
To connect a Redis instance using [ACL](https://redis.io/topics/acl), use:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
redis = Redis.new(username: 'myname', password: 'mysecret')
|
61
|
+
```
|
62
|
+
|
53
63
|
The Redis class exports methods that are named identical to the commands
|
54
64
|
they execute. The arguments these methods accept are often identical to
|
55
65
|
the arguments specified on the [Redis website][redis-commands]. For
|
@@ -95,10 +105,60 @@ but a few so that if one is down the client will try the next one. The client
|
|
95
105
|
is able to remember the last Sentinel that was able to reply correctly and will
|
96
106
|
use it for the next requests.
|
97
107
|
|
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.
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
SENTINELS = [{ host: '127.0.0.1', port: 26380, password: 'mysecret' },
|
112
|
+
{ host: '127.0.0.1', port: 26381, password: 'mysecret' }]
|
113
|
+
|
114
|
+
redis = Redis.new(host: 'mymaster', sentinels: SENTINELS, role: :master)
|
115
|
+
```
|
116
|
+
|
117
|
+
## Cluster support
|
118
|
+
|
119
|
+
`redis-rb` supports [clustering](https://redis.io/topics/cluster-spec).
|
120
|
+
|
121
|
+
```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)
|
125
|
+
|
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 } }
|
128
|
+
```
|
129
|
+
|
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.
|
131
|
+
|
132
|
+
```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.
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
Redis.new(cluster: nodes, replica: true)
|
140
|
+
```
|
141
|
+
|
142
|
+
The calling code is responsible for [avoiding cross slot commands](https://redis.io/topics/cluster-spec#keys-distribution-model).
|
143
|
+
|
144
|
+
```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]
|
152
|
+
```
|
153
|
+
|
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
|
+
|
98
158
|
## Storing objects
|
99
159
|
|
100
|
-
Redis
|
101
|
-
|
160
|
+
Redis "string" types can be used to store serialized Ruby objects, for
|
161
|
+
example with JSON:
|
102
162
|
|
103
163
|
```ruby
|
104
164
|
require "json"
|
@@ -124,9 +184,9 @@ commands to Redis and gathers their replies. These replies are returned
|
|
124
184
|
by the `#pipelined` method.
|
125
185
|
|
126
186
|
```ruby
|
127
|
-
redis.pipelined do
|
128
|
-
|
129
|
-
|
187
|
+
redis.pipelined do |pipeline|
|
188
|
+
pipeline.set "foo", "bar"
|
189
|
+
pipeline.incr "baz"
|
130
190
|
end
|
131
191
|
# => ["OK", 1]
|
132
192
|
```
|
@@ -140,9 +200,9 @@ the regular pipeline, the replies to the commands are returned by the
|
|
140
200
|
`#multi` method.
|
141
201
|
|
142
202
|
```ruby
|
143
|
-
redis.multi do
|
144
|
-
|
145
|
-
|
203
|
+
redis.multi do |transaction|
|
204
|
+
transaction.set "foo", "bar"
|
205
|
+
transaction.incr "baz"
|
146
206
|
end
|
147
207
|
# => ["OK", 1]
|
148
208
|
```
|
@@ -150,15 +210,15 @@ end
|
|
150
210
|
### Futures
|
151
211
|
|
152
212
|
Replies to commands in a pipeline can be accessed via the *futures* they
|
153
|
-
emit (since redis-rb 3.0). All calls
|
213
|
+
emit (since redis-rb 3.0). All calls on the pipeline object return a
|
154
214
|
`Future` object, which responds to the `#value` method. When the
|
155
215
|
pipeline has successfully executed, all futures are assigned their
|
156
216
|
respective replies and can be used.
|
157
217
|
|
158
218
|
```ruby
|
159
|
-
redis.pipelined do
|
160
|
-
@set =
|
161
|
-
@incr =
|
219
|
+
redis.pipelined do |pipeline|
|
220
|
+
@set = pipeline.set "foo", "bar"
|
221
|
+
@incr = pipeline.incr "baz"
|
162
222
|
end
|
163
223
|
|
164
224
|
@set.value
|
@@ -211,6 +271,7 @@ All timeout values are specified in seconds.
|
|
211
271
|
When using pub/sub, you can subscribe to a channel using a timeout as well:
|
212
272
|
|
213
273
|
```ruby
|
274
|
+
redis = Redis.new(reconnect_attempts: 0)
|
214
275
|
redis.subscribe_with_timeout(5, "news") do |on|
|
215
276
|
on.message do |channel, message|
|
216
277
|
# ...
|
@@ -272,7 +333,7 @@ This library supports natively terminating client side SSL/TLS connections
|
|
272
333
|
when talking to Redis via a server-side proxy such as [stunnel], [hitch],
|
273
334
|
or [ghostunnel].
|
274
335
|
|
275
|
-
To enable SSL support, pass the `:ssl =>
|
336
|
+
To enable SSL support, pass the `:ssl => true` option when configuring the
|
276
337
|
Redis client, or pass in `:url => "rediss://..."` (like HTTPS for Redis).
|
277
338
|
You will also need to pass in an `:ssl_params => { ... }` hash used to
|
278
339
|
configure the `OpenSSL::SSL::SSLContext` object used for the connection:
|
@@ -385,7 +446,11 @@ redis = Redis.new(:driver => :synchrony)
|
|
385
446
|
## Testing
|
386
447
|
|
387
448
|
This library is tested against recent Ruby and Redis versions.
|
388
|
-
Check [
|
449
|
+
Check [Github Actions][gh-actions-link] for the exact versions supported.
|
450
|
+
|
451
|
+
## See Also
|
452
|
+
|
453
|
+
- [async-redis](https://github.com/socketry/async-redis) — An [async](https://github.com/socketry/async) compatible Redis client.
|
389
454
|
|
390
455
|
## Contributors
|
391
456
|
|
@@ -397,15 +462,14 @@ client and evangelized Redis in Rubyland. Thank you, Ezra.
|
|
397
462
|
## Contributing
|
398
463
|
|
399
464
|
[Fork the project](https://github.com/redis/redis-rb) and send pull
|
400
|
-
requests.
|
401
|
-
|
402
|
-
|
403
|
-
[inchpages-image]:
|
404
|
-
[inchpages-link]:
|
405
|
-
[redis-commands]:
|
406
|
-
[redis-home]:
|
407
|
-
[redis-url]:
|
408
|
-
[
|
409
|
-
[
|
410
|
-
[
|
411
|
-
[rubydoc]: http://www.rubydoc.info/gems/redis
|
465
|
+
requests.
|
466
|
+
|
467
|
+
|
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
|