redis 3.3.5 → 4.8.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 +232 -2
- data/README.md +169 -89
- data/lib/redis/client.rb +177 -100
- data/lib/redis/cluster/command.rb +79 -0
- data/lib/redis/cluster/command_loader.rb +33 -0
- data/lib/redis/cluster/key_slot_converter.rb +72 -0
- data/lib/redis/cluster/node.rb +120 -0
- data/lib/redis/cluster/node_key.rb +31 -0
- data/lib/redis/cluster/node_loader.rb +34 -0
- data/lib/redis/cluster/option.rb +100 -0
- data/lib/redis/cluster/slot.rb +86 -0
- data/lib/redis/cluster/slot_loader.rb +46 -0
- data/lib/redis/cluster.rb +315 -0
- 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 +455 -0
- data/lib/redis/commands/lists.rb +290 -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 +223 -0
- data/lib/redis/commands/sorted_sets.rb +812 -0
- data/lib/redis/commands/streams.rb +382 -0
- data/lib/redis/commands/strings.rb +313 -0
- data/lib/redis/commands/transactions.rb +139 -0
- data/lib/redis/commands.rb +240 -0
- data/lib/redis/connection/command_helper.rb +7 -10
- data/lib/redis/connection/hiredis.rb +5 -3
- data/lib/redis/connection/registry.rb +2 -1
- data/lib/redis/connection/ruby.rb +136 -128
- data/lib/redis/connection/synchrony.rb +24 -9
- data/lib/redis/connection.rb +3 -1
- data/lib/redis/distributed.rb +255 -85
- data/lib/redis/errors.rb +57 -0
- data/lib/redis/hash_ring.rb +30 -73
- data/lib/redis/pipeline.rb +178 -13
- data/lib/redis/subscribe.rb +11 -12
- data/lib/redis/version.rb +3 -1
- data/lib/redis.rb +174 -2661
- metadata +66 -202
- data/.gitignore +0 -16
- data/.travis/Gemfile +0 -11
- data/.travis.yml +0 -89
- data/.yardopts +0 -3
- data/Gemfile +0 -4
- data/Rakefile +0 -87
- data/benchmarking/logging.rb +0 -71
- data/benchmarking/pipeline.rb +0 -51
- data/benchmarking/speed.rb +0 -21
- data/benchmarking/suite.rb +0 -24
- data/benchmarking/worker.rb +0 -71
- data/examples/basic.rb +0 -15
- data/examples/consistency.rb +0 -114
- data/examples/dist_redis.rb +0 -43
- data/examples/incr-decr.rb +0 -17
- data/examples/list.rb +0 -26
- data/examples/pubsub.rb +0 -37
- data/examples/sentinel/sentinel.conf +0 -9
- data/examples/sentinel/start +0 -49
- data/examples/sentinel.rb +0 -41
- data/examples/sets.rb +0 -36
- data/examples/unicorn/config.ru +0 -3
- data/examples/unicorn/unicorn.rb +0 -20
- data/redis.gemspec +0 -44
- data/test/bitpos_test.rb +0 -69
- data/test/blocking_commands_test.rb +0 -42
- data/test/client_test.rb +0 -59
- data/test/command_map_test.rb +0 -30
- data/test/commands_on_hashes_test.rb +0 -21
- data/test/commands_on_hyper_log_log_test.rb +0 -21
- data/test/commands_on_lists_test.rb +0 -20
- data/test/commands_on_sets_test.rb +0 -77
- data/test/commands_on_sorted_sets_test.rb +0 -137
- data/test/commands_on_strings_test.rb +0 -101
- data/test/commands_on_value_types_test.rb +0 -133
- data/test/connection_handling_test.rb +0 -277
- data/test/connection_test.rb +0 -57
- data/test/db/.gitkeep +0 -0
- data/test/distributed_blocking_commands_test.rb +0 -46
- data/test/distributed_commands_on_hashes_test.rb +0 -10
- data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
- data/test/distributed_commands_on_lists_test.rb +0 -22
- data/test/distributed_commands_on_sets_test.rb +0 -83
- data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
- data/test/distributed_commands_on_strings_test.rb +0 -59
- data/test/distributed_commands_on_value_types_test.rb +0 -95
- data/test/distributed_commands_requiring_clustering_test.rb +0 -164
- data/test/distributed_connection_handling_test.rb +0 -23
- data/test/distributed_internals_test.rb +0 -79
- data/test/distributed_key_tags_test.rb +0 -52
- data/test/distributed_persistence_control_commands_test.rb +0 -26
- data/test/distributed_publish_subscribe_test.rb +0 -92
- data/test/distributed_remote_server_control_commands_test.rb +0 -66
- data/test/distributed_scripting_test.rb +0 -102
- data/test/distributed_sorting_test.rb +0 -20
- data/test/distributed_test.rb +0 -58
- data/test/distributed_transactions_test.rb +0 -32
- data/test/encoding_test.rb +0 -18
- data/test/error_replies_test.rb +0 -59
- data/test/fork_safety_test.rb +0 -65
- data/test/helper.rb +0 -232
- data/test/helper_test.rb +0 -24
- data/test/internals_test.rb +0 -417
- data/test/lint/blocking_commands.rb +0 -150
- data/test/lint/hashes.rb +0 -162
- data/test/lint/hyper_log_log.rb +0 -60
- data/test/lint/lists.rb +0 -143
- data/test/lint/sets.rb +0 -140
- data/test/lint/sorted_sets.rb +0 -316
- data/test/lint/strings.rb +0 -260
- data/test/lint/value_types.rb +0 -122
- data/test/persistence_control_commands_test.rb +0 -26
- data/test/pipelining_commands_test.rb +0 -242
- data/test/publish_subscribe_test.rb +0 -282
- data/test/remote_server_control_commands_test.rb +0 -118
- data/test/scanning_test.rb +0 -413
- data/test/scripting_test.rb +0 -78
- data/test/sentinel_command_test.rb +0 -80
- data/test/sentinel_test.rb +0 -255
- data/test/sorting_test.rb +0 -59
- data/test/ssl_test.rb +0 -73
- data/test/support/connection/hiredis.rb +0 -1
- data/test/support/connection/ruby.rb +0 -1
- data/test/support/connection/synchrony.rb +0 -17
- data/test/support/redis_mock.rb +0 -130
- data/test/support/ssl/gen_certs.sh +0 -31
- data/test/support/ssl/trusted-ca.crt +0 -25
- data/test/support/ssl/trusted-ca.key +0 -27
- data/test/support/ssl/trusted-cert.crt +0 -81
- data/test/support/ssl/trusted-cert.key +0 -28
- data/test/support/ssl/untrusted-ca.crt +0 -26
- data/test/support/ssl/untrusted-ca.key +0 -27
- data/test/support/ssl/untrusted-cert.crt +0 -82
- data/test/support/ssl/untrusted-cert.key +0 -28
- data/test/support/wire/synchrony.rb +0 -24
- data/test/support/wire/thread.rb +0 -5
- data/test/synchrony_driver.rb +0 -88
- data/test/test.conf.erb +0 -9
- data/test/thread_safety_test.rb +0 -62
- data/test/transactions_test.rb +0 -264
- data/test/unknown_commands_test.rb +0 -14
- data/test/url_param_test.rb +0 -138
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c93b88c9766f0ba965110f61ff1e5cb3adcf378a515a9cdb7c345ef56159f98a
|
4
|
+
data.tar.gz: 6fa82d53bef3b0be6a5d192a925dfbd1e7585e66a5313605e631a1cf8585bf95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d2b5d59615cfdc2ec756c16560b88d3f968193d7ac1c827574b775b202f3f63b9d3ab9748c89cae5d82471063a1aded9f82557b86f850b0a58a180d404ee15c
|
7
|
+
data.tar.gz: 866c1968b84397450ca8882175240c345bf2dfb3a88fa4579d78c7ce8ee581226a0eb6007ac6de638dfc654eca15bf045e6f1860c187e5d736b196cac8b721c9
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,238 @@
|
|
1
|
+
# Unreleased
|
2
|
+
|
3
|
+
# 4.8.0
|
4
|
+
|
5
|
+
* Introduce `sadd?` and `srem?` as boolean returning versions of `sadd` and `srem`.
|
6
|
+
* Deprecate `sadd` and `srem` returning a boolean when called with a single argument.
|
7
|
+
To enable the redis 5.0 behavior you can set `Redis.sadd_returns_boolean = true`.
|
8
|
+
* Deprecate passing `timeout` as a positional argument in blocking commands (`brpop`, `blop`, etc).
|
9
|
+
|
10
|
+
# 4.7.1
|
11
|
+
|
12
|
+
* Gracefully handle OpenSSL 3.0 EOF Errors (`OpenSSL::SSL::SSLError: SSL_read: unexpected eof while reading`). See #1106
|
13
|
+
This happens frequently on heroku-22.
|
14
|
+
|
15
|
+
# 4.7.0
|
16
|
+
|
17
|
+
* Support single endpoint architecture with SSL/TLS in cluster mode. See #1086.
|
18
|
+
* `zrem` and `zadd` act as noop when provided an empty list of keys. See #1097.
|
19
|
+
* Support IPv6 URLs.
|
20
|
+
* Add `Redis#with` for better compatibility with `connection_pool` usage.
|
21
|
+
* Fix the block form of `multi` called inside `pipelined`. Previously the `MUTLI/EXEC` wouldn't be sent. See #1073.
|
22
|
+
|
23
|
+
# 4.6.0
|
24
|
+
|
25
|
+
* Deprecate `Redis.current`.
|
26
|
+
* Deprecate calling commands on `Redis` inside `Redis#pipelined`. See #1059.
|
27
|
+
```ruby
|
28
|
+
redis.pipelined do
|
29
|
+
redis.get("key")
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
should be replaced by:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
redis.pipelined do |pipeline|
|
37
|
+
pipeline.get("key")
|
38
|
+
end
|
39
|
+
```
|
40
|
+
* Deprecate calling commands on `Redis` inside `Redis#multi`. See #1059.
|
41
|
+
```ruby
|
42
|
+
redis.multi do
|
43
|
+
redis.get("key")
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
should be replaced by:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
redis.multi do |transaction|
|
51
|
+
transaction.get("key")
|
52
|
+
end
|
53
|
+
```
|
54
|
+
* Deprecate `Redis#queue` and `Redis#commit`. See #1059.
|
55
|
+
|
56
|
+
* Fix `zpopmax` and `zpopmin` when called inside a pipeline. See #1055.
|
57
|
+
* `Redis#synchronize` is now private like it should always have been.
|
58
|
+
|
59
|
+
* Add `Redis.silence_deprecations=` to turn off deprecation warnings.
|
60
|
+
If you don't wish to see warnings yet, you can set `Redis.silence_deprecations = true`.
|
61
|
+
It is however heavily recommended to fix them instead when possible.
|
62
|
+
* Add `Redis.raise_deprecations=` to turn deprecation warnings into errors.
|
63
|
+
This makes it easier to identitify the source of deprecated APIs usage.
|
64
|
+
It is recommended to set `Redis.raise_deprecations = true` in development and test environments.
|
65
|
+
* Add new options to ZRANGE. See #1053.
|
66
|
+
* Add ZRANGESTORE command. See #1053.
|
67
|
+
* Add SCAN support for `Redis::Cluster`. See #1049.
|
68
|
+
* Add COPY command. See #1053. See #1048.
|
69
|
+
* Add ZDIFFSTORE command. See #1046.
|
70
|
+
* Add ZDIFF command. See #1044.
|
71
|
+
* Add ZUNION command. See #1042.
|
72
|
+
* Add HRANDFIELD command. See #1040.
|
73
|
+
|
74
|
+
# 4.5.1
|
75
|
+
|
76
|
+
* 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,
|
77
|
+
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.
|
78
|
+
This behavior is deprecated and will be removed in Redis 4.6.0. Fix #1038.
|
79
|
+
|
80
|
+
# 4.5.0
|
81
|
+
|
82
|
+
* Handle parts of the command using incompatible encodings. See #1037.
|
83
|
+
* Add GET option to SET command. See #1036.
|
84
|
+
* Add ZRANDMEMBER command. See #1035.
|
85
|
+
* Add LMOVE/BLMOVE commands. See #1034.
|
86
|
+
* Add ZMSCORE command. See #1032.
|
87
|
+
* Add LT/GT options to ZADD. See #1033.
|
88
|
+
* Add SMISMEMBER command. See #1031.
|
89
|
+
* Add EXAT/PXAT options to SET. See #1028.
|
90
|
+
* Add GETDEL/GETEX commands. See #1024.
|
91
|
+
* `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`.
|
92
|
+
* Fix Redis < 6 detection during connect. See #1025.
|
93
|
+
* Fix fetching command details in Redis cluster when the first node is unhealthy. See #1026.
|
94
|
+
|
95
|
+
# 4.4.0
|
96
|
+
|
97
|
+
* Redis cluster: fix cross-slot validation in pipelines. Fix ##1019.
|
98
|
+
* Add support for `XAUTOCLAIM`. See #1018.
|
99
|
+
* Properly issue `READONLY` when reconnecting to replicas. Fix #1017.
|
100
|
+
* Make `del` a noop if passed an empty list of keys. See #998.
|
101
|
+
* Add support for `ZINTER`. See #995.
|
102
|
+
|
103
|
+
# 4.3.1
|
104
|
+
|
105
|
+
* Fix password authentication against redis server 5 and older.
|
106
|
+
|
107
|
+
# 4.3.0
|
108
|
+
|
109
|
+
* Add the TYPE argument to scan and scan_each. See #985.
|
110
|
+
* Support AUTH command for ACL. See #967.
|
111
|
+
|
112
|
+
# 4.2.5
|
113
|
+
|
114
|
+
* Optimize the ruby connector write buffering. See #964.
|
115
|
+
|
116
|
+
# 4.2.4
|
117
|
+
|
118
|
+
* Fix bytesize calculations in the ruby connector, and work on a copy of the buffer. Fix #961, #962.
|
119
|
+
|
120
|
+
# 4.2.3
|
121
|
+
|
122
|
+
* Use io/wait instead of IO.select in the ruby connector. See #960.
|
123
|
+
* Use exception free non blocking IOs in the ruby connector. See #926.
|
124
|
+
* Prevent corruption of the client when an interrupt happen during inside a pipeline block. See #945.
|
125
|
+
|
126
|
+
# 4.2.2
|
127
|
+
|
128
|
+
* Fix `WATCH` support for `Redis::Distributed`. See #941.
|
129
|
+
* Fix handling of empty stream responses. See #905, #929.
|
130
|
+
|
131
|
+
# 4.2.1
|
132
|
+
|
133
|
+
* Fix `exists?` returning an actual boolean when called with multiple keys. See #918.
|
134
|
+
* Setting `Redis.exists_returns_integer = false` disables warning message about new behaviour. See #920.
|
135
|
+
|
136
|
+
# 4.2.0
|
137
|
+
|
138
|
+
* Convert commands to accept keyword arguments rather than option hashes. This both help catching typos, and reduce needless allocations.
|
139
|
+
* Deprecate the synchrony driver. It will be removed in 5.0 and hopefully maintained as a separate gem. See #915.
|
140
|
+
* Make `Redis#exists` variadic, will return an Integer if called with multiple keys.
|
141
|
+
* Add `Redis#exists?` to get a Boolean if any of the keys exists.
|
142
|
+
* `Redis#exists` when called with a single key will warn that future versions will return an Integer.
|
143
|
+
Set `Redis.exists_returns_integer = true` to opt-in to the new behavior.
|
144
|
+
* Support `keepttl` ooption in `set`. See #913.
|
145
|
+
* Optimized initialization of Redis::Cluster. See #912.
|
146
|
+
* Accept sentinel options even with string key. See #599.
|
147
|
+
* Verify TLS connections by default. See #900.
|
148
|
+
* Make `Redis#hset` variadic. It now returns an integer, not a boolean. See #910.
|
149
|
+
|
150
|
+
# 4.1.4
|
151
|
+
|
152
|
+
* Alias `Redis#disconnect` as `#close`. See #901.
|
153
|
+
* Handle clusters with multiple slot ranges. See #894.
|
154
|
+
* Fix password authentication to a redis cluster. See #889.
|
155
|
+
* Handle recursive MOVED responses. See #882.
|
156
|
+
* Increase buffer size in the ruby connector. See #880.
|
157
|
+
* Fix thread safety of `Redis.queue`. See #878.
|
158
|
+
* Deprecate `Redis::Future#==` as it's likely to be a mistake. See #876.
|
159
|
+
* Support `KEEPTTL` option for SET command. See #913.
|
160
|
+
|
161
|
+
# 4.1.3
|
162
|
+
|
163
|
+
* Fix the client hanging forever when connecting with SSL to a non-SSL server. See #835.
|
164
|
+
|
165
|
+
# 4.1.2
|
166
|
+
|
167
|
+
* Fix several authentication problems with sentinel. See #850 and #856.
|
168
|
+
* Explicitly drop Ruby 2.2 support.
|
169
|
+
|
170
|
+
|
171
|
+
# 4.1.1
|
172
|
+
|
173
|
+
* Fix error handling in multi blocks. See #754.
|
174
|
+
* Fix geoadd to accept arrays like georadius and georadiusbymember. See #841.
|
175
|
+
* Fix georadius command failing when long == lat. See #841.
|
176
|
+
* Fix timeout error in xread block: 0. See #837.
|
177
|
+
* Fix incompatibility issue with redis-objects. See #834.
|
178
|
+
* Properly handle Errno::EADDRNOTAVAIL on connect.
|
179
|
+
* Fix password authentication to sentinel instances. See #813.
|
180
|
+
|
181
|
+
# 4.1.0
|
182
|
+
|
183
|
+
* Add Redis Cluster support. See #716.
|
184
|
+
* Add streams support. See #799 and #811.
|
185
|
+
* Add ZPOP* support. See #812.
|
186
|
+
* Fix issues with integer-like objects as BPOP timeout
|
187
|
+
|
188
|
+
# 4.0.3
|
189
|
+
|
190
|
+
* Fix raising command error for first command in pipeline. See #788.
|
191
|
+
* Fix the gemspec to stop exposing a `build` executable. See #785.
|
192
|
+
* Add `:reconnect_delay` and `:reconnect_delay_max` options. See #778.
|
193
|
+
|
194
|
+
# 4.0.2
|
195
|
+
|
196
|
+
* Added `Redis#unlink`. See #766.
|
197
|
+
|
198
|
+
* `Redis.new` now accept a custom connector via `:connector`. See #591.
|
199
|
+
|
200
|
+
* `Redis#multi` no longer perform empty transactions. See #747.
|
201
|
+
|
202
|
+
* `Redis#hdel` now accepts hash keys as multiple arguments like `#del`. See #755.
|
203
|
+
|
204
|
+
* Allow to skip SSL verification. See #745.
|
205
|
+
|
206
|
+
* Add Geo commands: `geoadd`, `geohash`, `georadius`, `georadiusbymember`, `geopos`, `geodist`. See #730.
|
207
|
+
|
208
|
+
# 4.0.1
|
209
|
+
|
210
|
+
* `Redis::Distributed` now supports `mget` and `mapped_mget`. See #687.
|
211
|
+
|
212
|
+
* `Redis::Distributed` now supports `sscan` and `sscan_each`. See #572.
|
213
|
+
|
214
|
+
* `Redis#connection` returns a hash with connection information.
|
215
|
+
You shouldn't need to call `Redis#_client`, ever.
|
216
|
+
|
217
|
+
* `Redis#flushdb` and `Redis#flushall` now support the `:async` option. See #706.
|
218
|
+
|
219
|
+
|
220
|
+
# 4.0
|
221
|
+
|
222
|
+
* Removed `Redis.connect`. Use `Redis.new`.
|
223
|
+
|
224
|
+
* Removed `Redis#[]` and `Redis#[]=` aliases.
|
225
|
+
|
226
|
+
* Added support for `CLIENT` commands. The lower-level client can be
|
227
|
+
accessed via `Redis#_client`.
|
228
|
+
|
229
|
+
* Dropped official support for Ruby < 2.2.2.
|
230
|
+
|
1
231
|
# 3.3.5
|
2
232
|
|
3
233
|
* Fixed Ruby 1.8 compatibility after backporting `Redis#connection`. See #719.
|
4
234
|
|
5
|
-
# 3.3.4
|
235
|
+
# 3.3.4 (yanked)
|
6
236
|
|
7
237
|
* `Redis#connection` returns a hash with connection information.
|
8
238
|
You shouldn't need to call `Redis#_client`, ever.
|
@@ -13,7 +243,7 @@
|
|
13
243
|
|
14
244
|
# 3.3.2
|
15
245
|
|
16
|
-
* Added support for SPOP with COUNT. See #628.
|
246
|
+
* Added support for `SPOP` with COUNT. See #628.
|
17
247
|
|
18
248
|
* Fixed connection glitches when using SSL. See #644.
|
19
249
|
|
data/README.md
CHANGED
@@ -1,46 +1,18 @@
|
|
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
|
-
[
|
4
|
-
|
5
|
-
[travis-home]: http://travis-ci.org/
|
6
|
-
[inchpages-image]: http://inch-ci.org/github/redis/redis-rb.png
|
7
|
-
[inchpages-link]: http://inch-ci.org/github/redis/redis-rb
|
3
|
+
A Ruby client that tries to match [Redis][redis-home]' API one-to-one, while still
|
4
|
+
providing an idiomatic interface.
|
8
5
|
|
9
|
-
|
10
|
-
|
11
|
-
[redis-home]: http://redis.io
|
12
|
-
|
13
|
-
A Ruby client that tries to match Redis' API one-to-one, while still
|
14
|
-
providing an idiomatic interface. It features thread-safety, client-side
|
15
|
-
sharding, pipelining, and an obsession for performance.
|
16
|
-
|
17
|
-
## Upgrading from 2.x to 3.0
|
18
|
-
|
19
|
-
Please refer to the [CHANGELOG][changelog-3.0.0] for a summary of the
|
20
|
-
most important changes, as well as a full list of changes.
|
21
|
-
|
22
|
-
[changelog-3.0.0]: https://github.com/redis/redis-rb/blob/master/CHANGELOG.md#300
|
6
|
+
See [RubyDoc.info][rubydoc] for the API docs of the latest published gem.
|
23
7
|
|
24
8
|
## Getting started
|
25
9
|
|
26
|
-
|
27
|
-
|
28
|
-
```
|
29
|
-
gem install redis
|
30
|
-
```
|
31
|
-
|
32
|
-
Or if you are using **bundler**, add
|
10
|
+
Install with:
|
33
11
|
|
34
12
|
```
|
35
|
-
|
13
|
+
$ gem install redis
|
36
14
|
```
|
37
15
|
|
38
|
-
to your `Gemfile`, and run `bundle install`
|
39
|
-
|
40
|
-
As of version 2.0 this client only targets Redis version 2.0 and higher.
|
41
|
-
You can use an older version of this client if you need to interface
|
42
|
-
with a Redis instance older than 2.0, but this is no longer supported.
|
43
|
-
|
44
16
|
You can connect to Redis by instantiating the `Redis` class:
|
45
17
|
|
46
18
|
```ruby
|
@@ -54,16 +26,17 @@ listening on `localhost`, port 6379. If you need to connect to a remote
|
|
54
26
|
server or a different port, try:
|
55
27
|
|
56
28
|
```ruby
|
57
|
-
redis = Redis.new(:
|
29
|
+
redis = Redis.new(host: "10.0.1.1", port: 6380, db: 15)
|
58
30
|
```
|
59
31
|
|
60
32
|
You can also specify connection options as a [`redis://` URL][redis-url]:
|
61
33
|
|
62
34
|
```ruby
|
63
|
-
redis = Redis.new(:
|
35
|
+
redis = Redis.new(url: "redis://:p4ssw0rd@10.0.1.1:6380/15")
|
64
36
|
```
|
65
37
|
|
66
|
-
|
38
|
+
The client expects passwords with special chracters to be URL-encoded (i.e.
|
39
|
+
`CGI.escape(password)`).
|
67
40
|
|
68
41
|
By default, the client will try to read the `REDIS_URL` environment variable
|
69
42
|
and use that as URL to connect to. The above statement is therefore equivalent
|
@@ -72,13 +45,19 @@ to setting this environment variable and calling `Redis.new` without arguments.
|
|
72
45
|
To connect to Redis listening on a Unix socket, try:
|
73
46
|
|
74
47
|
```ruby
|
75
|
-
redis = Redis.new(:
|
48
|
+
redis = Redis.new(path: "/tmp/redis.sock")
|
76
49
|
```
|
77
50
|
|
78
51
|
To connect to a password protected Redis instance, use:
|
79
52
|
|
80
53
|
```ruby
|
81
|
-
redis = Redis.new(:
|
54
|
+
redis = Redis.new(password: "mysecret")
|
55
|
+
```
|
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')
|
82
61
|
```
|
83
62
|
|
84
63
|
The Redis class exports methods that are named identical to the commands
|
@@ -86,8 +65,6 @@ they execute. The arguments these methods accept are often identical to
|
|
86
65
|
the arguments specified on the [Redis website][redis-commands]. For
|
87
66
|
instance, the `SET` and `GET` commands can be called like this:
|
88
67
|
|
89
|
-
[redis-commands]: http://redis.io/commands
|
90
|
-
|
91
68
|
```ruby
|
92
69
|
redis.set("mykey", "hello world")
|
93
70
|
# => "OK"
|
@@ -96,24 +73,22 @@ redis.get("mykey")
|
|
96
73
|
# => "hello world"
|
97
74
|
```
|
98
75
|
|
99
|
-
All commands, their arguments and return values are documented
|
100
|
-
available on [
|
101
|
-
|
102
|
-
[rdoc]: http://rdoc.info/github/redis/redis-rb/
|
76
|
+
All commands, their arguments, and return values are documented and
|
77
|
+
available on [RubyDoc.info][rubydoc].
|
103
78
|
|
104
79
|
## Sentinel support
|
105
80
|
|
106
|
-
The client is able to perform automatic
|
81
|
+
The client is able to perform automatic failover by using [Redis
|
107
82
|
Sentinel](http://redis.io/topics/sentinel). Make sure to run Redis 2.8+
|
108
83
|
if you want to use this feature.
|
109
84
|
|
110
85
|
To connect using Sentinel, use:
|
111
86
|
|
112
87
|
```ruby
|
113
|
-
SENTINELS = [{:
|
114
|
-
{:
|
88
|
+
SENTINELS = [{ host: "127.0.0.1", port: 26380 },
|
89
|
+
{ host: "127.0.0.1", port: 26381 }]
|
115
90
|
|
116
|
-
redis = Redis.new(:
|
91
|
+
redis = Redis.new(url: "redis://mymaster", sentinels: SENTINELS, role: :master)
|
117
92
|
```
|
118
93
|
|
119
94
|
* The master name identifies a group of Redis instances composed of a master
|
@@ -130,10 +105,75 @@ but a few so that if one is down the client will try the next one. The client
|
|
130
105
|
is able to remember the last Sentinel that was able to reply correctly and will
|
131
106
|
use it for the next requests.
|
132
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
|
+
|
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
|
+
|
133
173
|
## Storing objects
|
134
174
|
|
135
|
-
Redis
|
136
|
-
|
175
|
+
Redis "string" types can be used to store serialized Ruby objects, for
|
176
|
+
example with JSON:
|
137
177
|
|
138
178
|
```ruby
|
139
179
|
require "json"
|
@@ -159,9 +199,9 @@ commands to Redis and gathers their replies. These replies are returned
|
|
159
199
|
by the `#pipelined` method.
|
160
200
|
|
161
201
|
```ruby
|
162
|
-
redis.pipelined do
|
163
|
-
|
164
|
-
|
202
|
+
redis.pipelined do |pipeline|
|
203
|
+
pipeline.set "foo", "bar"
|
204
|
+
pipeline.incr "baz"
|
165
205
|
end
|
166
206
|
# => ["OK", 1]
|
167
207
|
```
|
@@ -175,9 +215,9 @@ the regular pipeline, the replies to the commands are returned by the
|
|
175
215
|
`#multi` method.
|
176
216
|
|
177
217
|
```ruby
|
178
|
-
redis.multi do
|
179
|
-
|
180
|
-
|
218
|
+
redis.multi do |transaction|
|
219
|
+
transaction.set "foo", "bar"
|
220
|
+
transaction.incr "baz"
|
181
221
|
end
|
182
222
|
# => ["OK", 1]
|
183
223
|
```
|
@@ -185,15 +225,15 @@ end
|
|
185
225
|
### Futures
|
186
226
|
|
187
227
|
Replies to commands in a pipeline can be accessed via the *futures* they
|
188
|
-
emit (since redis-rb 3.0). All calls
|
228
|
+
emit (since redis-rb 3.0). All calls on the pipeline object return a
|
189
229
|
`Future` object, which responds to the `#value` method. When the
|
190
230
|
pipeline has successfully executed, all futures are assigned their
|
191
231
|
respective replies and can be used.
|
192
232
|
|
193
233
|
```ruby
|
194
|
-
redis.pipelined do
|
195
|
-
@set =
|
196
|
-
@incr =
|
234
|
+
redis.pipelined do |pipeline|
|
235
|
+
@set = pipeline.set "foo", "bar"
|
236
|
+
@incr = pipeline.incr "baz"
|
197
237
|
end
|
198
238
|
|
199
239
|
@set.value
|
@@ -211,7 +251,7 @@ it can't connect to the server a `Redis::CannotConnectError` error will be raise
|
|
211
251
|
```ruby
|
212
252
|
begin
|
213
253
|
redis.ping
|
214
|
-
rescue
|
254
|
+
rescue StandardError => e
|
215
255
|
e.inspect
|
216
256
|
# => #<Redis::CannotConnectError: Timed out connecting to Redis on 10.0.1.1:6380>
|
217
257
|
|
@@ -246,6 +286,7 @@ All timeout values are specified in seconds.
|
|
246
286
|
When using pub/sub, you can subscribe to a channel using a timeout as well:
|
247
287
|
|
248
288
|
```ruby
|
289
|
+
redis = Redis.new(reconnect_attempts: 0)
|
249
290
|
redis.subscribe_with_timeout(5, "news") do |on|
|
250
291
|
on.message do |channel, message|
|
251
292
|
# ...
|
@@ -255,6 +296,51 @@ end
|
|
255
296
|
|
256
297
|
If no message is received after 5 seconds, the client will unsubscribe.
|
257
298
|
|
299
|
+
## Reconnections
|
300
|
+
|
301
|
+
The client allows you to configure how many `reconnect_attempts` it should
|
302
|
+
complete before declaring a connection as failed. Furthermore, you may want
|
303
|
+
to control the maximum duration between reconnection attempts with
|
304
|
+
`reconnect_delay` and `reconnect_delay_max`.
|
305
|
+
|
306
|
+
```ruby
|
307
|
+
Redis.new(
|
308
|
+
:reconnect_attempts => 10,
|
309
|
+
:reconnect_delay => 1.5,
|
310
|
+
:reconnect_delay_max => 10.0,
|
311
|
+
)
|
312
|
+
```
|
313
|
+
|
314
|
+
The delay values are specified in seconds. With the above configuration, the
|
315
|
+
client would attempt 10 reconnections, exponentially increasing the duration
|
316
|
+
between each attempt but it never waits longer than `reconnect_delay_max`.
|
317
|
+
|
318
|
+
This is the retry algorithm:
|
319
|
+
|
320
|
+
```ruby
|
321
|
+
attempt_wait_time = [(reconnect_delay * 2**(attempt-1)), reconnect_delay_max].min
|
322
|
+
```
|
323
|
+
|
324
|
+
**By default**, this gem will only **retry a connection once** and then fail, but with the
|
325
|
+
above configuration the reconnection attempt would look like this:
|
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`.
|
258
344
|
|
259
345
|
## SSL/TLS Support
|
260
346
|
|
@@ -262,7 +348,7 @@ This library supports natively terminating client side SSL/TLS connections
|
|
262
348
|
when talking to Redis via a server-side proxy such as [stunnel], [hitch],
|
263
349
|
or [ghostunnel].
|
264
350
|
|
265
|
-
To enable SSL support, pass the `:ssl =>
|
351
|
+
To enable SSL support, pass the `:ssl => true` option when configuring the
|
266
352
|
Redis client, or pass in `:url => "rediss://..."` (like HTTPS for Redis).
|
267
353
|
You will also need to pass in an `:ssl_params => { ... }` hash used to
|
268
354
|
configure the `OpenSSL::SSL::SSLContext` object used for the connection:
|
@@ -374,37 +460,31 @@ redis = Redis.new(:driver => :synchrony)
|
|
374
460
|
|
375
461
|
## Testing
|
376
462
|
|
377
|
-
This library is tested
|
378
|
-
|
463
|
+
This library is tested against recent Ruby and Redis versions.
|
464
|
+
Check [Github Actions][gh-actions-link] for the exact versions supported.
|
465
|
+
|
466
|
+
## See Also
|
379
467
|
|
380
|
-
|
381
|
-
* MRI 1.9.3 (drivers: ruby, hiredis, synchrony)
|
382
|
-
* MRI 2.0 (drivers: ruby, hiredis, synchrony)
|
383
|
-
* MRI 2.1 (drivers: ruby, hiredis, synchrony)
|
384
|
-
* MRI 2.2 (drivers: ruby, hiredis, synchrony)
|
385
|
-
* MRI 2.3 (drivers: ruby, hiredis, synchrony)
|
386
|
-
* JRuby 1.7 (1.8 mode) (drivers: ruby)
|
387
|
-
* JRuby 1.7 (1.9 mode) (drivers: ruby)
|
468
|
+
- [async-redis](https://github.com/socketry/async-redis) — An [async](https://github.com/socketry/async) compatible Redis client.
|
388
469
|
|
389
470
|
## Contributors
|
390
471
|
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
* Taylor Weibley
|
396
|
-
* Matthew Clark
|
397
|
-
* Brian McKinney
|
398
|
-
* Luca Guidi
|
399
|
-
* Salvatore Sanfilippo
|
400
|
-
* Chris Wanstrath
|
401
|
-
* Damian Janowski
|
402
|
-
* Michel Martens
|
403
|
-
* Nick Quaranto
|
404
|
-
* Pieter Noordhuis
|
405
|
-
* Ilya Grigorik
|
472
|
+
Several people contributed to redis-rb, but we would like to especially
|
473
|
+
mention Ezra Zygmuntowicz. Ezra introduced the Ruby community to many
|
474
|
+
new cool technologies, like Redis. He wrote the first version of this
|
475
|
+
client and evangelized Redis in Rubyland. Thank you, Ezra.
|
406
476
|
|
407
477
|
## Contributing
|
408
478
|
|
409
479
|
[Fork the project](https://github.com/redis/redis-rb) and send pull
|
410
|
-
requests.
|
480
|
+
requests.
|
481
|
+
|
482
|
+
|
483
|
+
[inchpages-image]: https://inch-ci.org/github/redis/redis-rb.svg
|
484
|
+
[inchpages-link]: https://inch-ci.org/github/redis/redis-rb
|
485
|
+
[redis-commands]: https://redis.io/commands
|
486
|
+
[redis-home]: https://redis.io
|
487
|
+
[redis-url]: http://www.iana.org/assignments/uri-schemes/prov/redis
|
488
|
+
[gh-actions-image]: https://github.com/redis/redis-rb/workflows/Test/badge.svg
|
489
|
+
[gh-actions-link]: https://github.com/redis/redis-rb/actions
|
490
|
+
[rubydoc]: http://www.rubydoc.info/gems/redis
|