redis 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/README.md +1 -1
- data/lib/redis.rb +26 -4
- data/lib/redis/distributed.rb +16 -3
- data/lib/redis/version.rb +1 -1
- data/test/commands_on_value_types_test.rb +40 -0
- data/test/connection_test.rb +57 -0
- data/test/distributed_commands_on_sets_test.rb +25 -0
- data/test/distributed_commands_on_strings_test.rb +18 -6
- data/test/internals_test.rb +0 -40
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e0d0ba2328aca583c0f487729779c2b10b12c7b
|
4
|
+
data.tar.gz: 4a411cfa3512bafe7c2c12ac8a02c02bc87065aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3af7dc63dc7bdc243da306817583db9b6989c21a0714c6652b4a443bfd9c46b2afba0707b028d708a74148bbeedd09d4ec207a0459b3559cb19b95f2f030bb07
|
7
|
+
data.tar.gz: 98d5aed456ebcd3ccdc50980879a3c14be4c8a1874c6febae95579d2fb3828bda2e82b05e62dc6a4966e178993d4a2a20dc3dedd9f8583cd731851eab2f8e164
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,16 @@
|
|
1
|
-
# 4.0
|
1
|
+
# 4.0.1
|
2
|
+
|
3
|
+
* `Redis::Distributed` now supports `mget` and `mapped_mget`. See #687.
|
4
|
+
|
5
|
+
* `Redis::Distributed` now supports `sscan` and `sscan_each`. See #572.
|
6
|
+
|
7
|
+
* `Redis#connection` returns a hash with connection information.
|
8
|
+
You shouldn't need to call `Redis#_client`, ever.
|
9
|
+
|
10
|
+
* `Redis#flushdb` and `Redis#flushall` now support the `:async` option. See #706.
|
11
|
+
|
12
|
+
|
13
|
+
# 4.0
|
2
14
|
|
3
15
|
* Removed `Redis.connect`. Use `Redis.new`.
|
4
16
|
|
data/README.md
CHANGED
@@ -363,4 +363,4 @@ requests. You can also ask for help at `#redis-rb` on Freenode.
|
|
363
363
|
[travis-home]: https://travis-ci.org/
|
364
364
|
[travis-image]: https://secure.travis-ci.org/redis/redis-rb.svg?branch=master
|
365
365
|
[travis-link]: https://travis-ci.org/redis/redis-rb
|
366
|
-
[rubydoc]:
|
366
|
+
[rubydoc]: http://www.rubydoc.info/gems/redis
|
data/lib/redis.rb
CHANGED
@@ -237,19 +237,31 @@ class Redis
|
|
237
237
|
|
238
238
|
# Remove all keys from all databases.
|
239
239
|
#
|
240
|
+
# @param [Hash] options
|
241
|
+
# - `:async => Boolean`: async flush (default: false)
|
240
242
|
# @return [String] `OK`
|
241
|
-
def flushall
|
243
|
+
def flushall(options = nil)
|
242
244
|
synchronize do |client|
|
243
|
-
|
245
|
+
if options && options[:async]
|
246
|
+
client.call([:flushall, :async])
|
247
|
+
else
|
248
|
+
client.call([:flushall])
|
249
|
+
end
|
244
250
|
end
|
245
251
|
end
|
246
252
|
|
247
253
|
# Remove all keys from the current database.
|
248
254
|
#
|
255
|
+
# @param [Hash] options
|
256
|
+
# - `:async => Boolean`: async flush (default: false)
|
249
257
|
# @return [String] `OK`
|
250
|
-
def flushdb
|
258
|
+
def flushdb(options = nil)
|
251
259
|
synchronize do |client|
|
252
|
-
|
260
|
+
if options && options[:async]
|
261
|
+
client.call([:flushdb, :async])
|
262
|
+
else
|
263
|
+
client.call([:flushdb])
|
264
|
+
end
|
253
265
|
end
|
254
266
|
end
|
255
267
|
|
@@ -2737,6 +2749,16 @@ class Redis
|
|
2737
2749
|
self.class.new(@options)
|
2738
2750
|
end
|
2739
2751
|
|
2752
|
+
def connection
|
2753
|
+
{
|
2754
|
+
host: @original_client.host,
|
2755
|
+
port: @original_client.port,
|
2756
|
+
db: @original_client.db,
|
2757
|
+
id: @original_client.id,
|
2758
|
+
location: @original_client.location
|
2759
|
+
}
|
2760
|
+
end
|
2761
|
+
|
2740
2762
|
def method_missing(command, *args)
|
2741
2763
|
synchronize do |client|
|
2742
2764
|
client.call([command] + args)
|
data/lib/redis/distributed.rb
CHANGED
@@ -277,13 +277,16 @@ class Redis
|
|
277
277
|
node_for(key).get(key)
|
278
278
|
end
|
279
279
|
|
280
|
-
# Get the values of all the given keys.
|
280
|
+
# Get the values of all the given keys as an Array.
|
281
281
|
def mget(*keys)
|
282
|
-
|
282
|
+
mapped_mget(*keys).values_at(*keys)
|
283
283
|
end
|
284
284
|
|
285
|
+
# Get the values of all the given keys as a Hash.
|
285
286
|
def mapped_mget(*keys)
|
286
|
-
|
287
|
+
keys.group_by { |k| node_for k }.inject({}) do |results, (node, subkeys)|
|
288
|
+
results.merge! node.mapped_mget(*subkeys)
|
289
|
+
end
|
287
290
|
end
|
288
291
|
|
289
292
|
# Overwrite part of a string at key starting at the specified offset.
|
@@ -509,6 +512,16 @@ class Redis
|
|
509
512
|
node_for(key).smembers(key)
|
510
513
|
end
|
511
514
|
|
515
|
+
# Scan a set
|
516
|
+
def sscan(key, cursor, options={})
|
517
|
+
node_for(key).sscan(key, cursor, options)
|
518
|
+
end
|
519
|
+
|
520
|
+
# Scan a set and return an enumerator
|
521
|
+
def sscan_each(key, options={}, &block)
|
522
|
+
node_for(key).sscan_each(key, options, &block)
|
523
|
+
end
|
524
|
+
|
512
525
|
# Subtract multiple sets.
|
513
526
|
def sdiff(*keys)
|
514
527
|
ensure_same_node(:sdiff, keys) do |node|
|
data/lib/redis/version.rb
CHANGED
@@ -79,6 +79,7 @@ class TestCommandsOnValueTypes < Test::Unit::TestCase
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def test_flushdb
|
82
|
+
# Test defaults
|
82
83
|
r.set("foo", "s1")
|
83
84
|
r.set("bar", "s2")
|
84
85
|
|
@@ -87,12 +88,51 @@ class TestCommandsOnValueTypes < Test::Unit::TestCase
|
|
87
88
|
r.flushdb
|
88
89
|
|
89
90
|
assert_equal 0, r.dbsize
|
91
|
+
|
92
|
+
# Test sync
|
93
|
+
r.set("foo", "s1")
|
94
|
+
r.set("bar", "s2")
|
95
|
+
|
96
|
+
assert_equal 2, r.dbsize
|
97
|
+
|
98
|
+
r.flushdb(:async => false)
|
99
|
+
|
100
|
+
assert_equal 0, r.dbsize
|
101
|
+
|
102
|
+
# Test async
|
103
|
+
target_version "3.9.101" do
|
104
|
+
r.set("foo", "s1")
|
105
|
+
r.set("bar", "s2")
|
106
|
+
|
107
|
+
assert_equal 2, r.dbsize
|
108
|
+
|
109
|
+
r.flushdb(:async => true)
|
110
|
+
|
111
|
+
assert_equal 0, r.dbsize
|
112
|
+
|
113
|
+
redis_mock(:flushdb => lambda { |args| "+FLUSHDB #{args.upcase}" }) do |redis|
|
114
|
+
assert_equal "FLUSHDB ASYNC", redis.flushdb(:async => true)
|
115
|
+
end
|
116
|
+
end
|
90
117
|
end
|
91
118
|
|
92
119
|
def test_flushall
|
120
|
+
# Test defaults
|
93
121
|
redis_mock(:flushall => lambda { "+FLUSHALL" }) do |redis|
|
94
122
|
assert_equal "FLUSHALL", redis.flushall
|
95
123
|
end
|
124
|
+
|
125
|
+
# Test sync
|
126
|
+
redis_mock(:flushall => lambda { "+FLUSHALL" }) do |redis|
|
127
|
+
assert_equal "FLUSHALL", redis.flushall(:async => false)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Test async
|
131
|
+
target_version "3.9.101" do
|
132
|
+
redis_mock(:flushall => lambda { |args| "+FLUSHALL #{args.upcase}" }) do |redis|
|
133
|
+
assert_equal "FLUSHALL ASYNC", redis.flushall(:async => true)
|
134
|
+
end
|
135
|
+
end
|
96
136
|
end
|
97
137
|
|
98
138
|
def test_migrate
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
class TestConnection < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include Helper::Client
|
6
|
+
|
7
|
+
def test_provides_a_meaningful_inspect
|
8
|
+
assert_equal "#<Redis client v#{Redis::VERSION} for redis://127.0.0.1:#{PORT}/15>", r.inspect
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_connection_information
|
12
|
+
assert_equal "127.0.0.1", r.connection.fetch(:host)
|
13
|
+
assert_equal 6381, r.connection.fetch(:port)
|
14
|
+
assert_equal 15, r.connection.fetch(:db)
|
15
|
+
assert_equal "127.0.0.1:6381", r.connection.fetch(:location)
|
16
|
+
assert_equal "redis://127.0.0.1:6381/15", r.connection.fetch(:id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_default_id_with_host_and_port
|
20
|
+
redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0))
|
21
|
+
assert_equal "redis://host:1234/0", redis.connection.fetch(:id)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_default_id_with_host_and_port_and_explicit_scheme
|
25
|
+
redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0, :scheme => "foo"))
|
26
|
+
assert_equal "redis://host:1234/0", redis.connection.fetch(:id)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_default_id_with_path
|
30
|
+
redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0))
|
31
|
+
assert_equal "redis:///tmp/redis.sock/0", redis.connection.fetch(:id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_default_id_with_path_and_explicit_scheme
|
35
|
+
redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0, :scheme => "foo"))
|
36
|
+
assert_equal "redis:///tmp/redis.sock/0", redis.connection.fetch(:id)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_override_id
|
40
|
+
redis = Redis.new(OPTIONS.merge(:id => "test"))
|
41
|
+
assert_equal "test", redis.connection.fetch(:id)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_id_inside_multi
|
45
|
+
redis = Redis.new(OPTIONS)
|
46
|
+
id = nil
|
47
|
+
connection_id = nil
|
48
|
+
|
49
|
+
redis.multi do
|
50
|
+
id = redis.id
|
51
|
+
connection_id = redis.connection.fetch(:id)
|
52
|
+
end
|
53
|
+
|
54
|
+
assert_equal "redis://127.0.0.1:6381/15", id
|
55
|
+
assert_equal "redis://127.0.0.1:6381/15", connection_id
|
56
|
+
end
|
57
|
+
end
|
@@ -78,4 +78,29 @@ class TestDistributedCommandsOnSets < Test::Unit::TestCase
|
|
78
78
|
r.sdiffstore("baz", "foo", "bar")
|
79
79
|
end
|
80
80
|
end
|
81
|
+
|
82
|
+
def test_sscan
|
83
|
+
assert_nothing_raised do
|
84
|
+
r.sadd "foo", "s1"
|
85
|
+
r.sadd "foo", "s2"
|
86
|
+
r.sadd "bar", "s2"
|
87
|
+
r.sadd "bar", "s3"
|
88
|
+
|
89
|
+
cursor, vals = r.sscan "foo", 0
|
90
|
+
assert_equal '0', cursor
|
91
|
+
assert_equal %w(s1 s2), vals.sort
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_sscan_each
|
96
|
+
assert_nothing_raised do
|
97
|
+
r.sadd "foo", "s1"
|
98
|
+
r.sadd "foo", "s2"
|
99
|
+
r.sadd "bar", "s2"
|
100
|
+
r.sadd "bar", "s3"
|
101
|
+
|
102
|
+
vals = r.sscan_each("foo").to_a
|
103
|
+
assert_equal %w(s1 s2), vals.sort
|
104
|
+
end
|
105
|
+
end
|
81
106
|
end
|
@@ -7,15 +7,27 @@ class TestDistributedCommandsOnStrings < Test::Unit::TestCase
|
|
7
7
|
include Lint::Strings
|
8
8
|
|
9
9
|
def test_mget
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
r.set("foo", "s1")
|
11
|
+
r.set("bar", "s2")
|
12
|
+
|
13
|
+
assert_equal ["s1", "s2"] , r.mget("foo", "bar")
|
14
|
+
assert_equal ["s1", "s2", nil], r.mget("foo", "bar", "baz")
|
13
15
|
end
|
14
16
|
|
15
17
|
def test_mget_mapped
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
r.set("foo", "s1")
|
19
|
+
r.set("bar", "s2")
|
20
|
+
|
21
|
+
response = r.mapped_mget("foo", "bar")
|
22
|
+
|
23
|
+
assert_equal "s1", response["foo"]
|
24
|
+
assert_equal "s2", response["bar"]
|
25
|
+
|
26
|
+
response = r.mapped_mget("foo", "bar", "baz")
|
27
|
+
|
28
|
+
assert_equal "s1", response["foo"]
|
29
|
+
assert_equal "s2", response["bar"]
|
30
|
+
assert_equal nil , response["baz"]
|
19
31
|
end
|
20
32
|
|
21
33
|
def test_mset
|
data/test/internals_test.rb
CHANGED
@@ -41,10 +41,6 @@ class TestInternals < Test::Unit::TestCase
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
def test_provides_a_meaningful_inspect
|
45
|
-
assert_equal "#<Redis client v#{Redis::VERSION} for redis://127.0.0.1:#{PORT}/15>", r.inspect
|
46
|
-
end
|
47
|
-
|
48
44
|
def test_redis_current
|
49
45
|
assert_equal "127.0.0.1", Redis.current._client.host
|
50
46
|
assert_equal 6379, Redis.current._client.port
|
@@ -76,48 +72,12 @@ class TestInternals < Test::Unit::TestCase
|
|
76
72
|
assert !fresh_client.connected?
|
77
73
|
end
|
78
74
|
|
79
|
-
def test_default_id_with_host_and_port
|
80
|
-
redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0))
|
81
|
-
assert_equal "redis://host:1234/0", redis._client.id
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_default_id_with_host_and_port_and_explicit_scheme
|
85
|
-
redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0, :scheme => "foo"))
|
86
|
-
assert_equal "redis://host:1234/0", redis._client.id
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_default_id_with_path
|
90
|
-
redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0))
|
91
|
-
assert_equal "redis:///tmp/redis.sock/0", redis._client.id
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_default_id_with_path_and_explicit_scheme
|
95
|
-
redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0, :scheme => "foo"))
|
96
|
-
assert_equal "redis:///tmp/redis.sock/0", redis._client.id
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_override_id
|
100
|
-
redis = Redis.new(OPTIONS.merge(:id => "test"))
|
101
|
-
assert_equal redis._client.id, "test"
|
102
|
-
end
|
103
|
-
|
104
75
|
def test_timeout
|
105
76
|
assert_nothing_raised do
|
106
77
|
Redis.new(OPTIONS.merge(:timeout => 0))
|
107
78
|
end
|
108
79
|
end
|
109
80
|
|
110
|
-
def test_id_inside_multi
|
111
|
-
redis = Redis.new(OPTIONS)
|
112
|
-
id = nil
|
113
|
-
|
114
|
-
redis.multi do
|
115
|
-
id = redis.id
|
116
|
-
end
|
117
|
-
|
118
|
-
assert_equal id, "redis://127.0.0.1:6381/15"
|
119
|
-
end
|
120
|
-
|
121
81
|
driver(:ruby) do
|
122
82
|
def test_tcp_keepalive
|
123
83
|
keepalive = {:time => 20, :intvl => 10, :probes => 5}
|
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.0.
|
4
|
+
version: 4.0.1
|
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: 2017-
|
19
|
+
date: 2017-09-28 00:00:00.000000000 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: test-unit
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- test/commands_on_strings_test.rb
|
124
124
|
- test/commands_on_value_types_test.rb
|
125
125
|
- test/connection_handling_test.rb
|
126
|
+
- test/connection_test.rb
|
126
127
|
- test/db/.gitkeep
|
127
128
|
- test/distributed_blocking_commands_test.rb
|
128
129
|
- test/distributed_commands_on_hashes_test.rb
|
@@ -225,6 +226,7 @@ test_files:
|
|
225
226
|
- test/commands_on_strings_test.rb
|
226
227
|
- test/commands_on_value_types_test.rb
|
227
228
|
- test/connection_handling_test.rb
|
229
|
+
- test/connection_test.rb
|
228
230
|
- test/db/.gitkeep
|
229
231
|
- test/distributed_blocking_commands_test.rb
|
230
232
|
- test/distributed_commands_on_hashes_test.rb
|