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.
Files changed (77) hide show
  1. data/.travis.yml +50 -0
  2. data/.travis/Gemfile +11 -0
  3. data/CHANGELOG.md +47 -19
  4. data/README.md +160 -149
  5. data/Rakefile +15 -50
  6. data/examples/pubsub.rb +1 -1
  7. data/examples/unicorn/config.ru +1 -1
  8. data/examples/unicorn/unicorn.rb +1 -1
  9. data/lib/redis.rb +790 -390
  10. data/lib/redis/client.rb +137 -49
  11. data/lib/redis/connection/hiredis.rb +26 -15
  12. data/lib/redis/connection/ruby.rb +170 -53
  13. data/lib/redis/connection/synchrony.rb +23 -35
  14. data/lib/redis/distributed.rb +92 -32
  15. data/lib/redis/errors.rb +4 -2
  16. data/lib/redis/pipeline.rb +17 -6
  17. data/lib/redis/version.rb +1 -1
  18. data/redis.gemspec +4 -6
  19. data/test/blocking_commands_test.rb +42 -0
  20. data/test/command_map_test.rb +18 -17
  21. data/test/commands_on_hashes_test.rb +13 -12
  22. data/test/commands_on_lists_test.rb +35 -45
  23. data/test/commands_on_sets_test.rb +55 -54
  24. data/test/commands_on_sorted_sets_test.rb +106 -105
  25. data/test/commands_on_strings_test.rb +64 -55
  26. data/test/commands_on_value_types_test.rb +66 -54
  27. data/test/connection_handling_test.rb +136 -151
  28. data/test/distributed_blocking_commands_test.rb +33 -40
  29. data/test/distributed_commands_on_hashes_test.rb +6 -7
  30. data/test/distributed_commands_on_lists_test.rb +13 -14
  31. data/test/distributed_commands_on_sets_test.rb +57 -58
  32. data/test/distributed_commands_on_sorted_sets_test.rb +11 -12
  33. data/test/distributed_commands_on_strings_test.rb +31 -32
  34. data/test/distributed_commands_on_value_types_test.rb +61 -46
  35. data/test/distributed_commands_requiring_clustering_test.rb +108 -108
  36. data/test/distributed_connection_handling_test.rb +14 -15
  37. data/test/distributed_internals_test.rb +7 -19
  38. data/test/distributed_key_tags_test.rb +36 -36
  39. data/test/distributed_persistence_control_commands_test.rb +17 -14
  40. data/test/distributed_publish_subscribe_test.rb +61 -69
  41. data/test/distributed_remote_server_control_commands_test.rb +39 -28
  42. data/test/distributed_sorting_test.rb +12 -13
  43. data/test/distributed_test.rb +40 -41
  44. data/test/distributed_transactions_test.rb +20 -21
  45. data/test/encoding_test.rb +12 -9
  46. data/test/error_replies_test.rb +42 -36
  47. data/test/helper.rb +118 -85
  48. data/test/helper_test.rb +20 -6
  49. data/test/internals_test.rb +167 -103
  50. data/test/lint/blocking_commands.rb +124 -0
  51. data/test/lint/hashes.rb +115 -93
  52. data/test/lint/lists.rb +86 -80
  53. data/test/lint/sets.rb +68 -62
  54. data/test/lint/sorted_sets.rb +200 -195
  55. data/test/lint/strings.rb +112 -94
  56. data/test/lint/value_types.rb +76 -55
  57. data/test/persistence_control_commands_test.rb +17 -12
  58. data/test/pipelining_commands_test.rb +135 -126
  59. data/test/publish_subscribe_test.rb +105 -110
  60. data/test/remote_server_control_commands_test.rb +74 -58
  61. data/test/sorting_test.rb +31 -29
  62. data/test/support/connection/hiredis.rb +1 -0
  63. data/test/support/connection/ruby.rb +1 -0
  64. data/test/support/connection/synchrony.rb +17 -0
  65. data/test/{redis_mock.rb → support/redis_mock.rb} +24 -21
  66. data/test/support/wire/synchrony.rb +24 -0
  67. data/test/support/wire/thread.rb +5 -0
  68. data/test/synchrony_driver.rb +9 -9
  69. data/test/test.conf +1 -1
  70. data/test/thread_safety_test.rb +21 -19
  71. data/test/transactions_test.rb +189 -118
  72. data/test/unknown_commands_test.rb +9 -8
  73. data/test/url_param_test.rb +46 -41
  74. metadata +28 -43
  75. data/TODO.md +0 -4
  76. data/benchmarking/thread_safety.rb +0 -38
  77. data/test/lint/internals.rb +0 -36
@@ -1,53 +1,46 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.expand_path("./helper", File.dirname(__FILE__))
4
- require "redis/distributed"
3
+ require "helper"
4
+ require "lint/blocking_commands"
5
5
 
6
- setup do
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
- test "BLPOP" do |r|
12
- r.lpush("foo", "s1")
13
- r.lpush("foo", "s2")
8
+ include Helper::Distributed
9
+ include Lint::BlockingCommands
14
10
 
15
- wire = Wire.new do
16
- redis = Redis::Distributed.new(NODES)
17
- Wire.sleep 0.3
18
- redis.lpush("foo", "s3")
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
- assert ["foo", "s2"] == r.blpop("foo", 1)
22
- assert ["foo", "s1"] == r.blpop("foo", 1)
23
- assert ["foo", "s3"] == r.blpop("foo", 1)
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
- assert ["foo", "s2"] == r.brpop("foo", 1)
39
- assert ["foo", "s1"] == r.brpop("foo", 1)
40
- assert ["foo", "s3"] == r.brpop("foo", 1)
41
-
42
- wire.join
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
- test "BRPOP should unset a configured socket timeout" do |r|
46
- r = Redis::Distributed.new(NODES, :timeout => 1)
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
- assert_nothing_raised do
49
- r.brpop("foo", 2)
50
- end # Errno::EAGAIN raised if socket times out before redis command times out
35
+ def test_brpoplpush_raises
36
+ assert_raises(Redis::Distributed::CannotDistribute) do
37
+ r.brpoplpush("foo", "bar")
38
+ end
39
+ end
51
40
 
52
- assert r.nodes.all? { |node| node.client.timeout == 1 }
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 File.expand_path("./helper", File.dirname(__FILE__))
4
- require "redis/distributed"
3
+ require "helper"
4
+ require "lint/hashes"
5
5
 
6
- setup do
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
- load './test/lint/hashes.rb'
8
+ include Helper::Distributed
9
+ include Lint::Hashes
10
+ end
@@ -1,23 +1,22 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.expand_path("./helper", File.dirname(__FILE__))
4
- require "redis/distributed"
3
+ require "helper"
4
+ require "lint/lists"
5
5
 
6
- setup do
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
- load './test/lint/lists.rb'
8
+ include Helper::Distributed
9
+ include Lint::Lists
12
10
 
13
- test "RPOPLPUSH" do |r|
14
- assert_raise Redis::Distributed::CannotDistribute do
15
- r.rpoplpush("foo", "bar")
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
- test "BRPOPLPUSH" do |r|
20
- assert_raise Redis::Distributed::CannotDistribute do
21
- r.brpoplpush("foo", "bar", 1)
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 File.expand_path("./helper", File.dirname(__FILE__))
4
- require "redis/distributed"
3
+ require "helper"
4
+ require "lint/sets"
5
5
 
6
- setup do
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
- load './test/lint/sets.rb'
8
+ include Helper::Distributed
9
+ include Lint::Sets
12
10
 
13
- test "SMOVE" do |r|
14
- assert_raise Redis::Distributed::CannotDistribute do
15
- r.sadd "foo", "s1"
16
- r.sadd "bar", "s2"
11
+ def test_smove
12
+ assert_raise Redis::Distributed::CannotDistribute do
13
+ r.sadd "foo", "s1"
14
+ r.sadd "bar", "s2"
17
15
 
18
- r.smove("foo", "bar", "s1")
16
+ r.smove("foo", "bar", "s1")
17
+ end
19
18
  end
20
- end
21
19
 
22
- test "SINTER" do |r|
23
- assert_raise Redis::Distributed::CannotDistribute do
24
- r.sadd "foo", "s1"
25
- r.sadd "foo", "s2"
26
- r.sadd "bar", "s2"
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
- r.sinter("foo", "bar")
26
+ r.sinter("foo", "bar")
27
+ end
29
28
  end
30
- end
31
29
 
32
- test "SINTERSTORE" do |r|
33
- assert_raise Redis::Distributed::CannotDistribute do
34
- r.sadd "foo", "s1"
35
- r.sadd "foo", "s2"
36
- r.sadd "bar", "s2"
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
- r.sinterstore("baz", "foo", "bar")
36
+ r.sinterstore("baz", "foo", "bar")
37
+ end
39
38
  end
40
- end
41
39
 
42
- test "SUNION" do |r|
43
- assert_raise Redis::Distributed::CannotDistribute do
44
- r.sadd "foo", "s1"
45
- r.sadd "foo", "s2"
46
- r.sadd "bar", "s2"
47
- r.sadd "bar", "s3"
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
- r.sunion("foo", "bar")
47
+ r.sunion("foo", "bar")
48
+ end
50
49
  end
51
- end
52
50
 
53
- test "SUNIONSTORE" do |r|
54
- assert_raise Redis::Distributed::CannotDistribute do
55
- r.sadd "foo", "s1"
56
- r.sadd "foo", "s2"
57
- r.sadd "bar", "s2"
58
- r.sadd "bar", "s3"
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
- r.sunionstore("baz", "foo", "bar")
58
+ r.sunionstore("baz", "foo", "bar")
59
+ end
61
60
  end
62
- end
63
61
 
64
- test "SDIFF" do |r|
65
- assert_raise Redis::Distributed::CannotDistribute do
66
- r.sadd "foo", "s1"
67
- r.sadd "foo", "s2"
68
- r.sadd "bar", "s2"
69
- r.sadd "bar", "s3"
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
- r.sdiff("foo", "bar")
69
+ r.sdiff("foo", "bar")
70
+ end
72
71
  end
73
- end
74
72
 
75
- test "SDIFFSTORE" do |r|
76
- assert_raise Redis::Distributed::CannotDistribute do
77
- r.sadd "foo", "s1"
78
- r.sadd "foo", "s2"
79
- r.sadd "bar", "s2"
80
- r.sadd "bar", "s3"
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
- r.sdiffstore("baz", "foo", "bar")
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 File.expand_path("./helper", File.dirname(__FILE__))
4
- require "redis/distributed"
3
+ require "helper"
4
+ require "lint/sorted_sets"
5
5
 
6
- setup do
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
- load './test/lint/sorted_sets.rb'
8
+ include Helper::Distributed
9
+ include Lint::SortedSets
12
10
 
13
- test "ZCOUNT" do |r|
14
- r.zadd "foo", 1, "s1"
15
- r.zadd "foo", 2, "s2"
16
- r.zadd "foo", 3, "s3"
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
- assert 2 == r.zcount("foo", 2, 3)
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 File.expand_path("./helper", File.dirname(__FILE__))
4
- require "redis/distributed"
3
+ require "helper"
4
+ require "lint/strings"
5
5
 
6
- setup do
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
- load './test/lint/strings.rb'
8
+ include Helper::Distributed
9
+ include Lint::Strings
12
10
 
13
- test "MGET" do |r|
14
- assert_raise Redis::Distributed::CannotDistribute do
15
- r.mget("foo", "bar")
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
- test "MGET mapped" do |r|
20
- assert_raise Redis::Distributed::CannotDistribute do
21
- r.mapped_mget("foo", "bar")
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
- test "MSET" do |r|
26
- assert_raise Redis::Distributed::CannotDistribute do
27
- r.mset(:foo, "s1", :bar, "s2")
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
- test "MSET mapped" do |r|
32
- assert_raise Redis::Distributed::CannotDistribute do
33
- r.mapped_mset(:foo => "s1", :bar => "s2")
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
- test "MSETNX" do |r|
38
- assert_raise Redis::Distributed::CannotDistribute do
39
- r.set("foo", "s1")
40
- r.msetnx(:foo, "s2", :bar, "s3")
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
- test "MSETNX mapped" do |r|
45
- assert_raise Redis::Distributed::CannotDistribute do
46
- r.set("foo", "s1")
47
- r.mapped_msetnx(:foo => "s2", :bar => "s3")
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 File.expand_path("./helper", File.dirname(__FILE__))
4
- require "redis/distributed"
3
+ require "helper"
4
+ require "lint/value_types"
5
5
 
6
- setup do
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
- load "./test/lint/value_types.rb"
8
+ include Helper::Distributed
9
+ include Lint::ValueTypes
12
10
 
13
- test "DEL" do |r|
14
- r.set "foo", "s1"
15
- r.set "bar", "s2"
16
- r.set "baz", "s3"
11
+ def test_del
12
+ r.set "foo", "s1"
13
+ r.set "bar", "s2"
14
+ r.set "baz", "s3"
17
15
 
18
- assert ["bar", "baz", "foo"] == r.keys("*").sort
16
+ assert_equal ["bar", "baz", "foo"], r.keys("*").sort
19
17
 
20
- assert 1 == r.del("foo")
18
+ assert_equal 1, r.del("foo")
21
19
 
22
- assert ["bar", "baz"] == r.keys("*").sort
20
+ assert_equal ["bar", "baz"], r.keys("*").sort
23
21
 
24
- assert 2 == r.del("bar", "baz")
22
+ assert_equal 2, r.del("bar", "baz")
25
23
 
26
- assert [] == r.keys("*").sort
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
- test "RANDOMKEY" do |r|
30
- assert_raise Redis::Distributed::CannotDistribute do
31
- r.randomkey
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
- test "RENAME" do |r|
36
- assert_raise Redis::Distributed::CannotDistribute do
37
- r.set("foo", "s1")
38
- r.rename "foo", "bar"
43
+ def test_randomkey
44
+ assert_raise Redis::Distributed::CannotDistribute do
45
+ r.randomkey
46
+ end
39
47
  end
40
48
 
41
- assert "s1" == r.get("foo")
42
- assert nil == r.get("bar")
43
- end
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
- test "RENAMENX" do |r|
46
- assert_raise Redis::Distributed::CannotDistribute do
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
- assert "s1" == r.get("foo")
52
- assert nil == r.get("bar")
53
- end
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
- test "DBSIZE" do |r|
56
- assert [0] == r.dbsize
65
+ assert_equal "s1", r.get("foo")
66
+ assert_equal nil , r.get("bar")
67
+ end
57
68
 
58
- r.set("foo", "s1")
69
+ def test_dbsize
70
+ assert_equal [0], r.dbsize
59
71
 
60
- assert [1] == r.dbsize
61
- end
72
+ r.set("foo", "s1")
62
73
 
63
- test "FLUSHDB" do |r|
64
- r.set("foo", "s1")
65
- r.set("bar", "s2")
74
+ assert_equal [1], r.dbsize
75
+ end
66
76
 
67
- assert [2] == r.dbsize
77
+ def test_flushdb
78
+ r.set("foo", "s1")
79
+ r.set("bar", "s2")
68
80
 
69
- r.flushdb
81
+ assert_equal [2], r.dbsize
70
82
 
71
- assert [0] == r.dbsize
83
+ r.flushdb
84
+
85
+ assert_equal [0], r.dbsize
86
+ end
72
87
  end