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,133 +1,151 @@
1
- require File.expand_path("../redis_mock", File.dirname(__FILE__))
1
+ module Lint
2
2
 
3
- include RedisMock::Helper
3
+ module Strings
4
4
 
5
- test "SET and GET" do |r|
6
- r.set("foo", "s1")
5
+ def test_set_and_get
6
+ r.set("foo", "s1")
7
7
 
8
- assert "s1" == r.get("foo")
9
- end
8
+ assert_equal "s1", r.get("foo")
9
+ end
10
10
 
11
- test "SET and GET with brackets" do |r|
12
- r["foo"] = "s1"
11
+ def test_set_and_get_with_brackets
12
+ r["foo"] = "s1"
13
13
 
14
- assert "s1" == r["foo"]
15
- end
14
+ assert_equal "s1", r["foo"]
15
+ end
16
16
 
17
- test "SET and GET with brackets and symbol" do |r|
18
- r[:foo] = "s1"
17
+ def test_set_and_get_with_brackets_and_symbol
18
+ r[:foo] = "s1"
19
19
 
20
- assert "s1" == r[:foo]
21
- end
20
+ assert_equal "s1", r[:foo]
21
+ end
22
22
 
23
- test "SET and GET with newline characters" do |r|
24
- r.set("foo", "1\n")
23
+ def test_set_and_get_with_newline_characters
24
+ r.set("foo", "1\n")
25
25
 
26
- assert "1\n" == r.get("foo")
27
- end
26
+ assert_equal "1\n", r.get("foo")
27
+ end
28
28
 
29
- test "SET and GET with ASCII characters" do |r|
30
- with_external_encoding("ASCII-8BIT") do
31
- (0..255).each do |i|
32
- str = "#{i.chr}---#{i.chr}"
33
- r.set("foo", str)
29
+ def test_set_and_get_with_ascii_characters
30
+ if defined?(Encoding)
31
+ with_external_encoding("ASCII-8BIT") do
32
+ (0..255).each do |i|
33
+ str = "#{i.chr}---#{i.chr}"
34
+ r.set("foo", str)
35
+
36
+ assert_equal str, r.get("foo")
37
+ end
38
+ end
39
+ end
40
+ end
34
41
 
35
- assert str == r.get("foo")
42
+ def test_setex
43
+ assert r.setex("foo", 1, "bar")
44
+ assert_equal "bar", r.get("foo")
45
+ assert [0, 1].include? r.ttl("foo")
36
46
  end
37
- end
38
- end if defined?(Encoding)
39
47
 
40
- test "SETEX" do
41
- redis_mock(:setex => lambda { |*args| "+#{args.join(" ")}" }) do
42
- r = Redis.new(OPTIONS.merge(:port => 6380))
48
+ def test_psetex
49
+ return if version < "2.5.4"
43
50
 
44
- assert_equal "foo 1 s1", r.setex("foo", 1, "s1")
45
- end
46
- end
51
+ assert r.psetex("foo", 1000, "bar")
52
+ assert_equal "bar", r.get("foo")
53
+ assert [0, 1].include? r.ttl("foo")
54
+ end
47
55
 
48
- test "GETSET" do |r|
49
- r.set("foo", "bar")
56
+ def test_getset
57
+ r.set("foo", "bar")
50
58
 
51
- assert "bar" == r.getset("foo", "baz")
52
- assert "baz" == r.get("foo")
53
- end
59
+ assert_equal "bar", r.getset("foo", "baz")
60
+ assert_equal "baz", r.get("foo")
61
+ end
54
62
 
55
- test "SETNX" do |r|
56
- r.set("foo", "s1")
63
+ def test_setnx
64
+ r.set("foo", "s1")
57
65
 
58
- assert "s1" == r.get("foo")
66
+ assert_equal "s1", r.get("foo")
59
67
 
60
- r.setnx("foo", "s2")
68
+ r.setnx("foo", "s2")
61
69
 
62
- assert "s1" == r.get("foo")
63
- end
70
+ assert_equal "s1", r.get("foo")
71
+ end
64
72
 
65
- test "INCR" do |r|
66
- assert 1 == r.incr("foo")
67
- assert 2 == r.incr("foo")
68
- assert 3 == r.incr("foo")
69
- end
73
+ def test_incr
74
+ assert_equal 1, r.incr("foo")
75
+ assert_equal 2, r.incr("foo")
76
+ assert_equal 3, r.incr("foo")
77
+ end
70
78
 
71
- test "INCRBY" do |r|
72
- assert 1 == r.incrby("foo", 1)
73
- assert 3 == r.incrby("foo", 2)
74
- assert 6 == r.incrby("foo", 3)
75
- end
79
+ def test_incrby
80
+ assert_equal 1, r.incrby("foo", 1)
81
+ assert_equal 3, r.incrby("foo", 2)
82
+ assert_equal 6, r.incrby("foo", 3)
83
+ end
76
84
 
77
- test "DECR" do |r|
78
- r.set("foo", 3)
85
+ def test_incrbyfloat
86
+ return if version < "2.5.4"
79
87
 
80
- assert 2 == r.decr("foo")
81
- assert 1 == r.decr("foo")
82
- assert 0 == r.decr("foo")
83
- end
88
+ assert_equal 1.23, r.incrbyfloat("foo", 1.23)
89
+ assert_equal 2 , r.incrbyfloat("foo", 0.77)
90
+ assert_equal 1.9 , r.incrbyfloat("foo", -0.1)
91
+ end
84
92
 
85
- test "DECRBY" do |r|
86
- r.set("foo", 6)
93
+ def test_decr
94
+ r.set("foo", 3)
87
95
 
88
- assert 3 == r.decrby("foo", 3)
89
- assert 1 == r.decrby("foo", 2)
90
- assert 0 == r.decrby("foo", 1)
91
- end
96
+ assert_equal 2, r.decr("foo")
97
+ assert_equal 1, r.decr("foo")
98
+ assert_equal 0, r.decr("foo")
99
+ end
92
100
 
93
- test "APPEND" do |r|
94
- r.set "foo", "s"
95
- r.append "foo", "1"
101
+ def test_decrby
102
+ r.set("foo", 6)
96
103
 
97
- assert "s1" == r.get("foo")
98
- end
104
+ assert_equal 3, r.decrby("foo", 3)
105
+ assert_equal 1, r.decrby("foo", 2)
106
+ assert_equal 0, r.decrby("foo", 1)
107
+ end
99
108
 
100
- test "GETBIT" do |r|
101
- r.set("foo", "a")
109
+ def test_append
110
+ r.set "foo", "s"
111
+ r.append "foo", "1"
102
112
 
103
- assert_equal 1, r.getbit("foo", 1)
104
- assert_equal 1, r.getbit("foo", 2)
105
- assert_equal 0, r.getbit("foo", 3)
106
- assert_equal 0, r.getbit("foo", 4)
107
- assert_equal 0, r.getbit("foo", 5)
108
- assert_equal 0, r.getbit("foo", 6)
109
- assert_equal 1, r.getbit("foo", 7)
110
- end
113
+ assert_equal "s1", r.get("foo")
114
+ end
111
115
 
112
- test "SETBIT" do |r|
113
- r.set("foo", "a")
116
+ def test_getbit
117
+ r.set("foo", "a")
114
118
 
115
- r.setbit("foo", 6, 1)
119
+ assert_equal 1, r.getbit("foo", 1)
120
+ assert_equal 1, r.getbit("foo", 2)
121
+ assert_equal 0, r.getbit("foo", 3)
122
+ assert_equal 0, r.getbit("foo", 4)
123
+ assert_equal 0, r.getbit("foo", 5)
124
+ assert_equal 0, r.getbit("foo", 6)
125
+ assert_equal 1, r.getbit("foo", 7)
126
+ end
116
127
 
117
- assert_equal "c", r.get("foo")
118
- end
128
+ def test_setbit
129
+ r.set("foo", "a")
119
130
 
120
- test "GETRANGE" do |r|
121
- r.set("foo", "abcde")
131
+ r.setbit("foo", 6, 1)
122
132
 
123
- assert_equal "bcd", r.getrange("foo", 1, 3)
124
- assert_equal "abcde", r.getrange("foo", 0, -1)
125
- end
133
+ assert_equal "c", r.get("foo")
134
+ end
126
135
 
127
- test "SETRANGE" do |r|
128
- r.set("foo", "abcde")
136
+ def test_getrange
137
+ r.set("foo", "abcde")
129
138
 
130
- r.setrange("foo", 1, "bar")
139
+ assert_equal "bcd", r.getrange("foo", 1, 3)
140
+ assert_equal "abcde", r.getrange("foo", 0, -1)
141
+ end
131
142
 
132
- assert_equal "abare", r.get("foo")
143
+ def test_setrange
144
+ r.set("foo", "abcde")
145
+
146
+ r.setrange("foo", 1, "bar")
147
+
148
+ assert_equal "abare", r.get("foo")
149
+ end
150
+ end
133
151
  end
@@ -1,81 +1,102 @@
1
- require File.expand_path("../redis_mock", File.dirname(__FILE__))
1
+ module Lint
2
2
 
3
- include RedisMock::Helper
3
+ module ValueTypes
4
4
 
5
- test "EXISTS" do |r|
6
- assert false == r.exists("foo")
5
+ def test_exists
6
+ assert_equal false, r.exists("foo")
7
7
 
8
- r.set("foo", "s1")
8
+ r.set("foo", "s1")
9
9
 
10
- assert true == r.exists("foo")
11
- end
10
+ assert_equal true, r.exists("foo")
11
+ end
12
12
 
13
- test "TYPE" do |r|
14
- assert "none" == r.type("foo")
13
+ def test_type
14
+ assert_equal "none", r.type("foo")
15
15
 
16
- r.set("foo", "s1")
16
+ r.set("foo", "s1")
17
17
 
18
- assert "string" == r.type("foo")
19
- end
18
+ assert_equal "string", r.type("foo")
19
+ end
20
20
 
21
- test "KEYS" do |r|
22
- r.set("f", "s1")
23
- r.set("fo", "s2")
24
- r.set("foo", "s3")
21
+ def test_keys
22
+ r.set("f", "s1")
23
+ r.set("fo", "s2")
24
+ r.set("foo", "s3")
25
25
 
26
- assert ["f","fo", "foo"] == r.keys("f*").sort
27
- end
26
+ assert_equal ["f","fo", "foo"], r.keys("f*").sort
27
+ end
28
28
 
29
- test "EXPIRE" do |r|
30
- redis_mock(:expire => lambda { |*args| args == ["foo", "1"] ? ":1" : ":0" }) do
31
- r = Redis.new(OPTIONS.merge(:port => 6380))
29
+ def test_expire
30
+ r.set("foo", "s1")
31
+ assert r.expire("foo", 1)
32
+ assert [0, 1].include? r.ttl("foo")
33
+ end
32
34
 
33
- assert r.expire("foo", 1)
34
- end
35
- end
35
+ def test_pexpire
36
+ return if version < "2.5.4"
36
37
 
37
- test "EXPIREAT" do |r|
38
- redis_mock(:expireat => lambda { |*args| args == ["foo", "1328236326"] ? ":1" : ":0" }) do
39
- r = Redis.new(OPTIONS.merge(:port => 6380))
38
+ r.set("foo", "s1")
39
+ assert r.pexpire("foo", 1000)
40
+ assert [0, 1].include? r.ttl("foo")
41
+ end
40
42
 
41
- assert r.expireat("foo", 1328236326)
42
- end
43
- end
43
+ def test_expireat
44
+ r.set("foo", "s1")
45
+ assert r.expireat("foo", (Time.now + 1).to_i)
46
+ assert [0, 1].include? r.ttl("foo")
47
+ end
44
48
 
45
- test "PERSIST" do |r|
46
- r.set("foo", "s1")
47
- r.expire("foo", 1)
48
- r.persist("foo")
49
+ def test_pexpireat
50
+ return if version < "2.5.4"
49
51
 
50
- assert(-1 == r.ttl("foo"))
51
- end
52
+ r.set("foo", "s1")
53
+ assert r.pexpireat("foo", (Time.now + 1).to_i * 1_000)
54
+ assert [0, 1].include? r.ttl("foo")
55
+ end
52
56
 
53
- test "TTL" do |r|
54
- r.set("foo", "s1")
55
- r.expire("foo", 1)
57
+ def test_persist
58
+ r.set("foo", "s1")
59
+ r.expire("foo", 1)
60
+ r.persist("foo")
56
61
 
57
- assert 1 == r.ttl("foo")
58
- end
62
+ assert(-1 == r.ttl("foo"))
63
+ end
64
+
65
+ def test_ttl
66
+ r.set("foo", "s1")
67
+ r.expire("foo", 1)
68
+ assert [0, 1].include? r.ttl("foo")
69
+ end
59
70
 
60
- test "MOVE" do |r|
61
- r.select 14
62
- r.flushdb
71
+ def test_pttl
72
+ return if version < "2.5.4"
63
73
 
64
- r.set "bar", "s3"
74
+ r.set("foo", "s1")
75
+ r.expire("foo", 1)
76
+ assert 1000 >= r.pttl("foo")
77
+ end
65
78
 
66
- r.select 15
79
+ def test_move
80
+ r.select 14
81
+ r.flushdb
67
82
 
68
- r.set "foo", "s1"
69
- r.set "bar", "s2"
83
+ r.set "bar", "s3"
70
84
 
71
- assert r.move("foo", 14)
72
- assert nil == r.get("foo")
85
+ r.select 15
73
86
 
74
- assert !r.move("bar", 14)
75
- assert "s2" == r.get("bar")
87
+ r.set "foo", "s1"
88
+ r.set "bar", "s2"
76
89
 
77
- r.select 14
90
+ assert r.move("foo", 14)
91
+ assert_equal nil, r.get("foo")
78
92
 
79
- assert "s1" == r.get("foo")
80
- assert "s3" == r.get("bar")
93
+ assert !r.move("bar", 14)
94
+ assert_equal "s2", r.get("bar")
95
+
96
+ r.select 14
97
+
98
+ assert_equal "s1", r.get("foo")
99
+ assert_equal "s3", r.get("bar")
100
+ end
101
+ end
81
102
  end
@@ -1,21 +1,26 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.expand_path("./helper", File.dirname(__FILE__))
3
+ require "helper"
4
4
 
5
- setup do
6
- init Redis.new(OPTIONS)
7
- end
5
+ class TestPersistenceControlCommands < Test::Unit::TestCase
6
+
7
+ include Helper::Client
8
8
 
9
- test "SAVE and BGSAVE" do |r|
10
- assert_nothing_raised do
11
- r.save
9
+ def test_save
10
+ redis_mock(:save => lambda { "+SAVE" }) do |redis|
11
+ assert_equal "SAVE", redis.save
12
+ end
12
13
  end
13
14
 
14
- assert_nothing_raised do
15
- r.bgsave
15
+ def test_bgsave
16
+ redis_mock(:bgsave => lambda { "+BGSAVE" }) do |redis|
17
+ assert_equal "BGSAVE", redis.bgsave
18
+ end
16
19
  end
17
- end
18
20
 
19
- test "LASTSAVE" do |r|
20
- assert Time.at(r.lastsave) <= Time.now
21
+ def test_lastsave
22
+ redis_mock(:lastsave => lambda { "+LASTSAVE" }) do |redis|
23
+ assert_equal "LASTSAVE", redis.lastsave
24
+ end
25
+ end
21
26
  end
@@ -1,186 +1,195 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.expand_path("./helper", File.dirname(__FILE__))
3
+ require "helper"
4
4
 
5
- setup do
6
- init Redis.new(OPTIONS)
7
- end
5
+ class TestPipeliningCommands < Test::Unit::TestCase
8
6
 
9
- test "BULK commands" do |r|
10
- r.pipelined do
11
- r.lpush "foo", "s1"
12
- r.lpush "foo", "s2"
13
- end
7
+ include Helper::Client
14
8
 
15
- assert 2 == r.llen("foo")
16
- assert "s2" == r.lpop("foo")
17
- assert "s1" == r.lpop("foo")
18
- end
9
+ def test_bulk_commands
10
+ r.pipelined do
11
+ r.lpush "foo", "s1"
12
+ r.lpush "foo", "s2"
13
+ end
19
14
 
20
- test "MULTI_BULK commands" do |r|
21
- r.pipelined do
22
- r.mset("foo", "s1", "bar", "s2")
23
- r.mset("baz", "s3", "qux", "s4")
15
+ assert_equal 2, r.llen("foo")
16
+ assert_equal "s2", r.lpop("foo")
17
+ assert_equal "s1", r.lpop("foo")
24
18
  end
25
19
 
26
- assert "s1" == r.get("foo")
27
- assert "s2" == r.get("bar")
28
- assert "s3" == r.get("baz")
29
- assert "s4" == r.get("qux")
30
- end
20
+ def test_multi_bulk_commands
21
+ r.pipelined do
22
+ r.mset("foo", "s1", "bar", "s2")
23
+ r.mset("baz", "s3", "qux", "s4")
24
+ end
31
25
 
32
- test "BULK and MULTI_BULK commands mixed" do |r|
33
- r.pipelined do
34
- r.lpush "foo", "s1"
35
- r.lpush "foo", "s2"
36
- r.mset("baz", "s3", "qux", "s4")
26
+ assert_equal "s1", r.get("foo")
27
+ assert_equal "s2", r.get("bar")
28
+ assert_equal "s3", r.get("baz")
29
+ assert_equal "s4", r.get("qux")
37
30
  end
38
31
 
39
- assert 2 == r.llen("foo")
40
- assert "s2" == r.lpop("foo")
41
- assert "s1" == r.lpop("foo")
42
- assert "s3" == r.get("baz")
43
- assert "s4" == r.get("qux")
44
- end
32
+ def test_bulk_and_multi_bulk_commands_mixed
33
+ r.pipelined do
34
+ r.lpush "foo", "s1"
35
+ r.lpush "foo", "s2"
36
+ r.mset("baz", "s3", "qux", "s4")
37
+ end
45
38
 
46
- test "MULTI_BULK and BULK commands mixed" do |r|
47
- r.pipelined do
48
- r.mset("baz", "s3", "qux", "s4")
49
- r.lpush "foo", "s1"
50
- r.lpush "foo", "s2"
39
+ assert_equal 2, r.llen("foo")
40
+ assert_equal "s2", r.lpop("foo")
41
+ assert_equal "s1", r.lpop("foo")
42
+ assert_equal "s3", r.get("baz")
43
+ assert_equal "s4", r.get("qux")
51
44
  end
52
45
 
53
- assert 2 == r.llen("foo")
54
- assert "s2" == r.lpop("foo")
55
- assert "s1" == r.lpop("foo")
56
- assert "s3" == r.get("baz")
57
- assert "s4" == r.get("qux")
58
- end
59
-
60
- test "Pipelined with an empty block" do |r|
61
- assert_nothing_raised do
46
+ def test_multi_bulk_and_bulk_commands_mixed
62
47
  r.pipelined do
48
+ r.mset("baz", "s3", "qux", "s4")
49
+ r.lpush "foo", "s1"
50
+ r.lpush "foo", "s2"
63
51
  end
52
+
53
+ assert_equal 2, r.llen("foo")
54
+ assert_equal "s2", r.lpop("foo")
55
+ assert_equal "s1", r.lpop("foo")
56
+ assert_equal "s3", r.get("baz")
57
+ assert_equal "s4", r.get("qux")
64
58
  end
65
59
 
66
- assert 0 == r.dbsize
67
- end
60
+ def test_pipelined_with_an_empty_block
61
+ assert_nothing_raised do
62
+ r.pipelined do
63
+ end
64
+ end
68
65
 
69
- test "Returning the result of a pipeline" do |r|
70
- result = r.pipelined do
71
- r.set "foo", "bar"
72
- r.get "foo"
73
- r.get "bar"
66
+ assert_equal 0, r.dbsize
74
67
  end
75
68
 
76
- assert ["OK", "bar", nil] == result
77
- end
69
+ def test_returning_the_result_of_a_pipeline
70
+ result = r.pipelined do
71
+ r.set "foo", "bar"
72
+ r.get "foo"
73
+ r.get "bar"
74
+ end
78
75
 
79
- test "Assignment of results inside the block" do |r|
80
- r.pipelined do
81
- @first = r.sadd("foo", 1)
82
- @second = r.sadd("foo", 1)
76
+ assert_equal ["OK", "bar", nil], result
83
77
  end
84
78
 
85
- assert_equal true, @first.value
86
- assert_equal false, @second.value
87
- end
88
-
89
- # Although we could support accessing the values in these futures,
90
- # it doesn't make a lot of sense.
91
- test "Assignment of results inside the block with errors" do |r|
92
- assert_raise do
79
+ def test_assignment_of_results_inside_the_block
93
80
  r.pipelined do
94
- r.doesnt_exist
95
81
  @first = r.sadd("foo", 1)
96
- r.doesnt_exist
97
82
  @second = r.sadd("foo", 1)
98
- r.doesnt_exist
99
83
  end
100
- end
101
84
 
102
- assert_raise(Redis::FutureNotReady) { @first.value }
103
- assert_raise(Redis::FutureNotReady) { @second.value }
104
- end
85
+ assert_equal true, @first.value
86
+ assert_equal false, @second.value
87
+ end
88
+
89
+ # Although we could support accessing the values in these futures,
90
+ # it doesn't make a lot of sense.
91
+ def test_assignment_of_results_inside_the_block_with_errors
92
+ assert_raise(Redis::CommandError) do
93
+ r.pipelined do
94
+ r.doesnt_exist
95
+ @first = r.sadd("foo", 1)
96
+ r.doesnt_exist
97
+ @second = r.sadd("foo", 1)
98
+ r.doesnt_exist
99
+ end
100
+ end
105
101
 
106
- test "Assignment of results inside a nested block" do |r|
107
- r.pipelined do
108
- @first = r.sadd("foo", 1)
102
+ assert_raise(Redis::FutureNotReady) { @first.value }
103
+ assert_raise(Redis::FutureNotReady) { @second.value }
104
+ end
109
105
 
106
+ def test_assignment_of_results_inside_a_nested_block
110
107
  r.pipelined do
111
- @second = r.sadd("foo", 1)
108
+ @first = r.sadd("foo", 1)
109
+
110
+ r.pipelined do
111
+ @second = r.sadd("foo", 1)
112
+ end
112
113
  end
114
+
115
+ assert_equal true, @first.value
116
+ assert_equal false, @second.value
113
117
  end
114
118
 
115
- assert_equal true, @first.value
116
- assert_equal false, @second.value
117
- end
119
+ def test_futures_raise_when_confused_with_something_else
120
+ r.pipelined do
121
+ @result = r.sadd("foo", 1)
122
+ end
118
123
 
119
- test "Futures raise when confused with something else" do |r|
120
- r.pipelined do
121
- @result = r.sadd("foo", 1)
124
+ assert_raise(NoMethodError) { @result.to_s }
122
125
  end
123
126
 
124
- assert_raise(NoMethodError) { @result.to_s }
125
- end
126
-
127
- test "Futures raise when trying to access their values too early" do |r|
128
- r.pipelined do
129
- assert_raise(Redis::FutureNotReady) do
130
- r.sadd("foo", 1).value
127
+ def test_futures_raise_when_trying_to_access_their_values_too_early
128
+ r.pipelined do
129
+ assert_raise(Redis::FutureNotReady) do
130
+ r.sadd("foo", 1).value
131
+ end
131
132
  end
132
133
  end
133
- end
134
134
 
135
- test "Returning the result of an empty pipeline" do |r|
136
- result = r.pipelined do
137
- end
135
+ def test_returning_the_result_of_an_empty_pipeline
136
+ result = r.pipelined do
137
+ end
138
138
 
139
- assert [] == result
140
- end
139
+ assert_equal [], result
140
+ end
141
141
 
142
- test "Nesting pipeline blocks" do |r|
143
- r.pipelined do
144
- r.set("foo", "s1")
142
+ def test_nesting_pipeline_blocks
145
143
  r.pipelined do
146
- r.set("bar", "s2")
144
+ r.set("foo", "s1")
145
+ r.pipelined do
146
+ r.set("bar", "s2")
147
+ end
147
148
  end
149
+
150
+ assert_equal "s1", r.get("foo")
151
+ assert_equal "s2", r.get("bar")
148
152
  end
149
153
 
150
- assert "s1" == r.get("foo")
151
- assert "s2" == r.get("bar")
152
- end
154
+ def test_info_in_a_pipeline_returns_hash
155
+ result = r.pipelined do
156
+ r.info
157
+ end
153
158
 
154
- test "INFO in a pipeline returns hash" do |r|
155
- result = r.pipelined do
156
- r.info
159
+ assert result.first.kind_of?(Hash)
157
160
  end
158
161
 
159
- assert result.first.kind_of?(Hash)
160
- end
162
+ def test_config_get_in_a_pipeline_returns_hash
163
+ result = r.pipelined do
164
+ r.config(:get, "*")
165
+ end
161
166
 
162
- test "CONFIG GET in a pipeline returns hash" do |r|
163
- result = r.pipelined do
164
- r.config(:get, "*")
167
+ assert result.first.kind_of?(Hash)
165
168
  end
166
169
 
167
- assert result.first.kind_of?(Hash)
168
- end
170
+ def test_hgetall_in_a_pipeline_returns_hash
171
+ r.hmset("hash", "field", "value")
172
+ result = r.pipelined do
173
+ r.hgetall("hash")
174
+ end
169
175
 
170
- test "HGETALL in a pipeline returns hash" do |r|
171
- r.hmset("hash", "field", "value")
172
- result = r.pipelined do
173
- r.hgetall("hash")
176
+ assert_equal result.first, { "field" => "value" }
174
177
  end
175
178
 
176
- assert result.first == { "field" => "value" }
177
- end
179
+ def test_keys_in_a_pipeline
180
+ r.set("key", "value")
181
+ result = r.pipelined do
182
+ r.keys("*")
183
+ end
178
184
 
179
- test "KEYS in a pipeline" do |r|
180
- r.set("key", "value")
181
- result = r.pipelined do
182
- r.keys("*")
185
+ assert_equal ["key"], result.first
183
186
  end
184
187
 
185
- assert ["key"] == result.first
188
+ def test_pipeline_yields_a_connection
189
+ r.pipelined do |p|
190
+ p.set("foo", "bar")
191
+ end
192
+
193
+ assert_equal "bar", r.get("foo")
194
+ end
186
195
  end