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
@@ -0,0 +1,124 @@
1
+ module Lint
2
+
3
+ module BlockingCommands
4
+
5
+ def setup
6
+ super
7
+
8
+ r.rpush("{zap}foo", "s1")
9
+ r.rpush("{zap}foo", "s2")
10
+ r.rpush("{zap}bar", "s1")
11
+ r.rpush("{zap}bar", "s2")
12
+ end
13
+
14
+ def to_protocol(obj)
15
+ case obj
16
+ when String
17
+ "$#{obj.length}\r\n#{obj}\r\n"
18
+ when Array
19
+ "*#{obj.length}\r\n" + obj.map { |e| to_protocol(e) }.join
20
+ else
21
+ fail
22
+ end
23
+ end
24
+
25
+ def mock(options = {}, &blk)
26
+ commands = {
27
+ :blpop => lambda do |*args|
28
+ sleep options[:delay] if options.has_key?(:delay)
29
+ to_protocol([args.first, args.last])
30
+ end,
31
+ :brpop => lambda do |*args|
32
+ sleep options[:delay] if options.has_key?(:delay)
33
+ to_protocol([args.first, args.last])
34
+ end,
35
+ :brpoplpush => lambda do |*args|
36
+ sleep options[:delay] if options.has_key?(:delay)
37
+ to_protocol(args.last)
38
+ end,
39
+ }
40
+
41
+ redis_mock(commands, &blk)
42
+ end
43
+
44
+ def test_blpop
45
+ assert_equal ["{zap}foo", "s1"], r.blpop("{zap}foo")
46
+ assert_equal ["{zap}foo", "s2"], r.blpop(["{zap}foo"])
47
+ assert_equal ["{zap}bar", "s1"], r.blpop(["{zap}bar", "{zap}foo"])
48
+ assert_equal ["{zap}bar", "s2"], r.blpop(["{zap}foo", "{zap}bar"])
49
+ end
50
+
51
+ def test_blpop_timeout
52
+ mock do |r|
53
+ assert_equal ["{zap}foo", "0"], r.blpop("{zap}foo")
54
+ assert_equal ["{zap}foo", "1"], r.blpop("{zap}foo", :timeout => 1)
55
+ end
56
+ end
57
+
58
+ def test_blpop_with_old_prototype
59
+ assert_equal ["{zap}foo", "s1"], r.blpop("{zap}foo", 0)
60
+ assert_equal ["{zap}foo", "s2"], r.blpop("{zap}foo", 0)
61
+ assert_equal ["{zap}bar", "s1"], r.blpop("{zap}bar", "{zap}foo", 0)
62
+ assert_equal ["{zap}bar", "s2"], r.blpop("{zap}foo", "{zap}bar", 0)
63
+ end
64
+
65
+ def test_blpop_timeout_with_old_prototype
66
+ mock do |r|
67
+ assert_equal ["{zap}foo", "0"], r.blpop("{zap}foo", 0)
68
+ assert_equal ["{zap}foo", "1"], r.blpop("{zap}foo", 1)
69
+ end
70
+ end
71
+
72
+ def test_brpop
73
+ assert_equal ["{zap}foo", "s2"], r.brpop("{zap}foo")
74
+ assert_equal ["{zap}foo", "s1"], r.brpop(["{zap}foo"])
75
+ assert_equal ["{zap}bar", "s2"], r.brpop(["{zap}bar", "{zap}foo"])
76
+ assert_equal ["{zap}bar", "s1"], r.brpop(["{zap}foo", "{zap}bar"])
77
+ end
78
+
79
+ def test_brpop_timeout
80
+ mock do |r|
81
+ assert_equal ["{zap}foo", "0"], r.brpop("{zap}foo")
82
+ assert_equal ["{zap}foo", "1"], r.brpop("{zap}foo", :timeout => 1)
83
+ end
84
+ end
85
+
86
+ def test_brpop_with_old_prototype
87
+ assert_equal ["{zap}foo", "s2"], r.brpop("{zap}foo", 0)
88
+ assert_equal ["{zap}foo", "s1"], r.brpop("{zap}foo", 0)
89
+ assert_equal ["{zap}bar", "s2"], r.brpop("{zap}bar", "{zap}foo", 0)
90
+ assert_equal ["{zap}bar", "s1"], r.brpop("{zap}foo", "{zap}bar", 0)
91
+ end
92
+
93
+ def test_brpop_timeout_with_old_prototype
94
+ mock do |r|
95
+ assert_equal ["{zap}foo", "0"], r.brpop("{zap}foo", 0)
96
+ assert_equal ["{zap}foo", "1"], r.brpop("{zap}foo", 1)
97
+ end
98
+ end
99
+
100
+ def test_brpoplpush
101
+ assert_equal "s2", r.brpoplpush("{zap}foo", "{zap}qux")
102
+ assert_equal ["s2"], r.lrange("{zap}qux", 0, -1)
103
+ end
104
+
105
+ def test_brpoplpush_timeout
106
+ mock do |r|
107
+ assert_equal "0", r.brpoplpush("{zap}foo", "{zap}bar")
108
+ assert_equal "1", r.brpoplpush("{zap}foo", "{zap}bar", :timeout => 1)
109
+ end
110
+ end
111
+
112
+ def test_brpoplpush_with_old_prototype
113
+ assert_equal "s2", r.brpoplpush("{zap}foo", "{zap}qux", 0)
114
+ assert_equal ["s2"], r.lrange("{zap}qux", 0, -1)
115
+ end
116
+
117
+ def test_brpoplpush_timeout_with_old_prototype
118
+ mock do |r|
119
+ assert_equal "0", r.brpoplpush("{zap}foo", "{zap}bar", 0)
120
+ assert_equal "1", r.brpoplpush("{zap}foo", "{zap}bar", 1)
121
+ end
122
+ end
123
+ end
124
+ end
@@ -1,140 +1,162 @@
1
- test "HSET and HGET" do |r|
2
- r.hset("foo", "f1", "s1")
1
+ module Lint
3
2
 
4
- assert "s1" == r.hget("foo", "f1")
5
- end
3
+ module Hashes
6
4
 
7
- test "HSETNX" do |r|
8
- r.hset("foo", "f1", "s1")
9
- r.hsetnx("foo", "f1", "s2")
5
+ def test_hset_and_hget
6
+ r.hset("foo", "f1", "s1")
10
7
 
11
- assert "s1" == r.hget("foo", "f1")
8
+ assert_equal "s1", r.hget("foo", "f1")
9
+ end
12
10
 
13
- r.del("foo")
14
- r.hsetnx("foo", "f1", "s2")
11
+ def test_hsetnx
12
+ r.hset("foo", "f1", "s1")
13
+ r.hsetnx("foo", "f1", "s2")
15
14
 
16
- assert "s2" == r.hget("foo", "f1")
17
- end
15
+ assert_equal "s1", r.hget("foo", "f1")
18
16
 
19
- test "HDEL" do |r|
20
- r.hset("foo", "f1", "s1")
17
+ r.del("foo")
18
+ r.hsetnx("foo", "f1", "s2")
21
19
 
22
- assert "s1" == r.hget("foo", "f1")
20
+ assert_equal "s2", r.hget("foo", "f1")
21
+ end
23
22
 
24
- assert 1 == r.hdel("foo", "f1")
23
+ def test_hdel
24
+ r.hset("foo", "f1", "s1")
25
25
 
26
- assert nil == r.hget("foo", "f1")
27
- end
26
+ assert_equal "s1", r.hget("foo", "f1")
28
27
 
29
- test "Variadic HDEL" do |r|
30
- next if version(r) < 203090
28
+ assert_equal 1, r.hdel("foo", "f1")
31
29
 
32
- r.hset("foo", "f1", "s1")
33
- r.hset("foo", "f2", "s2")
30
+ assert_equal nil, r.hget("foo", "f1")
31
+ end
34
32
 
35
- assert "s1" == r.hget("foo", "f1")
36
- assert "s2" == r.hget("foo", "f2")
33
+ def test_variadic_hdel
34
+ return if version < "2.3.9"
37
35
 
38
- assert 2 == r.hdel("foo", ["f1", "f2"])
36
+ r.hset("foo", "f1", "s1")
37
+ r.hset("foo", "f2", "s2")
39
38
 
40
- assert nil == r.hget("foo", "f1")
41
- assert nil == r.hget("foo", "f2")
42
- end
39
+ assert_equal "s1", r.hget("foo", "f1")
40
+ assert_equal "s2", r.hget("foo", "f2")
43
41
 
44
- test "HEXISTS" do |r|
45
- assert false == r.hexists("foo", "f1")
42
+ assert_equal 2, r.hdel("foo", ["f1", "f2"])
46
43
 
47
- r.hset("foo", "f1", "s1")
44
+ assert_equal nil, r.hget("foo", "f1")
45
+ assert_equal nil, r.hget("foo", "f2")
46
+ end
48
47
 
49
- assert r.hexists("foo", "f1")
50
- end
48
+ def test_hexists
49
+ assert_equal false, r.hexists("foo", "f1")
51
50
 
52
- test "HLEN" do |r|
53
- assert 0 == r.hlen("foo")
51
+ r.hset("foo", "f1", "s1")
54
52
 
55
- r.hset("foo", "f1", "s1")
53
+ assert r.hexists("foo", "f1")
54
+ end
56
55
 
57
- assert 1 == r.hlen("foo")
56
+ def test_hlen
57
+ assert_equal 0, r.hlen("foo")
58
58
 
59
- r.hset("foo", "f2", "s2")
59
+ r.hset("foo", "f1", "s1")
60
60
 
61
- assert 2 == r.hlen("foo")
62
- end
61
+ assert_equal 1, r.hlen("foo")
63
62
 
64
- test "HKEYS" do |r|
65
- assert [] == r.hkeys("foo")
63
+ r.hset("foo", "f2", "s2")
66
64
 
67
- r.hset("foo", "f1", "s1")
68
- r.hset("foo", "f2", "s2")
65
+ assert_equal 2, r.hlen("foo")
66
+ end
69
67
 
70
- assert ["f1", "f2"] == r.hkeys("foo")
71
- end
68
+ def test_hkeys
69
+ assert_equal [], r.hkeys("foo")
72
70
 
73
- test "HVALS" do |r|
74
- assert [] == r.hvals("foo")
71
+ r.hset("foo", "f1", "s1")
72
+ r.hset("foo", "f2", "s2")
75
73
 
76
- r.hset("foo", "f1", "s1")
77
- r.hset("foo", "f2", "s2")
74
+ assert_equal ["f1", "f2"], r.hkeys("foo")
75
+ end
78
76
 
79
- assert ["s1", "s2"] == r.hvals("foo")
80
- end
77
+ def test_hvals
78
+ assert_equal [], r.hvals("foo")
81
79
 
82
- test "HGETALL" do |r|
83
- assert({} == r.hgetall("foo"))
80
+ r.hset("foo", "f1", "s1")
81
+ r.hset("foo", "f2", "s2")
84
82
 
85
- r.hset("foo", "f1", "s1")
86
- r.hset("foo", "f2", "s2")
83
+ assert_equal ["s1", "s2"], r.hvals("foo")
84
+ end
87
85
 
88
- assert({"f1" => "s1", "f2" => "s2"} == r.hgetall("foo"))
89
- end
86
+ def test_hgetall
87
+ assert({} == r.hgetall("foo"))
90
88
 
91
- test "HMSET" do |r|
92
- r.hmset("hash", "foo1", "bar1", "foo2", "bar2")
89
+ r.hset("foo", "f1", "s1")
90
+ r.hset("foo", "f2", "s2")
93
91
 
94
- assert "bar1" == r.hget("hash", "foo1")
95
- assert "bar2" == r.hget("hash", "foo2")
96
- end
92
+ assert({"f1" => "s1", "f2" => "s2"} == r.hgetall("foo"))
93
+ end
97
94
 
98
- test "HMSET with invalid arguments" do |r|
99
- assert_raise(Redis::CommandError) do
100
- r.hmset("hash", "foo1", "bar1", "foo2", "bar2", "foo3")
101
- end
102
- end
95
+ def test_hmset
96
+ r.hmset("hash", "foo1", "bar1", "foo2", "bar2")
103
97
 
104
- test "Mapped HMSET" do |r|
105
- r.mapped_hmset("foo", :f1 => "s1", :f2 => "s2")
98
+ assert_equal "bar1", r.hget("hash", "foo1")
99
+ assert_equal "bar2", r.hget("hash", "foo2")
100
+ end
106
101
 
107
- assert "s1" == r.hget("foo", "f1")
108
- assert "s2" == r.hget("foo", "f2")
109
- end
102
+ def test_hmset_with_invalid_arguments
103
+ assert_raise(Redis::CommandError) do
104
+ r.hmset("hash", "foo1", "bar1", "foo2", "bar2", "foo3")
105
+ end
106
+ end
110
107
 
111
- test "HMGET" do |r|
112
- r.hset("foo", "f1", "s1")
113
- r.hset("foo", "f2", "s2")
114
- r.hset("foo", "f3", "s3")
108
+ def test_mapped_hmset
109
+ r.mapped_hmset("foo", :f1 => "s1", :f2 => "s2")
115
110
 
116
- assert ["s2", "s3"] == r.hmget("foo", "f2", "f3")
117
- end
111
+ assert_equal "s1", r.hget("foo", "f1")
112
+ assert_equal "s2", r.hget("foo", "f2")
113
+ end
118
114
 
119
- test "HMGET mapped" do |r|
120
- r.hset("foo", "f1", "s1")
121
- r.hset("foo", "f2", "s2")
122
- r.hset("foo", "f3", "s3")
115
+ def test_hmget
116
+ r.hset("foo", "f1", "s1")
117
+ r.hset("foo", "f2", "s2")
118
+ r.hset("foo", "f3", "s3")
123
119
 
124
- assert({"f1" => "s1"} == r.mapped_hmget("foo", "f1"))
125
- assert({"f1" => "s1", "f2" => "s2"} == r.mapped_hmget("foo", "f1", "f2"))
126
- end
120
+ assert_equal ["s2", "s3"], r.hmget("foo", "f2", "f3")
121
+ end
122
+
123
+ def test_hmget_mapped
124
+ r.hset("foo", "f1", "s1")
125
+ r.hset("foo", "f2", "s2")
126
+ r.hset("foo", "f3", "s3")
127
+
128
+ assert({"f1" => "s1"} == r.mapped_hmget("foo", "f1"))
129
+ assert({"f1" => "s1", "f2" => "s2"} == r.mapped_hmget("foo", "f1", "f2"))
130
+ end
131
+
132
+ def test_hincrby
133
+ r.hincrby("foo", "f1", 1)
134
+
135
+ assert_equal "1", r.hget("foo", "f1")
127
136
 
128
- test "HINCRBY" do |r|
129
- r.hincrby("foo", "f1", 1)
137
+ r.hincrby("foo", "f1", 2)
130
138
 
131
- assert "1" == r.hget("foo", "f1")
139
+ assert_equal "3", r.hget("foo", "f1")
132
140
 
133
- r.hincrby("foo", "f1", 2)
141
+ r.hincrby("foo", "f1", -1)
134
142
 
135
- assert "3" == r.hget("foo", "f1")
143
+ assert_equal "2", r.hget("foo", "f1")
144
+ end
136
145
 
137
- r.hincrby("foo", "f1", -1)
146
+ def test_hincrbyfloat
147
+ return if version < "2.5.4"
138
148
 
139
- assert "2" == r.hget("foo", "f1")
149
+ r.hincrbyfloat("foo", "f1", 1.23)
150
+
151
+ assert_equal "1.23", r.hget("foo", "f1")
152
+
153
+ r.hincrbyfloat("foo", "f1", 0.77)
154
+
155
+ assert_equal "2", r.hget("foo", "f1")
156
+
157
+ r.hincrbyfloat("foo", "f1", -0.1)
158
+
159
+ assert_equal "1.9", r.hget("foo", "f1")
160
+ end
161
+ end
140
162
  end
@@ -1,107 +1,113 @@
1
- test "RPUSH" do |r|
2
- r.rpush "foo", "s1"
3
- r.rpush "foo", "s2"
1
+ module Lint
4
2
 
5
- assert 2 == r.llen("foo")
6
- assert "s2" == r.rpop("foo")
7
- end
3
+ module Lists
8
4
 
9
- test "Variadic RPUSH" do |r|
10
- next if version(r) < 203090 # 2.4-rc6
5
+ def test_rpush
6
+ r.rpush "foo", "s1"
7
+ r.rpush "foo", "s2"
11
8
 
12
- assert 3 == r.rpush("foo", ["s1", "s2", "s3"])
13
- assert 3 == r.llen("foo")
14
- assert "s3" == r.rpop("foo")
15
- end
9
+ assert_equal 2, r.llen("foo")
10
+ assert_equal "s2", r.rpop("foo")
11
+ end
16
12
 
17
- test "LPUSH" do |r|
18
- r.lpush "foo", "s1"
19
- r.lpush "foo", "s2"
13
+ def test_variadic_rpush
14
+ return if version < "2.3.9" # 2.4-rc6
20
15
 
21
- assert 2 == r.llen("foo")
22
- assert "s2" == r.lpop("foo")
23
- end
16
+ assert_equal 3, r.rpush("foo", ["s1", "s2", "s3"])
17
+ assert_equal 3, r.llen("foo")
18
+ assert_equal "s3", r.rpop("foo")
19
+ end
24
20
 
25
- test "Variadic LPUSH" do |r|
26
- next if version(r) < 203090 # 2.4-rc6
21
+ def test_lpush
22
+ r.lpush "foo", "s1"
23
+ r.lpush "foo", "s2"
27
24
 
28
- assert 3 == r.lpush("foo", ["s1", "s2", "s3"])
29
- assert 3 == r.llen("foo")
30
- assert "s3" == r.lpop("foo")
31
- end
25
+ assert_equal 2, r.llen("foo")
26
+ assert_equal "s2", r.lpop("foo")
27
+ end
32
28
 
33
- test "LLEN" do |r|
34
- r.rpush "foo", "s1"
35
- r.rpush "foo", "s2"
29
+ def test_variadic_lpush
30
+ return if version < "2.3.9" # 2.4-rc6
36
31
 
37
- assert 2 == r.llen("foo")
38
- end
32
+ assert_equal 3, r.lpush("foo", ["s1", "s2", "s3"])
33
+ assert_equal 3, r.llen("foo")
34
+ assert_equal "s3", r.lpop("foo")
35
+ end
39
36
 
40
- test "LRANGE" do |r|
41
- r.rpush "foo", "s1"
42
- r.rpush "foo", "s2"
43
- r.rpush "foo", "s3"
37
+ def test_llen
38
+ r.rpush "foo", "s1"
39
+ r.rpush "foo", "s2"
44
40
 
45
- assert ["s2", "s3"] == r.lrange("foo", 1, -1)
46
- assert ["s1", "s2"] == r.lrange("foo", 0, 1)
41
+ assert_equal 2, r.llen("foo")
42
+ end
47
43
 
48
- assert [] == r.lrange("bar", 0, -1)
49
- end
44
+ def test_lrange
45
+ r.rpush "foo", "s1"
46
+ r.rpush "foo", "s2"
47
+ r.rpush "foo", "s3"
50
48
 
51
- test "LTRIM" do |r|
52
- r.rpush "foo", "s1"
53
- r.rpush "foo", "s2"
54
- r.rpush "foo", "s3"
49
+ assert_equal ["s2", "s3"], r.lrange("foo", 1, -1)
50
+ assert_equal ["s1", "s2"], r.lrange("foo", 0, 1)
55
51
 
56
- r.ltrim "foo", 0, 1
52
+ assert_equal [], r.lrange("bar", 0, -1)
53
+ end
57
54
 
58
- assert 2 == r.llen("foo")
59
- assert ["s1", "s2"] == r.lrange("foo", 0, -1)
60
- end
55
+ def test_ltrim
56
+ r.rpush "foo", "s1"
57
+ r.rpush "foo", "s2"
58
+ r.rpush "foo", "s3"
61
59
 
62
- test "LINDEX" do |r|
63
- r.rpush "foo", "s1"
64
- r.rpush "foo", "s2"
60
+ r.ltrim "foo", 0, 1
65
61
 
66
- assert "s1" == r.lindex("foo", 0)
67
- assert "s2" == r.lindex("foo", 1)
68
- end
62
+ assert_equal 2, r.llen("foo")
63
+ assert_equal ["s1", "s2"], r.lrange("foo", 0, -1)
64
+ end
69
65
 
70
- test "LSET" do |r|
71
- r.rpush "foo", "s1"
72
- r.rpush "foo", "s2"
66
+ def test_lindex
67
+ r.rpush "foo", "s1"
68
+ r.rpush "foo", "s2"
73
69
 
74
- assert "s2" == r.lindex("foo", 1)
75
- assert r.lset("foo", 1, "s3")
76
- assert "s3" == r.lindex("foo", 1)
70
+ assert_equal "s1", r.lindex("foo", 0)
71
+ assert_equal "s2", r.lindex("foo", 1)
72
+ end
77
73
 
78
- assert_raise Redis::CommandError do
79
- r.lset("foo", 4, "s3")
80
- end
81
- end
74
+ def test_lset
75
+ r.rpush "foo", "s1"
76
+ r.rpush "foo", "s2"
82
77
 
83
- test "LREM" do |r|
84
- r.rpush "foo", "s1"
85
- r.rpush "foo", "s2"
78
+ assert_equal "s2", r.lindex("foo", 1)
79
+ assert r.lset("foo", 1, "s3")
80
+ assert_equal "s3", r.lindex("foo", 1)
86
81
 
87
- assert 1 == r.lrem("foo", 1, "s1")
88
- assert ["s2"] == r.lrange("foo", 0, -1)
89
- end
82
+ assert_raise Redis::CommandError do
83
+ r.lset("foo", 4, "s3")
84
+ end
85
+ end
90
86
 
91
- test "LPOP" do |r|
92
- r.rpush "foo", "s1"
93
- r.rpush "foo", "s2"
87
+ def test_lrem
88
+ r.rpush "foo", "s1"
89
+ r.rpush "foo", "s2"
94
90
 
95
- assert 2 == r.llen("foo")
96
- assert "s1" == r.lpop("foo")
97
- assert 1 == r.llen("foo")
98
- end
91
+ assert_equal 1, r.lrem("foo", 1, "s1")
92
+ assert_equal ["s2"], r.lrange("foo", 0, -1)
93
+ end
99
94
 
100
- test "RPOP" do |r|
101
- r.rpush "foo", "s1"
102
- r.rpush "foo", "s2"
95
+ def test_lpop
96
+ r.rpush "foo", "s1"
97
+ r.rpush "foo", "s2"
103
98
 
104
- assert 2 == r.llen("foo")
105
- assert "s2" == r.rpop("foo")
106
- assert 1 == r.llen("foo")
99
+ assert_equal 2, r.llen("foo")
100
+ assert_equal "s1", r.lpop("foo")
101
+ assert_equal 1, r.llen("foo")
102
+ end
103
+
104
+ def test_rpop
105
+ r.rpush "foo", "s1"
106
+ r.rpush "foo", "s2"
107
+
108
+ assert_equal 2, r.llen("foo")
109
+ assert_equal "s2", r.rpop("foo")
110
+ assert_equal 1, r.llen("foo")
111
+ end
112
+ end
107
113
  end