redis 4.1.3 → 4.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +1 -1
- data/lib/redis.rb +103 -102
- data/lib/redis/client.rb +1 -0
- data/lib/redis/cluster.rb +6 -4
- data/lib/redis/cluster/node_key.rb +3 -7
- data/lib/redis/cluster/option.rb +23 -13
- data/lib/redis/cluster/slot.rb +5 -2
- data/lib/redis/cluster/slot_loader.rb +5 -4
- data/lib/redis/connection.rb +1 -0
- data/lib/redis/connection/command_helper.rb +1 -0
- data/lib/redis/connection/hiredis.rb +1 -0
- data/lib/redis/connection/registry.rb +1 -0
- data/lib/redis/connection/ruby.rb +4 -3
- data/lib/redis/connection/synchrony.rb +1 -0
- data/lib/redis/distributed.rb +1 -0
- data/lib/redis/errors.rb +1 -0
- data/lib/redis/hash_ring.rb +1 -0
- data/lib/redis/pipeline.rb +15 -0
- data/lib/redis/subscribe.rb +1 -0
- data/lib/redis/version.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83f1f7270db68603d63e86ec43e68348cb5ccb2b4e6759642d89898566bdbaf6
|
4
|
+
data.tar.gz: 45c5bcc92629ec7d85cdc2b913e7922cd5425f2e6691891efc379aeec73026b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 692dfc5c73c6410492589f38f279976a023f6a2ff13f7b1476806011eb387f41bed784bdeac746de5f4b990b6d22bf297b36dddc7b8e448a842241a389f50796
|
7
|
+
data.tar.gz: 55a9e305c7563f5dd7d38f50dc7b919967dbb0f6a131ebc5e1569f49f196ab458203b6594394fa9a33ea9e337b741113e781378113783683dd36b87196607b8f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# 4.1.4
|
4
|
+
|
5
|
+
* Alias `Redis#disconnect` as `#close`. See #901.
|
6
|
+
* Handle clusters with multiple slot ranges. See #894.
|
7
|
+
* Fix password authentication to a redis cluster. See #889.
|
8
|
+
* Handle recursive MOVED responses. See #882.
|
9
|
+
* Increase buffer size in the ruby connector. See #880.
|
10
|
+
* Fix thread safety of `Redis.queue`. See #878.
|
11
|
+
* Deprecate `Redis::Future#==` as it's likely to be a mistake. See #876.
|
12
|
+
|
3
13
|
# 4.1.3
|
4
14
|
|
5
15
|
* Fix the client hanging forever when connecting with SSL to a non-SSL server. See #835.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# redis-rb [![Build Status][travis-image]][travis-link] [![Inline docs][inchpages-image]][inchpages-link]
|
1
|
+
# redis-rb [![Build Status][travis-image]][travis-link] [![Inline docs][inchpages-image]][inchpages-link] ![](https://github.com/redis/redis-rb/workflows/Test/badge.svg?branch=master)
|
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.
|
data/lib/redis.rb
CHANGED
@@ -4,7 +4,6 @@ require "monitor"
|
|
4
4
|
require_relative "redis/errors"
|
5
5
|
|
6
6
|
class Redis
|
7
|
-
|
8
7
|
def self.current
|
9
8
|
@current ||= Redis.new
|
10
9
|
end
|
@@ -20,16 +19,16 @@ class Redis
|
|
20
19
|
# @param [Hash] options
|
21
20
|
# @option options [String] :url (value of the environment variable REDIS_URL) a Redis URL, for a TCP connection: `redis://:[password]@[hostname]:[port]/[db]` (password, port and database are optional), for a unix socket connection: `unix://[path to Redis socket]`. This overrides all other options.
|
22
21
|
# @option options [String] :host ("127.0.0.1") server hostname
|
23
|
-
# @option options [
|
22
|
+
# @option options [Integer] :port (6379) server port
|
24
23
|
# @option options [String] :path path to server socket (overrides host and port)
|
25
24
|
# @option options [Float] :timeout (5.0) timeout in seconds
|
26
25
|
# @option options [Float] :connect_timeout (same as timeout) timeout for initial connect in seconds
|
27
26
|
# @option options [String] :password Password to authenticate against server
|
28
|
-
# @option options [
|
27
|
+
# @option options [Integer] :db (0) Database to select after initial connect
|
29
28
|
# @option options [Symbol] :driver Driver to use, currently supported: `:ruby`, `:hiredis`, `:synchrony`
|
30
29
|
# @option options [String] :id ID for the client connection, assigns name to current connection by sending `CLIENT SETNAME`
|
31
|
-
# @option options [Hash,
|
32
|
-
# @option options [
|
30
|
+
# @option options [Hash, Integer] :tcp_keepalive Keepalive values, if Integer `intvl` and `probe` are calculated based on the value, if Hash `time`, `intvl` and `probes` can be specified as a Integer
|
31
|
+
# @option options [Integer] :reconnect_attempts Number of attempts trying to connect
|
33
32
|
# @option options [Boolean] :inherit_socket (false) Whether to use socket in forked process or not
|
34
33
|
# @option options [Array] :sentinels List of sentinels to contact
|
35
34
|
# @option options [Symbol] :role (:master) Role to fetch via Sentinel, either `:master` or `:slave`
|
@@ -96,7 +95,9 @@ class Redis
|
|
96
95
|
# See http://redis.io/topics/pipelining for more details.
|
97
96
|
#
|
98
97
|
def queue(*command)
|
99
|
-
|
98
|
+
synchronize do
|
99
|
+
@queue[Thread.current.object_id] << command
|
100
|
+
end
|
100
101
|
end
|
101
102
|
|
102
103
|
# Sends all commands in the queue.
|
@@ -135,7 +136,7 @@ class Redis
|
|
135
136
|
|
136
137
|
# Change the selected database for the current connection.
|
137
138
|
#
|
138
|
-
# @param [
|
139
|
+
# @param [Integer] db zero-based index of the DB to use (0 to 15)
|
139
140
|
# @return [String] `OK`
|
140
141
|
def select(db)
|
141
142
|
synchronize do |client|
|
@@ -234,7 +235,7 @@ class Redis
|
|
234
235
|
|
235
236
|
# Return the number of keys in the selected database.
|
236
237
|
#
|
237
|
-
# @return [
|
238
|
+
# @return [Integer]
|
238
239
|
def dbsize
|
239
240
|
synchronize do |client|
|
240
241
|
client.call([:dbsize])
|
@@ -303,7 +304,7 @@ class Redis
|
|
303
304
|
|
304
305
|
# Get the UNIX time stamp of the last successful save to disk.
|
305
306
|
#
|
306
|
-
# @return [
|
307
|
+
# @return [Integer]
|
307
308
|
def lastsave
|
308
309
|
synchronize do |client|
|
309
310
|
client.call([:lastsave])
|
@@ -355,8 +356,8 @@ class Redis
|
|
355
356
|
# Interact with the slowlog (get, len, reset)
|
356
357
|
#
|
357
358
|
# @param [String] subcommand e.g. `get`, `len`, `reset`
|
358
|
-
# @param [
|
359
|
-
# @return [Array<String>,
|
359
|
+
# @param [Integer] length maximum number of entries to return
|
360
|
+
# @return [Array<String>, Integer, String] depends on subcommand
|
360
361
|
def slowlog(subcommand, length=nil)
|
361
362
|
synchronize do |client|
|
362
363
|
args = [:slowlog, subcommand]
|
@@ -377,7 +378,7 @@ class Redis
|
|
377
378
|
# @example
|
378
379
|
# r.time # => [ 1333093196, 606806 ]
|
379
380
|
#
|
380
|
-
# @return [Array<
|
381
|
+
# @return [Array<Integer>] tuple of seconds since UNIX epoch and
|
381
382
|
# microseconds in the current second
|
382
383
|
def time
|
383
384
|
synchronize do |client|
|
@@ -400,7 +401,7 @@ class Redis
|
|
400
401
|
# Set a key's time to live in seconds.
|
401
402
|
#
|
402
403
|
# @param [String] key
|
403
|
-
# @param [
|
404
|
+
# @param [Integer] seconds time to live
|
404
405
|
# @return [Boolean] whether the timeout was set or not
|
405
406
|
def expire(key, seconds)
|
406
407
|
synchronize do |client|
|
@@ -411,7 +412,7 @@ class Redis
|
|
411
412
|
# Set the expiration for a key as a UNIX timestamp.
|
412
413
|
#
|
413
414
|
# @param [String] key
|
414
|
-
# @param [
|
415
|
+
# @param [Integer] unix_time expiry time specified as a UNIX timestamp
|
415
416
|
# @return [Boolean] whether the timeout was set or not
|
416
417
|
def expireat(key, unix_time)
|
417
418
|
synchronize do |client|
|
@@ -422,7 +423,7 @@ class Redis
|
|
422
423
|
# Get the time to live (in seconds) for a key.
|
423
424
|
#
|
424
425
|
# @param [String] key
|
425
|
-
# @return [
|
426
|
+
# @return [Integer] remaining time to live in seconds.
|
426
427
|
#
|
427
428
|
# In Redis 2.6 or older the command returns -1 if the key does not exist or if
|
428
429
|
# the key exist but has no associated expire.
|
@@ -440,7 +441,7 @@ class Redis
|
|
440
441
|
# Set a key's time to live in milliseconds.
|
441
442
|
#
|
442
443
|
# @param [String] key
|
443
|
-
# @param [
|
444
|
+
# @param [Integer] milliseconds time to live
|
444
445
|
# @return [Boolean] whether the timeout was set or not
|
445
446
|
def pexpire(key, milliseconds)
|
446
447
|
synchronize do |client|
|
@@ -451,7 +452,7 @@ class Redis
|
|
451
452
|
# Set the expiration for a key as number of milliseconds from UNIX Epoch.
|
452
453
|
#
|
453
454
|
# @param [String] key
|
454
|
-
# @param [
|
455
|
+
# @param [Integer] ms_unix_time expiry time specified as number of milliseconds from UNIX Epoch.
|
455
456
|
# @return [Boolean] whether the timeout was set or not
|
456
457
|
def pexpireat(key, ms_unix_time)
|
457
458
|
synchronize do |client|
|
@@ -462,7 +463,7 @@ class Redis
|
|
462
463
|
# Get the time to live (in milliseconds) for a key.
|
463
464
|
#
|
464
465
|
# @param [String] key
|
465
|
-
# @return [
|
466
|
+
# @return [Integer] remaining time to live in milliseconds
|
466
467
|
# In Redis 2.6 or older the command returns -1 if the key does not exist or if
|
467
468
|
# the key exist but has no associated expire.
|
468
469
|
#
|
@@ -532,7 +533,7 @@ class Redis
|
|
532
533
|
# Delete one or more keys.
|
533
534
|
#
|
534
535
|
# @param [String, Array<String>] keys
|
535
|
-
# @return [
|
536
|
+
# @return [Integer] number of keys that were deleted
|
536
537
|
def del(*keys)
|
537
538
|
synchronize do |client|
|
538
539
|
client.call([:del] + keys)
|
@@ -542,7 +543,7 @@ class Redis
|
|
542
543
|
# Unlink one or more keys.
|
543
544
|
#
|
544
545
|
# @param [String, Array<String>] keys
|
545
|
-
# @return [
|
546
|
+
# @return [Integer] number of keys that were unlinked
|
546
547
|
def unlink(*keys)
|
547
548
|
synchronize do |client|
|
548
549
|
client.call([:unlink] + keys)
|
@@ -592,7 +593,7 @@ class Redis
|
|
592
593
|
# # => "bar"
|
593
594
|
#
|
594
595
|
# @param [String] key
|
595
|
-
# @param [
|
596
|
+
# @param [Integer] db
|
596
597
|
# @return [Boolean] whether the key was moved or not
|
597
598
|
def move(key, db)
|
598
599
|
synchronize do |client|
|
@@ -656,7 +657,7 @@ class Redis
|
|
656
657
|
# - `:order => String`: combination of `ASC`, `DESC` and optionally `ALPHA`
|
657
658
|
# - `:store => String`: key to store the result at
|
658
659
|
#
|
659
|
-
# @return [Array<String>, Array<Array<String>>,
|
660
|
+
# @return [Array<String>, Array<Array<String>>, Integer]
|
660
661
|
# - when `:get` is not specified, or holds a single element, an array of elements
|
661
662
|
# - when `:get` is specified, and holds more than one element, an array of
|
662
663
|
# elements where every element is an array with the result for every
|
@@ -710,7 +711,7 @@ class Redis
|
|
710
711
|
# # => 4
|
711
712
|
#
|
712
713
|
# @param [String] key
|
713
|
-
# @return [
|
714
|
+
# @return [Integer] value after decrementing it
|
714
715
|
def decr(key)
|
715
716
|
synchronize do |client|
|
716
717
|
client.call([:decr, key])
|
@@ -724,8 +725,8 @@ class Redis
|
|
724
725
|
# # => 0
|
725
726
|
#
|
726
727
|
# @param [String] key
|
727
|
-
# @param [
|
728
|
-
# @return [
|
728
|
+
# @param [Integer] decrement
|
729
|
+
# @return [Integer] value after decrementing it
|
729
730
|
def decrby(key, decrement)
|
730
731
|
synchronize do |client|
|
731
732
|
client.call([:decrby, key, decrement])
|
@@ -739,7 +740,7 @@ class Redis
|
|
739
740
|
# # => 6
|
740
741
|
#
|
741
742
|
# @param [String] key
|
742
|
-
# @return [
|
743
|
+
# @return [Integer] value after incrementing it
|
743
744
|
def incr(key)
|
744
745
|
synchronize do |client|
|
745
746
|
client.call([:incr, key])
|
@@ -753,8 +754,8 @@ class Redis
|
|
753
754
|
# # => 10
|
754
755
|
#
|
755
756
|
# @param [String] key
|
756
|
-
# @param [
|
757
|
-
# @return [
|
757
|
+
# @param [Integer] increment
|
758
|
+
# @return [Integer] value after incrementing it
|
758
759
|
def incrby(key, increment)
|
759
760
|
synchronize do |client|
|
760
761
|
client.call([:incrby, key, increment])
|
@@ -781,8 +782,8 @@ class Redis
|
|
781
782
|
# @param [String] key
|
782
783
|
# @param [String] value
|
783
784
|
# @param [Hash] options
|
784
|
-
# - `:ex =>
|
785
|
-
# - `:px =>
|
785
|
+
# - `:ex => Integer`: Set the specified expire time, in seconds.
|
786
|
+
# - `:px => Integer`: Set the specified expire time, in milliseconds.
|
786
787
|
# - `:nx => true`: Only set the key if it does not already exist.
|
787
788
|
# - `:xx => true`: Only set the key if it already exist.
|
788
789
|
# @return [String, Boolean] `"OK"` or true, false if `:nx => true` or `:xx => true`
|
@@ -813,7 +814,7 @@ class Redis
|
|
813
814
|
# Set the time to live in seconds of a key.
|
814
815
|
#
|
815
816
|
# @param [String] key
|
816
|
-
# @param [
|
817
|
+
# @param [Integer] ttl
|
817
818
|
# @param [String] value
|
818
819
|
# @return [String] `"OK"`
|
819
820
|
def setex(key, ttl, value)
|
@@ -825,7 +826,7 @@ class Redis
|
|
825
826
|
# Set the time to live in milliseconds of a key.
|
826
827
|
#
|
827
828
|
# @param [String] key
|
828
|
-
# @param [
|
829
|
+
# @param [Integer] ttl
|
829
830
|
# @param [String] value
|
830
831
|
# @return [String] `"OK"`
|
831
832
|
def psetex(key, ttl, value)
|
@@ -918,7 +919,7 @@ class Redis
|
|
918
919
|
# Get the values of all the given keys.
|
919
920
|
#
|
920
921
|
# @example
|
921
|
-
# redis.mget("key1", "
|
922
|
+
# redis.mget("key1", "key2")
|
922
923
|
# # => ["v1", "v2"]
|
923
924
|
#
|
924
925
|
# @param [Array<String>] keys
|
@@ -954,9 +955,9 @@ class Redis
|
|
954
955
|
# Overwrite part of a string at key starting at the specified offset.
|
955
956
|
#
|
956
957
|
# @param [String] key
|
957
|
-
# @param [
|
958
|
+
# @param [Integer] offset byte offset
|
958
959
|
# @param [String] value
|
959
|
-
# @return [
|
960
|
+
# @return [Integer] length of the string after it was modified
|
960
961
|
def setrange(key, offset, value)
|
961
962
|
synchronize do |client|
|
962
963
|
client.call([:setrange, key, offset, value.to_s])
|
@@ -966,10 +967,10 @@ class Redis
|
|
966
967
|
# Get a substring of the string stored at a key.
|
967
968
|
#
|
968
969
|
# @param [String] key
|
969
|
-
# @param [
|
970
|
-
# @param [
|
970
|
+
# @param [Integer] start zero-based start offset
|
971
|
+
# @param [Integer] stop zero-based end offset. Use -1 for representing
|
971
972
|
# the end of the string
|
972
|
-
# @return [
|
973
|
+
# @return [Integer] `0` or `1`
|
973
974
|
def getrange(key, start, stop)
|
974
975
|
synchronize do |client|
|
975
976
|
client.call([:getrange, key, start, stop])
|
@@ -979,9 +980,9 @@ class Redis
|
|
979
980
|
# Sets or clears the bit at offset in the string value stored at key.
|
980
981
|
#
|
981
982
|
# @param [String] key
|
982
|
-
# @param [
|
983
|
-
# @param [
|
984
|
-
# @return [
|
983
|
+
# @param [Integer] offset bit offset
|
984
|
+
# @param [Integer] value bit value `0` or `1`
|
985
|
+
# @return [Integer] the original bit value stored at `offset`
|
985
986
|
def setbit(key, offset, value)
|
986
987
|
synchronize do |client|
|
987
988
|
client.call([:setbit, key, offset, value])
|
@@ -991,8 +992,8 @@ class Redis
|
|
991
992
|
# Returns the bit value at offset in the string value stored at key.
|
992
993
|
#
|
993
994
|
# @param [String] key
|
994
|
-
# @param [
|
995
|
-
# @return [
|
995
|
+
# @param [Integer] offset bit offset
|
996
|
+
# @return [Integer] `0` or `1`
|
996
997
|
def getbit(key, offset)
|
997
998
|
synchronize do |client|
|
998
999
|
client.call([:getbit, key, offset])
|
@@ -1003,7 +1004,7 @@ class Redis
|
|
1003
1004
|
#
|
1004
1005
|
# @param [String] key
|
1005
1006
|
# @param [String] value value to append
|
1006
|
-
# @return [
|
1007
|
+
# @return [Integer] length of the string after appending
|
1007
1008
|
def append(key, value)
|
1008
1009
|
synchronize do |client|
|
1009
1010
|
client.call([:append, key, value])
|
@@ -1013,9 +1014,9 @@ class Redis
|
|
1013
1014
|
# Count the number of set bits in a range of the string value stored at key.
|
1014
1015
|
#
|
1015
1016
|
# @param [String] key
|
1016
|
-
# @param [
|
1017
|
-
# @param [
|
1018
|
-
# @return [
|
1017
|
+
# @param [Integer] start start index
|
1018
|
+
# @param [Integer] stop stop index
|
1019
|
+
# @return [Integer] the number of bits set to 1
|
1019
1020
|
def bitcount(key, start = 0, stop = -1)
|
1020
1021
|
synchronize do |client|
|
1021
1022
|
client.call([:bitcount, key, start, stop])
|
@@ -1027,7 +1028,7 @@ class Redis
|
|
1027
1028
|
# @param [String] operation e.g. `and`, `or`, `xor`, `not`
|
1028
1029
|
# @param [String] destkey destination key
|
1029
1030
|
# @param [String, Array<String>] keys one or more source keys to perform `operation`
|
1030
|
-
# @return [
|
1031
|
+
# @return [Integer] the length of the string stored in `destkey`
|
1031
1032
|
def bitop(operation, destkey, *keys)
|
1032
1033
|
synchronize do |client|
|
1033
1034
|
client.call([:bitop, operation, destkey] + keys)
|
@@ -1037,10 +1038,10 @@ class Redis
|
|
1037
1038
|
# Return the position of the first bit set to 1 or 0 in a string.
|
1038
1039
|
#
|
1039
1040
|
# @param [String] key
|
1040
|
-
# @param [
|
1041
|
-
# @param [
|
1042
|
-
# @param [
|
1043
|
-
# @return [
|
1041
|
+
# @param [Integer] bit whether to look for the first 1 or 0 bit
|
1042
|
+
# @param [Integer] start start index
|
1043
|
+
# @param [Integer] stop stop index
|
1044
|
+
# @return [Integer] the position of the first 1/0 bit.
|
1044
1045
|
# -1 if looking for 1 and it is not found or start and stop are given.
|
1045
1046
|
def bitpos(key, bit, start=nil, stop=nil)
|
1046
1047
|
if stop and not start
|
@@ -1070,7 +1071,7 @@ class Redis
|
|
1070
1071
|
# Get the length of the value stored in a key.
|
1071
1072
|
#
|
1072
1073
|
# @param [String] key
|
1073
|
-
# @return [
|
1074
|
+
# @return [Integer] the length of the value stored in the key, or 0
|
1074
1075
|
# if the key does not exist
|
1075
1076
|
def strlen(key)
|
1076
1077
|
synchronize do |client|
|
@@ -1081,7 +1082,7 @@ class Redis
|
|
1081
1082
|
# Get the length of a list.
|
1082
1083
|
#
|
1083
1084
|
# @param [String] key
|
1084
|
-
# @return [
|
1085
|
+
# @return [Integer]
|
1085
1086
|
def llen(key)
|
1086
1087
|
synchronize do |client|
|
1087
1088
|
client.call([:llen, key])
|
@@ -1092,7 +1093,7 @@ class Redis
|
|
1092
1093
|
#
|
1093
1094
|
# @param [String] key
|
1094
1095
|
# @param [String, Array<String>] value string value, or array of string values to push
|
1095
|
-
# @return [
|
1096
|
+
# @return [Integer] the length of the list after the push operation
|
1096
1097
|
def lpush(key, value)
|
1097
1098
|
synchronize do |client|
|
1098
1099
|
client.call([:lpush, key, value])
|
@@ -1103,7 +1104,7 @@ class Redis
|
|
1103
1104
|
#
|
1104
1105
|
# @param [String] key
|
1105
1106
|
# @param [String] value
|
1106
|
-
# @return [
|
1107
|
+
# @return [Integer] the length of the list after the push operation
|
1107
1108
|
def lpushx(key, value)
|
1108
1109
|
synchronize do |client|
|
1109
1110
|
client.call([:lpushx, key, value])
|
@@ -1114,7 +1115,7 @@ class Redis
|
|
1114
1115
|
#
|
1115
1116
|
# @param [String] key
|
1116
1117
|
# @param [String, Array<String>] value string value, or array of string values to push
|
1117
|
-
# @return [
|
1118
|
+
# @return [Integer] the length of the list after the push operation
|
1118
1119
|
def rpush(key, value)
|
1119
1120
|
synchronize do |client|
|
1120
1121
|
client.call([:rpush, key, value])
|
@@ -1125,7 +1126,7 @@ class Redis
|
|
1125
1126
|
#
|
1126
1127
|
# @param [String] key
|
1127
1128
|
# @param [String] value
|
1128
|
-
# @return [
|
1129
|
+
# @return [Integer] the length of the list after the push operation
|
1129
1130
|
def rpushx(key, value)
|
1130
1131
|
synchronize do |client|
|
1131
1132
|
client.call([:rpushx, key, value])
|
@@ -1203,7 +1204,7 @@ class Redis
|
|
1203
1204
|
# @param [String, Array<String>] keys one or more keys to perform the
|
1204
1205
|
# blocking pop on
|
1205
1206
|
# @param [Hash] options
|
1206
|
-
# - `:timeout =>
|
1207
|
+
# - `:timeout => Integer`: timeout in seconds, defaults to no timeout
|
1207
1208
|
#
|
1208
1209
|
# @return [nil, [String, String]]
|
1209
1210
|
# - `nil` when the operation timed out
|
@@ -1217,7 +1218,7 @@ class Redis
|
|
1217
1218
|
# @param [String, Array<String>] keys one or more keys to perform the
|
1218
1219
|
# blocking pop on
|
1219
1220
|
# @param [Hash] options
|
1220
|
-
# - `:timeout =>
|
1221
|
+
# - `:timeout => Integer`: timeout in seconds, defaults to no timeout
|
1221
1222
|
#
|
1222
1223
|
# @return [nil, [String, String]]
|
1223
1224
|
# - `nil` when the operation timed out
|
@@ -1234,7 +1235,7 @@ class Redis
|
|
1234
1235
|
# @param [String] source source key
|
1235
1236
|
# @param [String] destination destination key
|
1236
1237
|
# @param [Hash] options
|
1237
|
-
# - `:timeout =>
|
1238
|
+
# - `:timeout => Integer`: timeout in seconds, defaults to no timeout
|
1238
1239
|
#
|
1239
1240
|
# @return [nil, String]
|
1240
1241
|
# - `nil` when the operation timed out
|
@@ -1258,7 +1259,7 @@ class Redis
|
|
1258
1259
|
# Get an element from a list by its index.
|
1259
1260
|
#
|
1260
1261
|
# @param [String] key
|
1261
|
-
# @param [
|
1262
|
+
# @param [Integer] index
|
1262
1263
|
# @return [String]
|
1263
1264
|
def lindex(key, index)
|
1264
1265
|
synchronize do |client|
|
@@ -1272,7 +1273,7 @@ class Redis
|
|
1272
1273
|
# @param [String, Symbol] where `BEFORE` or `AFTER`
|
1273
1274
|
# @param [String] pivot reference element
|
1274
1275
|
# @param [String] value
|
1275
|
-
# @return [
|
1276
|
+
# @return [Integer] length of the list after the insert operation, or `-1`
|
1276
1277
|
# when the element `pivot` was not found
|
1277
1278
|
def linsert(key, where, pivot, value)
|
1278
1279
|
synchronize do |client|
|
@@ -1283,8 +1284,8 @@ class Redis
|
|
1283
1284
|
# Get a range of elements from a list.
|
1284
1285
|
#
|
1285
1286
|
# @param [String] key
|
1286
|
-
# @param [
|
1287
|
-
# @param [
|
1287
|
+
# @param [Integer] start start index
|
1288
|
+
# @param [Integer] stop stop index
|
1288
1289
|
# @return [Array<String>]
|
1289
1290
|
def lrange(key, start, stop)
|
1290
1291
|
synchronize do |client|
|
@@ -1295,12 +1296,12 @@ class Redis
|
|
1295
1296
|
# Remove elements from a list.
|
1296
1297
|
#
|
1297
1298
|
# @param [String] key
|
1298
|
-
# @param [
|
1299
|
+
# @param [Integer] count number of elements to remove. Use a positive
|
1299
1300
|
# value to remove the first `count` occurrences of `value`. A negative
|
1300
1301
|
# value to remove the last `count` occurrences of `value`. Or zero, to
|
1301
1302
|
# remove all occurrences of `value` from the list.
|
1302
1303
|
# @param [String] value
|
1303
|
-
# @return [
|
1304
|
+
# @return [Integer] the number of removed elements
|
1304
1305
|
def lrem(key, count, value)
|
1305
1306
|
synchronize do |client|
|
1306
1307
|
client.call([:lrem, key, count, value])
|
@@ -1310,7 +1311,7 @@ class Redis
|
|
1310
1311
|
# Set the value of an element in a list by its index.
|
1311
1312
|
#
|
1312
1313
|
# @param [String] key
|
1313
|
-
# @param [
|
1314
|
+
# @param [Integer] index
|
1314
1315
|
# @param [String] value
|
1315
1316
|
# @return [String] `OK`
|
1316
1317
|
def lset(key, index, value)
|
@@ -1322,8 +1323,8 @@ class Redis
|
|
1322
1323
|
# Trim a list to the specified range.
|
1323
1324
|
#
|
1324
1325
|
# @param [String] key
|
1325
|
-
# @param [
|
1326
|
-
# @param [
|
1326
|
+
# @param [Integer] start start index
|
1327
|
+
# @param [Integer] stop stop index
|
1327
1328
|
# @return [String] `OK`
|
1328
1329
|
def ltrim(key, start, stop)
|
1329
1330
|
synchronize do |client|
|
@@ -1334,7 +1335,7 @@ class Redis
|
|
1334
1335
|
# Get the number of members in a set.
|
1335
1336
|
#
|
1336
1337
|
# @param [String] key
|
1337
|
-
# @return [
|
1338
|
+
# @return [Integer]
|
1338
1339
|
def scard(key)
|
1339
1340
|
synchronize do |client|
|
1340
1341
|
client.call([:scard, key])
|
@@ -1345,8 +1346,8 @@ class Redis
|
|
1345
1346
|
#
|
1346
1347
|
# @param [String] key
|
1347
1348
|
# @param [String, Array<String>] member one member, or array of members
|
1348
|
-
# @return [Boolean,
|
1349
|
-
# holding whether or not adding the member succeeded, or `
|
1349
|
+
# @return [Boolean, Integer] `Boolean` when a single member is specified,
|
1350
|
+
# holding whether or not adding the member succeeded, or `Integer` when an
|
1350
1351
|
# array of members is specified, holding the number of members that were
|
1351
1352
|
# successfully added
|
1352
1353
|
def sadd(key, member)
|
@@ -1367,8 +1368,8 @@ class Redis
|
|
1367
1368
|
#
|
1368
1369
|
# @param [String] key
|
1369
1370
|
# @param [String, Array<String>] member one member, or array of members
|
1370
|
-
# @return [Boolean,
|
1371
|
-
# holding whether or not removing the member succeeded, or `
|
1371
|
+
# @return [Boolean, Integer] `Boolean` when a single member is specified,
|
1372
|
+
# holding whether or not removing the member succeeded, or `Integer` when an
|
1372
1373
|
# array of members is specified, holding the number of members that were
|
1373
1374
|
# successfully removed
|
1374
1375
|
def srem(key, member)
|
@@ -1389,7 +1390,7 @@ class Redis
|
|
1389
1390
|
#
|
1390
1391
|
# @param [String] key
|
1391
1392
|
# @return [String]
|
1392
|
-
# @param [
|
1393
|
+
# @param [Integer] count
|
1393
1394
|
def spop(key, count = nil)
|
1394
1395
|
synchronize do |client|
|
1395
1396
|
if count.nil?
|
@@ -1403,7 +1404,7 @@ class Redis
|
|
1403
1404
|
# Get one or more random members from a set.
|
1404
1405
|
#
|
1405
1406
|
# @param [String] key
|
1406
|
-
# @param [
|
1407
|
+
# @param [Integer] count
|
1407
1408
|
# @return [String]
|
1408
1409
|
def srandmember(key, count = nil)
|
1409
1410
|
synchronize do |client|
|
@@ -1462,7 +1463,7 @@ class Redis
|
|
1462
1463
|
#
|
1463
1464
|
# @param [String] destination destination key
|
1464
1465
|
# @param [String, Array<String>] keys keys pointing to sets to subtract
|
1465
|
-
# @return [
|
1466
|
+
# @return [Integer] number of elements in the resulting set
|
1466
1467
|
def sdiffstore(destination, *keys)
|
1467
1468
|
synchronize do |client|
|
1468
1469
|
client.call([:sdiffstore, destination] + keys)
|
@@ -1483,7 +1484,7 @@ class Redis
|
|
1483
1484
|
#
|
1484
1485
|
# @param [String] destination destination key
|
1485
1486
|
# @param [String, Array<String>] keys keys pointing to sets to intersect
|
1486
|
-
# @return [
|
1487
|
+
# @return [Integer] number of elements in the resulting set
|
1487
1488
|
def sinterstore(destination, *keys)
|
1488
1489
|
synchronize do |client|
|
1489
1490
|
client.call([:sinterstore, destination] + keys)
|
@@ -1504,7 +1505,7 @@ class Redis
|
|
1504
1505
|
#
|
1505
1506
|
# @param [String] destination destination key
|
1506
1507
|
# @param [String, Array<String>] keys keys pointing to sets to unify
|
1507
|
-
# @return [
|
1508
|
+
# @return [Integer] number of elements in the resulting set
|
1508
1509
|
def sunionstore(destination, *keys)
|
1509
1510
|
synchronize do |client|
|
1510
1511
|
client.call([:sunionstore, destination] + keys)
|
@@ -1518,7 +1519,7 @@ class Redis
|
|
1518
1519
|
# # => 4
|
1519
1520
|
#
|
1520
1521
|
# @param [String] key
|
1521
|
-
# @return [
|
1522
|
+
# @return [Integer]
|
1522
1523
|
def zcard(key)
|
1523
1524
|
synchronize do |client|
|
1524
1525
|
client.call([:zcard, key])
|
@@ -1549,10 +1550,10 @@ class Redis
|
|
1549
1550
|
# - `:incr => true`: When this option is specified ZADD acts like
|
1550
1551
|
# ZINCRBY; only one score-element pair can be specified in this mode
|
1551
1552
|
#
|
1552
|
-
# @return [Boolean,
|
1553
|
+
# @return [Boolean, Integer, Float]
|
1553
1554
|
# - `Boolean` when a single pair is specified, holding whether or not it was
|
1554
1555
|
# **added** to the sorted set.
|
1555
|
-
# - `
|
1556
|
+
# - `Integer` when an array of pairs is specified, holding the number of
|
1556
1557
|
# pairs that were **added** to the sorted set.
|
1557
1558
|
# - `Float` when option :incr is specified, holding the score of the member
|
1558
1559
|
# after incrementing it.
|
@@ -1615,10 +1616,10 @@ class Redis
|
|
1615
1616
|
# - a single member
|
1616
1617
|
# - an array of members
|
1617
1618
|
#
|
1618
|
-
# @return [Boolean,
|
1619
|
+
# @return [Boolean, Integer]
|
1619
1620
|
# - `Boolean` when a single member is specified, holding whether or not it
|
1620
1621
|
# was removed from the sorted set
|
1621
|
-
# - `
|
1622
|
+
# - `Integer` when an array of pairs is specified, holding the number of
|
1622
1623
|
# members that were removed to the sorted set
|
1623
1624
|
def zrem(key, member)
|
1624
1625
|
synchronize do |client|
|
@@ -1743,8 +1744,8 @@ class Redis
|
|
1743
1744
|
# # => [["a", 32.0], ["b", 64.0]]
|
1744
1745
|
#
|
1745
1746
|
# @param [String] key
|
1746
|
-
# @param [
|
1747
|
-
# @param [
|
1747
|
+
# @param [Integer] start start index
|
1748
|
+
# @param [Integer] stop stop index
|
1748
1749
|
# @param [Hash] options
|
1749
1750
|
# - `:with_scores => true`: include scores in output
|
1750
1751
|
#
|
@@ -1796,7 +1797,7 @@ class Redis
|
|
1796
1797
|
#
|
1797
1798
|
# @param [String] key
|
1798
1799
|
# @param [String] member
|
1799
|
-
# @return [
|
1800
|
+
# @return [Integer]
|
1800
1801
|
def zrank(key, member)
|
1801
1802
|
synchronize do |client|
|
1802
1803
|
client.call([:zrank, key, member])
|
@@ -1808,7 +1809,7 @@ class Redis
|
|
1808
1809
|
#
|
1809
1810
|
# @param [String] key
|
1810
1811
|
# @param [String] member
|
1811
|
-
# @return [
|
1812
|
+
# @return [Integer]
|
1812
1813
|
def zrevrank(key, member)
|
1813
1814
|
synchronize do |client|
|
1814
1815
|
client.call([:zrevrank, key, member])
|
@@ -1825,9 +1826,9 @@ class Redis
|
|
1825
1826
|
# # => 5
|
1826
1827
|
#
|
1827
1828
|
# @param [String] key
|
1828
|
-
# @param [
|
1829
|
-
# @param [
|
1830
|
-
# @return [
|
1829
|
+
# @param [Integer] start start index
|
1830
|
+
# @param [Integer] stop stop index
|
1831
|
+
# @return [Integer] number of members that were removed
|
1831
1832
|
def zremrangebyrank(key, start, stop)
|
1832
1833
|
synchronize do |client|
|
1833
1834
|
client.call([:zremrangebyrank, key, start, stop])
|
@@ -1851,7 +1852,7 @@ class Redis
|
|
1851
1852
|
# - inclusive maximum is specified by prefixing `(`
|
1852
1853
|
# - exclusive maximum is specified by prefixing `[`
|
1853
1854
|
#
|
1854
|
-
# @return [
|
1855
|
+
# @return [Integer] number of members within the specified lexicographical range
|
1855
1856
|
def zlexcount(key, min, max)
|
1856
1857
|
synchronize do |client|
|
1857
1858
|
client.call([:zlexcount, key, min, max])
|
@@ -2005,7 +2006,7 @@ class Redis
|
|
2005
2006
|
# @param [String] max
|
2006
2007
|
# - inclusive maximum score is specified verbatim
|
2007
2008
|
# - exclusive maximum score is specified by prefixing `(`
|
2008
|
-
# @return [
|
2009
|
+
# @return [Integer] number of members that were removed
|
2009
2010
|
def zremrangebyscore(key, min, max)
|
2010
2011
|
synchronize do |client|
|
2011
2012
|
client.call([:zremrangebyscore, key, min, max])
|
@@ -2028,7 +2029,7 @@ class Redis
|
|
2028
2029
|
# @param [String] max
|
2029
2030
|
# - inclusive maximum score is specified verbatim
|
2030
2031
|
# - exclusive maximum score is specified by prefixing `(`
|
2031
|
-
# @return [
|
2032
|
+
# @return [Integer] number of members in within the specified range
|
2032
2033
|
def zcount(key, min, max)
|
2033
2034
|
synchronize do |client|
|
2034
2035
|
client.call([:zcount, key, min, max])
|
@@ -2048,7 +2049,7 @@ class Redis
|
|
2048
2049
|
# - `:weights => [Float, Float, ...]`: weights to associate with source
|
2049
2050
|
# sorted sets
|
2050
2051
|
# - `:aggregate => String`: aggregate function to use (sum, min, max, ...)
|
2051
|
-
# @return [
|
2052
|
+
# @return [Integer] number of elements in the resulting sorted set
|
2052
2053
|
def zinterstore(destination, keys, options = {})
|
2053
2054
|
args = []
|
2054
2055
|
|
@@ -2075,7 +2076,7 @@ class Redis
|
|
2075
2076
|
# - `:weights => [Float, Float, ...]`: weights to associate with source
|
2076
2077
|
# sorted sets
|
2077
2078
|
# - `:aggregate => String`: aggregate function to use (sum, min, max, ...)
|
2078
|
-
# @return [
|
2079
|
+
# @return [Integer] number of elements in the resulting sorted set
|
2079
2080
|
def zunionstore(destination, keys, options = {})
|
2080
2081
|
args = []
|
2081
2082
|
|
@@ -2093,7 +2094,7 @@ class Redis
|
|
2093
2094
|
# Get the number of fields in a hash.
|
2094
2095
|
#
|
2095
2096
|
# @param [String] key
|
2096
|
-
# @return [
|
2097
|
+
# @return [Integer] number of fields in the hash
|
2097
2098
|
def hlen(key)
|
2098
2099
|
synchronize do |client|
|
2099
2100
|
client.call([:hlen, key])
|
@@ -2209,7 +2210,7 @@ class Redis
|
|
2209
2210
|
#
|
2210
2211
|
# @param [String] key
|
2211
2212
|
# @param [String, Array<String>] field
|
2212
|
-
# @return [
|
2213
|
+
# @return [Integer] the number of fields that were removed from the hash
|
2213
2214
|
def hdel(key, *fields)
|
2214
2215
|
synchronize do |client|
|
2215
2216
|
client.call([:hdel, key, *fields])
|
@@ -2231,8 +2232,8 @@ class Redis
|
|
2231
2232
|
#
|
2232
2233
|
# @param [String] key
|
2233
2234
|
# @param [String] field
|
2234
|
-
# @param [
|
2235
|
-
# @return [
|
2235
|
+
# @param [Integer] increment
|
2236
|
+
# @return [Integer] value of the field after incrementing it
|
2236
2237
|
def hincrby(key, field, increment)
|
2237
2238
|
synchronize do |client|
|
2238
2239
|
client.call([:hincrby, key, field, increment])
|
@@ -2800,7 +2801,7 @@ class Redis
|
|
2800
2801
|
# union of the HyperLogLogs contained in the keys.
|
2801
2802
|
#
|
2802
2803
|
# @param [String, Array<String>] keys
|
2803
|
-
# @return [
|
2804
|
+
# @return [Integer]
|
2804
2805
|
def pfcount(*keys)
|
2805
2806
|
synchronize do |client|
|
2806
2807
|
client.call([:pfcount] + keys)
|
data/lib/redis/client.rb
CHANGED
data/lib/redis/cluster.rb
CHANGED
@@ -112,12 +112,11 @@ class Redis
|
|
112
112
|
node = Node.new(option.per_node_key)
|
113
113
|
available_slots = SlotLoader.load(node)
|
114
114
|
node_flags = NodeLoader.load_flags(node)
|
115
|
-
|
116
|
-
option.update_node(available_node_urls)
|
115
|
+
option.update_node(available_slots.keys.map { |k| NodeKey.optionize(k) })
|
117
116
|
[Node.new(option.per_node_key, node_flags, option.use_replica?),
|
118
117
|
Slot.new(available_slots, node_flags, option.use_replica?)]
|
119
118
|
ensure
|
120
|
-
node
|
119
|
+
node&.each(&:disconnect)
|
121
120
|
end
|
122
121
|
|
123
122
|
def fetch_command_details(nodes)
|
@@ -216,7 +215,10 @@ class Redis
|
|
216
215
|
node.public_send(method_name, *args, &block)
|
217
216
|
rescue CommandError => err
|
218
217
|
if err.message.start_with?('MOVED')
|
219
|
-
|
218
|
+
raise if retry_count <= 0
|
219
|
+
node = assign_redirection_node(err.message)
|
220
|
+
retry_count -= 1
|
221
|
+
retry
|
220
222
|
elsif err.message.start_with?('ASK')
|
221
223
|
raise if retry_count <= 0
|
222
224
|
node = assign_asking_node(err.message)
|
@@ -6,17 +6,13 @@ class Redis
|
|
6
6
|
# It is different from node id.
|
7
7
|
# Node id is internal identifying code in Redis Cluster.
|
8
8
|
module NodeKey
|
9
|
-
DEFAULT_SCHEME = 'redis'
|
10
|
-
SECURE_SCHEME = 'rediss'
|
11
9
|
DELIMITER = ':'
|
12
10
|
|
13
11
|
module_function
|
14
12
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
.map { |k| k.split(DELIMITER) }
|
19
|
-
.map { |k| URI::Generic.build(scheme: scheme, host: k[0], port: k[1].to_i).to_s }
|
13
|
+
def optionize(node_key)
|
14
|
+
host, port = split(node_key)
|
15
|
+
{ host: host, port: port }
|
20
16
|
end
|
21
17
|
|
22
18
|
def split(node_key)
|
data/lib/redis/cluster/option.rb
CHANGED
@@ -15,35 +15,33 @@ class Redis
|
|
15
15
|
def initialize(options)
|
16
16
|
options = options.dup
|
17
17
|
node_addrs = options.delete(:cluster)
|
18
|
-
@
|
18
|
+
@node_opts = build_node_options(node_addrs)
|
19
19
|
@replica = options.delete(:replica) == true
|
20
|
+
add_common_node_option_if_needed(options, @node_opts, :scheme)
|
21
|
+
add_common_node_option_if_needed(options, @node_opts, :password)
|
20
22
|
@options = options
|
21
23
|
end
|
22
24
|
|
23
25
|
def per_node_key
|
24
|
-
@
|
26
|
+
@node_opts.map { |opt| [NodeKey.build_from_host_port(opt[:host], opt[:port]), @options.merge(opt)] }
|
25
27
|
.to_h
|
26
28
|
end
|
27
29
|
|
28
|
-
def secure?
|
29
|
-
@node_uris.any? { |uri| uri.scheme == SECURE_SCHEME } || @options[:ssl_params] || false
|
30
|
-
end
|
31
|
-
|
32
30
|
def use_replica?
|
33
31
|
@replica
|
34
32
|
end
|
35
33
|
|
36
34
|
def update_node(addrs)
|
37
|
-
@
|
35
|
+
@node_opts = build_node_options(addrs)
|
38
36
|
end
|
39
37
|
|
40
38
|
def add_node(host, port)
|
41
|
-
@
|
39
|
+
@node_opts << { host: host, port: port }
|
42
40
|
end
|
43
41
|
|
44
42
|
private
|
45
43
|
|
46
|
-
def
|
44
|
+
def build_node_options(addrs)
|
47
45
|
raise InvalidClientOptionError, 'Redis option of `cluster` must be an Array' unless addrs.is_a?(Array)
|
48
46
|
addrs.map { |addr| parse_node_addr(addr) }
|
49
47
|
end
|
@@ -53,7 +51,7 @@ class Redis
|
|
53
51
|
when String
|
54
52
|
parse_node_url(addr)
|
55
53
|
when Hash
|
56
|
-
|
54
|
+
parse_node_option(addr)
|
57
55
|
else
|
58
56
|
raise InvalidClientOptionError, 'Redis option of `cluster` must includes String or Hash'
|
59
57
|
end
|
@@ -62,15 +60,27 @@ class Redis
|
|
62
60
|
def parse_node_url(addr)
|
63
61
|
uri = URI(addr)
|
64
62
|
raise InvalidClientOptionError, "Invalid uri scheme #{addr}" unless VALID_SCHEMES.include?(uri.scheme)
|
65
|
-
|
63
|
+
|
64
|
+
db = uri.path.split('/')[1]&.to_i
|
65
|
+
{ scheme: uri.scheme, password: uri.password, host: uri.host, port: uri.port, db: db }.reject { |_, v| v.nil? }
|
66
66
|
rescue URI::InvalidURIError => err
|
67
67
|
raise InvalidClientOptionError, err.message
|
68
68
|
end
|
69
69
|
|
70
|
-
def
|
70
|
+
def parse_node_option(addr)
|
71
71
|
addr = addr.map { |k, v| [k.to_sym, v] }.to_h
|
72
72
|
raise InvalidClientOptionError, 'Redis option of `cluster` must includes `:host` and `:port` keys' if addr.values_at(:host, :port).any?(&:nil?)
|
73
|
-
|
73
|
+
|
74
|
+
addr
|
75
|
+
end
|
76
|
+
|
77
|
+
# Redis cluster node returns only host and port information.
|
78
|
+
# So we should complement additional information such as:
|
79
|
+
# scheme, password and so on.
|
80
|
+
def add_common_node_option_if_needed(options, node_opts, key)
|
81
|
+
return options if options[key].nil? && node_opts.first[key].nil?
|
82
|
+
|
83
|
+
options[key] ||= node_opts.first[key]
|
74
84
|
end
|
75
85
|
end
|
76
86
|
end
|
data/lib/redis/cluster/slot.rb
CHANGED
@@ -50,9 +50,12 @@ class Redis
|
|
50
50
|
@node_flags[node_key] == ROLE_SLAVE
|
51
51
|
end
|
52
52
|
|
53
|
+
# available_slots is mapping of node_key to list of slot ranges
|
53
54
|
def build_slot_node_key_map(available_slots)
|
54
|
-
available_slots.each_with_object({}) do |(node_key,
|
55
|
-
|
55
|
+
available_slots.each_with_object({}) do |(node_key, slots_arr), acc|
|
56
|
+
slots_arr.each do |slots|
|
57
|
+
slots.each { |slot| assign_node_key(acc, slot, node_key) }
|
58
|
+
end
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
@@ -13,7 +13,7 @@ class Redis
|
|
13
13
|
info = {}
|
14
14
|
|
15
15
|
nodes.each do |node|
|
16
|
-
info =
|
16
|
+
info = fetch_slot_info(node)
|
17
17
|
info.empty? ? next : break
|
18
18
|
end
|
19
19
|
|
@@ -23,9 +23,11 @@ class Redis
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def fetch_slot_info(node)
|
26
|
+
hash_with_default_arr = Hash.new { |h, k| h[k] = [] }
|
26
27
|
node.call(%i[cluster slots])
|
27
|
-
|
28
|
-
|
28
|
+
.flat_map { |arr| parse_slot_info(arr, default_ip: node.host) }
|
29
|
+
.each_with_object(hash_with_default_arr) { |arr, h| h[arr[0]] << arr[1] }
|
30
|
+
|
29
31
|
rescue CannotConnectError, ConnectionError, CommandError
|
30
32
|
{} # can retry on another node
|
31
33
|
end
|
@@ -34,7 +36,6 @@ class Redis
|
|
34
36
|
first_slot, last_slot = arr[0..1]
|
35
37
|
slot_range = (first_slot..last_slot).freeze
|
36
38
|
arr[2..-1].map { |addr| [stringify_node_key(addr, default_ip), slot_range] }
|
37
|
-
.flatten
|
38
39
|
end
|
39
40
|
|
40
41
|
def stringify_node_key(arr, default_ip)
|
data/lib/redis/connection.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative "registry"
|
2
3
|
require_relative "command_helper"
|
3
4
|
require_relative "../errors"
|
@@ -53,7 +54,7 @@ class Redis
|
|
53
54
|
crlf = nil
|
54
55
|
|
55
56
|
while (crlf = @buffer.index(CRLF)) == nil
|
56
|
-
@buffer << _read_from_socket(
|
57
|
+
@buffer << _read_from_socket(16384)
|
57
58
|
end
|
58
59
|
|
59
60
|
@buffer.slice!(0, crlf + CRLF.bytesize)
|
@@ -354,8 +355,8 @@ class Redis
|
|
354
355
|
|
355
356
|
# disables Nagle's Algorithm, prevents multiple round trips with MULTI
|
356
357
|
if [:IPPROTO_TCP, :TCP_NODELAY].all?{|c| Socket.const_defined? c}
|
357
|
-
def set_tcp_nodelay
|
358
|
-
@sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
358
|
+
def set_tcp_nodelay
|
359
|
+
@sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
359
360
|
end
|
360
361
|
else
|
361
362
|
def set_tcp_nodelay
|
data/lib/redis/distributed.rb
CHANGED
data/lib/redis/errors.rb
CHANGED
data/lib/redis/hash_ring.rb
CHANGED
data/lib/redis/pipeline.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
class Redis
|
2
3
|
class Pipeline
|
3
4
|
attr_accessor :db
|
@@ -139,6 +140,20 @@ class Redis
|
|
139
140
|
@object = FutureNotReady
|
140
141
|
end
|
141
142
|
|
143
|
+
def ==(_other)
|
144
|
+
message = +"The methods == and != are deprecated for Redis::Future and will be removed in 4.2.0"
|
145
|
+
message << " - You probably meant to call .value == or .value !="
|
146
|
+
message << " (#{::Kernel.caller(1, 1).first})\n"
|
147
|
+
|
148
|
+
if defined?(::Warning)
|
149
|
+
::Warning.warn(message)
|
150
|
+
else
|
151
|
+
$stderr.puts(message)
|
152
|
+
end
|
153
|
+
|
154
|
+
super
|
155
|
+
end
|
156
|
+
|
142
157
|
def inspect
|
143
158
|
"<Redis::Future #{@command.inspect}>"
|
144
159
|
end
|
data/lib/redis/subscribe.rb
CHANGED
data/lib/redis/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ezra Zygmuntowicz
|
@@ -16,7 +16,7 @@ authors:
|
|
16
16
|
autorequire:
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
|
-
date:
|
19
|
+
date: 2020-05-01 00:00:00.000000000 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: mocha
|