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
@@ -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
|
data/test/lint/hashes.rb
CHANGED
@@ -1,140 +1,162 @@
|
|
1
|
-
|
2
|
-
r.hset("foo", "f1", "s1")
|
1
|
+
module Lint
|
3
2
|
|
4
|
-
|
5
|
-
end
|
3
|
+
module Hashes
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
r.hsetnx("foo", "f1", "s2")
|
5
|
+
def test_hset_and_hget
|
6
|
+
r.hset("foo", "f1", "s1")
|
10
7
|
|
11
|
-
|
8
|
+
assert_equal "s1", r.hget("foo", "f1")
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
def test_hsetnx
|
12
|
+
r.hset("foo", "f1", "s1")
|
13
|
+
r.hsetnx("foo", "f1", "s2")
|
15
14
|
|
16
|
-
|
17
|
-
end
|
15
|
+
assert_equal "s1", r.hget("foo", "f1")
|
18
16
|
|
19
|
-
|
20
|
-
|
17
|
+
r.del("foo")
|
18
|
+
r.hsetnx("foo", "f1", "s2")
|
21
19
|
|
22
|
-
|
20
|
+
assert_equal "s2", r.hget("foo", "f1")
|
21
|
+
end
|
23
22
|
|
24
|
-
|
23
|
+
def test_hdel
|
24
|
+
r.hset("foo", "f1", "s1")
|
25
25
|
|
26
|
-
|
27
|
-
end
|
26
|
+
assert_equal "s1", r.hget("foo", "f1")
|
28
27
|
|
29
|
-
|
30
|
-
next if version(r) < 203090
|
28
|
+
assert_equal 1, r.hdel("foo", "f1")
|
31
29
|
|
32
|
-
|
33
|
-
|
30
|
+
assert_equal nil, r.hget("foo", "f1")
|
31
|
+
end
|
34
32
|
|
35
|
-
|
36
|
-
|
33
|
+
def test_variadic_hdel
|
34
|
+
return if version < "2.3.9"
|
37
35
|
|
38
|
-
|
36
|
+
r.hset("foo", "f1", "s1")
|
37
|
+
r.hset("foo", "f2", "s2")
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
39
|
+
assert_equal "s1", r.hget("foo", "f1")
|
40
|
+
assert_equal "s2", r.hget("foo", "f2")
|
43
41
|
|
44
|
-
|
45
|
-
assert false == r.hexists("foo", "f1")
|
42
|
+
assert_equal 2, r.hdel("foo", ["f1", "f2"])
|
46
43
|
|
47
|
-
|
44
|
+
assert_equal nil, r.hget("foo", "f1")
|
45
|
+
assert_equal nil, r.hget("foo", "f2")
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
48
|
+
def test_hexists
|
49
|
+
assert_equal false, r.hexists("foo", "f1")
|
51
50
|
|
52
|
-
|
53
|
-
assert 0 == r.hlen("foo")
|
51
|
+
r.hset("foo", "f1", "s1")
|
54
52
|
|
55
|
-
|
53
|
+
assert r.hexists("foo", "f1")
|
54
|
+
end
|
56
55
|
|
57
|
-
|
56
|
+
def test_hlen
|
57
|
+
assert_equal 0, r.hlen("foo")
|
58
58
|
|
59
|
-
|
59
|
+
r.hset("foo", "f1", "s1")
|
60
60
|
|
61
|
-
|
62
|
-
end
|
61
|
+
assert_equal 1, r.hlen("foo")
|
63
62
|
|
64
|
-
|
65
|
-
assert [] == r.hkeys("foo")
|
63
|
+
r.hset("foo", "f2", "s2")
|
66
64
|
|
67
|
-
|
68
|
-
|
65
|
+
assert_equal 2, r.hlen("foo")
|
66
|
+
end
|
69
67
|
|
70
|
-
|
71
|
-
|
68
|
+
def test_hkeys
|
69
|
+
assert_equal [], r.hkeys("foo")
|
72
70
|
|
73
|
-
|
74
|
-
|
71
|
+
r.hset("foo", "f1", "s1")
|
72
|
+
r.hset("foo", "f2", "s2")
|
75
73
|
|
76
|
-
|
77
|
-
|
74
|
+
assert_equal ["f1", "f2"], r.hkeys("foo")
|
75
|
+
end
|
78
76
|
|
79
|
-
|
80
|
-
|
77
|
+
def test_hvals
|
78
|
+
assert_equal [], r.hvals("foo")
|
81
79
|
|
82
|
-
|
83
|
-
|
80
|
+
r.hset("foo", "f1", "s1")
|
81
|
+
r.hset("foo", "f2", "s2")
|
84
82
|
|
85
|
-
|
86
|
-
|
83
|
+
assert_equal ["s1", "s2"], r.hvals("foo")
|
84
|
+
end
|
87
85
|
|
88
|
-
|
89
|
-
|
86
|
+
def test_hgetall
|
87
|
+
assert({} == r.hgetall("foo"))
|
90
88
|
|
91
|
-
|
92
|
-
|
89
|
+
r.hset("foo", "f1", "s1")
|
90
|
+
r.hset("foo", "f2", "s2")
|
93
91
|
|
94
|
-
|
95
|
-
|
96
|
-
end
|
92
|
+
assert({"f1" => "s1", "f2" => "s2"} == r.hgetall("foo"))
|
93
|
+
end
|
97
94
|
|
98
|
-
|
99
|
-
|
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
|
-
|
105
|
-
|
98
|
+
assert_equal "bar1", r.hget("hash", "foo1")
|
99
|
+
assert_equal "bar2", r.hget("hash", "foo2")
|
100
|
+
end
|
106
101
|
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
112
|
-
|
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
|
-
|
117
|
-
|
111
|
+
assert_equal "s1", r.hget("foo", "f1")
|
112
|
+
assert_equal "s2", r.hget("foo", "f2")
|
113
|
+
end
|
118
114
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
129
|
-
r.hincrby("foo", "f1", 1)
|
137
|
+
r.hincrby("foo", "f1", 2)
|
130
138
|
|
131
|
-
|
139
|
+
assert_equal "3", r.hget("foo", "f1")
|
132
140
|
|
133
|
-
|
141
|
+
r.hincrby("foo", "f1", -1)
|
134
142
|
|
135
|
-
|
143
|
+
assert_equal "2", r.hget("foo", "f1")
|
144
|
+
end
|
136
145
|
|
137
|
-
|
146
|
+
def test_hincrbyfloat
|
147
|
+
return if version < "2.5.4"
|
138
148
|
|
139
|
-
|
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
|
data/test/lint/lists.rb
CHANGED
@@ -1,107 +1,113 @@
|
|
1
|
-
|
2
|
-
r.rpush "foo", "s1"
|
3
|
-
r.rpush "foo", "s2"
|
1
|
+
module Lint
|
4
2
|
|
5
|
-
|
6
|
-
assert "s2" == r.rpop("foo")
|
7
|
-
end
|
3
|
+
module Lists
|
8
4
|
|
9
|
-
|
10
|
-
|
5
|
+
def test_rpush
|
6
|
+
r.rpush "foo", "s1"
|
7
|
+
r.rpush "foo", "s2"
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
9
|
+
assert_equal 2, r.llen("foo")
|
10
|
+
assert_equal "s2", r.rpop("foo")
|
11
|
+
end
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
r.lpush "foo", "s2"
|
13
|
+
def test_variadic_rpush
|
14
|
+
return if version < "2.3.9" # 2.4-rc6
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
21
|
+
def test_lpush
|
22
|
+
r.lpush "foo", "s1"
|
23
|
+
r.lpush "foo", "s2"
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
25
|
+
assert_equal 2, r.llen("foo")
|
26
|
+
assert_equal "s2", r.lpop("foo")
|
27
|
+
end
|
32
28
|
|
33
|
-
|
34
|
-
|
35
|
-
r.rpush "foo", "s2"
|
29
|
+
def test_variadic_lpush
|
30
|
+
return if version < "2.3.9" # 2.4-rc6
|
36
31
|
|
37
|
-
|
38
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
r.rpush "foo", "s3"
|
37
|
+
def test_llen
|
38
|
+
r.rpush "foo", "s1"
|
39
|
+
r.rpush "foo", "s2"
|
44
40
|
|
45
|
-
|
46
|
-
|
41
|
+
assert_equal 2, r.llen("foo")
|
42
|
+
end
|
47
43
|
|
48
|
-
|
49
|
-
|
44
|
+
def test_lrange
|
45
|
+
r.rpush "foo", "s1"
|
46
|
+
r.rpush "foo", "s2"
|
47
|
+
r.rpush "foo", "s3"
|
50
48
|
|
51
|
-
|
52
|
-
|
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
|
-
|
52
|
+
assert_equal [], r.lrange("bar", 0, -1)
|
53
|
+
end
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
def test_ltrim
|
56
|
+
r.rpush "foo", "s1"
|
57
|
+
r.rpush "foo", "s2"
|
58
|
+
r.rpush "foo", "s3"
|
61
59
|
|
62
|
-
|
63
|
-
r.rpush "foo", "s1"
|
64
|
-
r.rpush "foo", "s2"
|
60
|
+
r.ltrim "foo", 0, 1
|
65
61
|
|
66
|
-
|
67
|
-
|
68
|
-
end
|
62
|
+
assert_equal 2, r.llen("foo")
|
63
|
+
assert_equal ["s1", "s2"], r.lrange("foo", 0, -1)
|
64
|
+
end
|
69
65
|
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
def test_lindex
|
67
|
+
r.rpush "foo", "s1"
|
68
|
+
r.rpush "foo", "s2"
|
73
69
|
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
assert_equal "s1", r.lindex("foo", 0)
|
71
|
+
assert_equal "s2", r.lindex("foo", 1)
|
72
|
+
end
|
77
73
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
74
|
+
def test_lset
|
75
|
+
r.rpush "foo", "s1"
|
76
|
+
r.rpush "foo", "s2"
|
82
77
|
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
88
|
-
|
89
|
-
end
|
82
|
+
assert_raise Redis::CommandError do
|
83
|
+
r.lset("foo", 4, "s3")
|
84
|
+
end
|
85
|
+
end
|
90
86
|
|
91
|
-
|
92
|
-
|
93
|
-
|
87
|
+
def test_lrem
|
88
|
+
r.rpush "foo", "s1"
|
89
|
+
r.rpush "foo", "s2"
|
94
90
|
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
101
|
-
|
102
|
-
|
95
|
+
def test_lpop
|
96
|
+
r.rpush "foo", "s1"
|
97
|
+
r.rpush "foo", "s2"
|
103
98
|
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|