redis 3.0.0.rc1 → 3.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +50 -0
- data/.travis/Gemfile +11 -0
- data/CHANGELOG.md +47 -19
- data/README.md +160 -149
- data/Rakefile +15 -50
- data/examples/pubsub.rb +1 -1
- data/examples/unicorn/config.ru +1 -1
- data/examples/unicorn/unicorn.rb +1 -1
- data/lib/redis.rb +790 -390
- data/lib/redis/client.rb +137 -49
- data/lib/redis/connection/hiredis.rb +26 -15
- data/lib/redis/connection/ruby.rb +170 -53
- data/lib/redis/connection/synchrony.rb +23 -35
- data/lib/redis/distributed.rb +92 -32
- data/lib/redis/errors.rb +4 -2
- data/lib/redis/pipeline.rb +17 -6
- data/lib/redis/version.rb +1 -1
- data/redis.gemspec +4 -6
- data/test/blocking_commands_test.rb +42 -0
- data/test/command_map_test.rb +18 -17
- data/test/commands_on_hashes_test.rb +13 -12
- data/test/commands_on_lists_test.rb +35 -45
- data/test/commands_on_sets_test.rb +55 -54
- data/test/commands_on_sorted_sets_test.rb +106 -105
- data/test/commands_on_strings_test.rb +64 -55
- data/test/commands_on_value_types_test.rb +66 -54
- data/test/connection_handling_test.rb +136 -151
- data/test/distributed_blocking_commands_test.rb +33 -40
- data/test/distributed_commands_on_hashes_test.rb +6 -7
- data/test/distributed_commands_on_lists_test.rb +13 -14
- data/test/distributed_commands_on_sets_test.rb +57 -58
- data/test/distributed_commands_on_sorted_sets_test.rb +11 -12
- data/test/distributed_commands_on_strings_test.rb +31 -32
- data/test/distributed_commands_on_value_types_test.rb +61 -46
- data/test/distributed_commands_requiring_clustering_test.rb +108 -108
- data/test/distributed_connection_handling_test.rb +14 -15
- data/test/distributed_internals_test.rb +7 -19
- data/test/distributed_key_tags_test.rb +36 -36
- data/test/distributed_persistence_control_commands_test.rb +17 -14
- data/test/distributed_publish_subscribe_test.rb +61 -69
- data/test/distributed_remote_server_control_commands_test.rb +39 -28
- data/test/distributed_sorting_test.rb +12 -13
- data/test/distributed_test.rb +40 -41
- data/test/distributed_transactions_test.rb +20 -21
- data/test/encoding_test.rb +12 -9
- data/test/error_replies_test.rb +42 -36
- data/test/helper.rb +118 -85
- data/test/helper_test.rb +20 -6
- data/test/internals_test.rb +167 -103
- data/test/lint/blocking_commands.rb +124 -0
- data/test/lint/hashes.rb +115 -93
- data/test/lint/lists.rb +86 -80
- data/test/lint/sets.rb +68 -62
- data/test/lint/sorted_sets.rb +200 -195
- data/test/lint/strings.rb +112 -94
- data/test/lint/value_types.rb +76 -55
- data/test/persistence_control_commands_test.rb +17 -12
- data/test/pipelining_commands_test.rb +135 -126
- data/test/publish_subscribe_test.rb +105 -110
- data/test/remote_server_control_commands_test.rb +74 -58
- data/test/sorting_test.rb +31 -29
- data/test/support/connection/hiredis.rb +1 -0
- data/test/support/connection/ruby.rb +1 -0
- data/test/support/connection/synchrony.rb +17 -0
- data/test/{redis_mock.rb → support/redis_mock.rb} +24 -21
- data/test/support/wire/synchrony.rb +24 -0
- data/test/support/wire/thread.rb +5 -0
- data/test/synchrony_driver.rb +9 -9
- data/test/test.conf +1 -1
- data/test/thread_safety_test.rb +21 -19
- data/test/transactions_test.rb +189 -118
- data/test/unknown_commands_test.rb +9 -8
- data/test/url_param_test.rb +46 -41
- metadata +28 -43
- data/TODO.md +0 -4
- data/benchmarking/thread_safety.rb +0 -38
- data/test/lint/internals.rb +0 -36
@@ -1,53 +1,46 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require "
|
3
|
+
require "helper"
|
4
|
+
require "lint/blocking_commands"
|
5
5
|
|
6
|
-
|
7
|
-
log = StringIO.new
|
8
|
-
init Redis::Distributed.new(NODES, :logger => ::Logger.new(log))
|
9
|
-
end
|
6
|
+
class TestDistributedBlockingCommands < Test::Unit::TestCase
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
r.lpush("foo", "s2")
|
8
|
+
include Helper::Distributed
|
9
|
+
include Lint::BlockingCommands
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
def test_blpop_raises
|
12
|
+
assert_raises(Redis::Distributed::CannotDistribute) do
|
13
|
+
r.blpop(["foo", "bar"])
|
14
|
+
end
|
19
15
|
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
wire.join
|
26
|
-
end
|
27
|
-
|
28
|
-
test "BRPOP" do |r|
|
29
|
-
r.rpush("foo", "s1")
|
30
|
-
r.rpush("foo", "s2")
|
31
|
-
|
32
|
-
wire = Wire.new do
|
33
|
-
redis = Redis::Distributed.new(NODES)
|
34
|
-
Wire.sleep 0.3
|
35
|
-
redis.rpush("foo", "s3")
|
17
|
+
def test_blpop_raises_with_old_prototype
|
18
|
+
assert_raises(Redis::Distributed::CannotDistribute) do
|
19
|
+
r.blpop("foo", "bar", 0)
|
20
|
+
end
|
36
21
|
end
|
37
22
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
23
|
+
def test_brpop_raises
|
24
|
+
assert_raises(Redis::Distributed::CannotDistribute) do
|
25
|
+
r.brpop(["foo", "bar"])
|
26
|
+
end
|
27
|
+
end
|
44
28
|
|
45
|
-
|
46
|
-
|
29
|
+
def test_brpop_raises_with_old_prototype
|
30
|
+
assert_raises(Redis::Distributed::CannotDistribute) do
|
31
|
+
r.brpop("foo", "bar", 0)
|
32
|
+
end
|
33
|
+
end
|
47
34
|
|
48
|
-
|
49
|
-
|
50
|
-
|
35
|
+
def test_brpoplpush_raises
|
36
|
+
assert_raises(Redis::Distributed::CannotDistribute) do
|
37
|
+
r.brpoplpush("foo", "bar")
|
38
|
+
end
|
39
|
+
end
|
51
40
|
|
52
|
-
|
41
|
+
def test_brpoplpush_raises_with_old_prototype
|
42
|
+
assert_raises(Redis::Distributed::CannotDistribute) do
|
43
|
+
r.brpoplpush("foo", "bar", 0)
|
44
|
+
end
|
45
|
+
end
|
53
46
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require "
|
3
|
+
require "helper"
|
4
|
+
require "lint/hashes"
|
5
5
|
|
6
|
-
|
7
|
-
log = StringIO.new
|
8
|
-
init Redis::Distributed.new(NODES, :logger => ::Logger.new(log))
|
9
|
-
end
|
6
|
+
class TestDistributedCommandsOnHashes < Test::Unit::TestCase
|
10
7
|
|
11
|
-
|
8
|
+
include Helper::Distributed
|
9
|
+
include Lint::Hashes
|
10
|
+
end
|
@@ -1,23 +1,22 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require "
|
3
|
+
require "helper"
|
4
|
+
require "lint/lists"
|
5
5
|
|
6
|
-
|
7
|
-
log = StringIO.new
|
8
|
-
init Redis::Distributed.new(NODES, :logger => ::Logger.new(log))
|
9
|
-
end
|
6
|
+
class TestDistributedCommandsOnLists < Test::Unit::TestCase
|
10
7
|
|
11
|
-
|
8
|
+
include Helper::Distributed
|
9
|
+
include Lint::Lists
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def test_rpoplpush
|
12
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
13
|
+
r.rpoplpush("foo", "bar")
|
14
|
+
end
|
16
15
|
end
|
17
|
-
end
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
def test_brpoplpush
|
18
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
19
|
+
r.brpoplpush("foo", "bar", :timeout => 1)
|
20
|
+
end
|
22
21
|
end
|
23
22
|
end
|
@@ -1,84 +1,83 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require "
|
3
|
+
require "helper"
|
4
|
+
require "lint/sets"
|
5
5
|
|
6
|
-
|
7
|
-
log = StringIO.new
|
8
|
-
init Redis::Distributed.new(NODES, :logger => ::Logger.new(log))
|
9
|
-
end
|
6
|
+
class TestDistributedCommandsOnSets < Test::Unit::TestCase
|
10
7
|
|
11
|
-
|
8
|
+
include Helper::Distributed
|
9
|
+
include Lint::Sets
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
def test_smove
|
12
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
13
|
+
r.sadd "foo", "s1"
|
14
|
+
r.sadd "bar", "s2"
|
17
15
|
|
18
|
-
|
16
|
+
r.smove("foo", "bar", "s1")
|
17
|
+
end
|
19
18
|
end
|
20
|
-
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
def test_sinter
|
21
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
22
|
+
r.sadd "foo", "s1"
|
23
|
+
r.sadd "foo", "s2"
|
24
|
+
r.sadd "bar", "s2"
|
27
25
|
|
28
|
-
|
26
|
+
r.sinter("foo", "bar")
|
27
|
+
end
|
29
28
|
end
|
30
|
-
end
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
def test_sinterstore
|
31
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
32
|
+
r.sadd "foo", "s1"
|
33
|
+
r.sadd "foo", "s2"
|
34
|
+
r.sadd "bar", "s2"
|
37
35
|
|
38
|
-
|
36
|
+
r.sinterstore("baz", "foo", "bar")
|
37
|
+
end
|
39
38
|
end
|
40
|
-
end
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
def test_sunion
|
41
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
42
|
+
r.sadd "foo", "s1"
|
43
|
+
r.sadd "foo", "s2"
|
44
|
+
r.sadd "bar", "s2"
|
45
|
+
r.sadd "bar", "s3"
|
48
46
|
|
49
|
-
|
47
|
+
r.sunion("foo", "bar")
|
48
|
+
end
|
50
49
|
end
|
51
|
-
end
|
52
50
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
def test_sunionstore
|
52
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
53
|
+
r.sadd "foo", "s1"
|
54
|
+
r.sadd "foo", "s2"
|
55
|
+
r.sadd "bar", "s2"
|
56
|
+
r.sadd "bar", "s3"
|
59
57
|
|
60
|
-
|
58
|
+
r.sunionstore("baz", "foo", "bar")
|
59
|
+
end
|
61
60
|
end
|
62
|
-
end
|
63
61
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
62
|
+
def test_sdiff
|
63
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
64
|
+
r.sadd "foo", "s1"
|
65
|
+
r.sadd "foo", "s2"
|
66
|
+
r.sadd "bar", "s2"
|
67
|
+
r.sadd "bar", "s3"
|
70
68
|
|
71
|
-
|
69
|
+
r.sdiff("foo", "bar")
|
70
|
+
end
|
72
71
|
end
|
73
|
-
end
|
74
72
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
73
|
+
def test_sdiffstore
|
74
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
75
|
+
r.sadd "foo", "s1"
|
76
|
+
r.sadd "foo", "s2"
|
77
|
+
r.sadd "bar", "s2"
|
78
|
+
r.sadd "bar", "s3"
|
81
79
|
|
82
|
-
|
80
|
+
r.sdiffstore("baz", "foo", "bar")
|
81
|
+
end
|
83
82
|
end
|
84
83
|
end
|
@@ -1,19 +1,18 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require "
|
3
|
+
require "helper"
|
4
|
+
require "lint/sorted_sets"
|
5
5
|
|
6
|
-
|
7
|
-
log = StringIO.new
|
8
|
-
init Redis::Distributed.new(NODES, :logger => ::Logger.new(log))
|
9
|
-
end
|
6
|
+
class TestDistributedCommandsOnSortedSets < Test::Unit::TestCase
|
10
7
|
|
11
|
-
|
8
|
+
include Helper::Distributed
|
9
|
+
include Lint::SortedSets
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
def test_zcount
|
12
|
+
r.zadd "foo", 1, "s1"
|
13
|
+
r.zadd "foo", 2, "s2"
|
14
|
+
r.zadd "foo", 3, "s3"
|
17
15
|
|
18
|
-
|
16
|
+
assert_equal 2, r.zcount("foo", 2, 3)
|
17
|
+
end
|
19
18
|
end
|
@@ -1,49 +1,48 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require "
|
3
|
+
require "helper"
|
4
|
+
require "lint/strings"
|
5
5
|
|
6
|
-
|
7
|
-
log = StringIO.new
|
8
|
-
init Redis::Distributed.new(NODES, :logger => ::Logger.new(log))
|
9
|
-
end
|
6
|
+
class TestDistributedCommandsOnStrings < Test::Unit::TestCase
|
10
7
|
|
11
|
-
|
8
|
+
include Helper::Distributed
|
9
|
+
include Lint::Strings
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def test_mget
|
12
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
13
|
+
r.mget("foo", "bar")
|
14
|
+
end
|
16
15
|
end
|
17
|
-
end
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
def test_mget_mapped
|
18
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
19
|
+
r.mapped_mget("foo", "bar")
|
20
|
+
end
|
22
21
|
end
|
23
|
-
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
def test_mset
|
24
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
25
|
+
r.mset(:foo, "s1", :bar, "s2")
|
26
|
+
end
|
28
27
|
end
|
29
|
-
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
def test_mset_mapped
|
30
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
31
|
+
r.mapped_mset(:foo => "s1", :bar => "s2")
|
32
|
+
end
|
34
33
|
end
|
35
|
-
end
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
def test_msetnx
|
36
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
37
|
+
r.set("foo", "s1")
|
38
|
+
r.msetnx(:foo, "s2", :bar, "s3")
|
39
|
+
end
|
41
40
|
end
|
42
|
-
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
def test_msetnx_mapped
|
43
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
44
|
+
r.set("foo", "s1")
|
45
|
+
r.mapped_msetnx(:foo => "s2", :bar => "s3")
|
46
|
+
end
|
48
47
|
end
|
49
48
|
end
|
@@ -1,72 +1,87 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require "
|
3
|
+
require "helper"
|
4
|
+
require "lint/value_types"
|
5
5
|
|
6
|
-
|
7
|
-
log = StringIO.new
|
8
|
-
init(Redis::Distributed.new(NODES, :logger => ::Logger.new(log)))
|
9
|
-
end
|
6
|
+
class TestDistributedCommandsOnValueTypes < Test::Unit::TestCase
|
10
7
|
|
11
|
-
|
8
|
+
include Helper::Distributed
|
9
|
+
include Lint::ValueTypes
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
def test_del
|
12
|
+
r.set "foo", "s1"
|
13
|
+
r.set "bar", "s2"
|
14
|
+
r.set "baz", "s3"
|
17
15
|
|
18
|
-
|
16
|
+
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
|
19
17
|
|
20
|
-
|
18
|
+
assert_equal 1, r.del("foo")
|
21
19
|
|
22
|
-
|
20
|
+
assert_equal ["bar", "baz"], r.keys("*").sort
|
23
21
|
|
24
|
-
|
22
|
+
assert_equal 2, r.del("bar", "baz")
|
25
23
|
|
26
|
-
|
27
|
-
end
|
24
|
+
assert_equal [], r.keys("*").sort
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_del_with_array_argument
|
28
|
+
r.set "foo", "s1"
|
29
|
+
r.set "bar", "s2"
|
30
|
+
r.set "baz", "s3"
|
31
|
+
|
32
|
+
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
|
28
33
|
|
29
|
-
|
30
|
-
|
31
|
-
r.
|
34
|
+
assert_equal 1, r.del(["foo"])
|
35
|
+
|
36
|
+
assert_equal ["bar", "baz"], r.keys("*").sort
|
37
|
+
|
38
|
+
assert_equal 2, r.del(["bar", "baz"])
|
39
|
+
|
40
|
+
assert_equal [], r.keys("*").sort
|
32
41
|
end
|
33
|
-
end
|
34
42
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
43
|
+
def test_randomkey
|
44
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
45
|
+
r.randomkey
|
46
|
+
end
|
39
47
|
end
|
40
48
|
|
41
|
-
|
42
|
-
|
43
|
-
|
49
|
+
def test_rename
|
50
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
51
|
+
r.set("foo", "s1")
|
52
|
+
r.rename "foo", "bar"
|
53
|
+
end
|
44
54
|
|
45
|
-
|
46
|
-
|
47
|
-
r.set("foo", "s1")
|
48
|
-
r.rename "foo", "bar"
|
55
|
+
assert_equal "s1", r.get("foo")
|
56
|
+
assert_equal nil, r.get("bar")
|
49
57
|
end
|
50
58
|
|
51
|
-
|
52
|
-
|
53
|
-
|
59
|
+
def test_renamenx
|
60
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
61
|
+
r.set("foo", "s1")
|
62
|
+
r.rename "foo", "bar"
|
63
|
+
end
|
54
64
|
|
55
|
-
|
56
|
-
|
65
|
+
assert_equal "s1", r.get("foo")
|
66
|
+
assert_equal nil , r.get("bar")
|
67
|
+
end
|
57
68
|
|
58
|
-
|
69
|
+
def test_dbsize
|
70
|
+
assert_equal [0], r.dbsize
|
59
71
|
|
60
|
-
|
61
|
-
end
|
72
|
+
r.set("foo", "s1")
|
62
73
|
|
63
|
-
|
64
|
-
|
65
|
-
r.set("bar", "s2")
|
74
|
+
assert_equal [1], r.dbsize
|
75
|
+
end
|
66
76
|
|
67
|
-
|
77
|
+
def test_flushdb
|
78
|
+
r.set("foo", "s1")
|
79
|
+
r.set("bar", "s2")
|
68
80
|
|
69
|
-
|
81
|
+
assert_equal [2], r.dbsize
|
70
82
|
|
71
|
-
|
83
|
+
r.flushdb
|
84
|
+
|
85
|
+
assert_equal [0], r.dbsize
|
86
|
+
end
|
72
87
|
end
|