redis 3.0.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +315 -0
- data/README.md +301 -58
- data/lib/redis/client.rb +383 -88
- data/lib/redis/cluster/command.rb +81 -0
- data/lib/redis/cluster/command_loader.rb +33 -0
- data/lib/redis/cluster/key_slot_converter.rb +72 -0
- data/lib/redis/cluster/node.rb +108 -0
- data/lib/redis/cluster/node_key.rb +31 -0
- data/lib/redis/cluster/node_loader.rb +37 -0
- data/lib/redis/cluster/option.rb +93 -0
- data/lib/redis/cluster/slot.rb +86 -0
- data/lib/redis/cluster/slot_loader.rb +49 -0
- data/lib/redis/cluster.rb +291 -0
- data/lib/redis/connection/command_helper.rb +7 -10
- data/lib/redis/connection/hiredis.rb +12 -8
- data/lib/redis/connection/registry.rb +2 -1
- data/lib/redis/connection/ruby.rb +266 -74
- data/lib/redis/connection/synchrony.rb +41 -14
- data/lib/redis/connection.rb +4 -2
- data/lib/redis/distributed.rb +258 -76
- data/lib/redis/errors.rb +48 -0
- data/lib/redis/hash_ring.rb +31 -73
- data/lib/redis/pipeline.rb +74 -18
- data/lib/redis/subscribe.rb +24 -13
- data/lib/redis/version.rb +3 -1
- data/lib/redis.rb +2068 -464
- metadata +63 -160
- data/.gitignore +0 -10
- data/.order +0 -169
- data/.travis/Gemfile +0 -11
- data/.travis.yml +0 -50
- data/.yardopts +0 -3
- data/Rakefile +0 -392
- data/benchmarking/logging.rb +0 -62
- data/benchmarking/pipeline.rb +0 -51
- data/benchmarking/speed.rb +0 -21
- data/benchmarking/suite.rb +0 -24
- data/benchmarking/worker.rb +0 -71
- data/examples/basic.rb +0 -15
- data/examples/dist_redis.rb +0 -43
- data/examples/incr-decr.rb +0 -17
- data/examples/list.rb +0 -26
- data/examples/pubsub.rb +0 -31
- data/examples/sets.rb +0 -36
- data/examples/unicorn/config.ru +0 -3
- data/examples/unicorn/unicorn.rb +0 -20
- data/redis.gemspec +0 -41
- data/test/blocking_commands_test.rb +0 -42
- data/test/command_map_test.rb +0 -30
- data/test/commands_on_hashes_test.rb +0 -21
- data/test/commands_on_lists_test.rb +0 -20
- data/test/commands_on_sets_test.rb +0 -77
- data/test/commands_on_sorted_sets_test.rb +0 -109
- data/test/commands_on_strings_test.rb +0 -83
- data/test/commands_on_value_types_test.rb +0 -99
- data/test/connection_handling_test.rb +0 -189
- data/test/db/.gitignore +0 -1
- data/test/distributed_blocking_commands_test.rb +0 -46
- data/test/distributed_commands_on_hashes_test.rb +0 -10
- data/test/distributed_commands_on_lists_test.rb +0 -22
- data/test/distributed_commands_on_sets_test.rb +0 -83
- data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
- data/test/distributed_commands_on_strings_test.rb +0 -48
- data/test/distributed_commands_on_value_types_test.rb +0 -87
- data/test/distributed_commands_requiring_clustering_test.rb +0 -148
- data/test/distributed_connection_handling_test.rb +0 -23
- data/test/distributed_internals_test.rb +0 -15
- data/test/distributed_key_tags_test.rb +0 -52
- data/test/distributed_persistence_control_commands_test.rb +0 -26
- data/test/distributed_publish_subscribe_test.rb +0 -92
- data/test/distributed_remote_server_control_commands_test.rb +0 -53
- data/test/distributed_scripting_test.rb +0 -102
- data/test/distributed_sorting_test.rb +0 -20
- data/test/distributed_test.rb +0 -58
- data/test/distributed_transactions_test.rb +0 -32
- data/test/encoding_test.rb +0 -18
- data/test/error_replies_test.rb +0 -59
- data/test/helper.rb +0 -188
- data/test/helper_test.rb +0 -22
- data/test/internals_test.rb +0 -214
- data/test/lint/blocking_commands.rb +0 -124
- data/test/lint/hashes.rb +0 -162
- data/test/lint/lists.rb +0 -143
- data/test/lint/sets.rb +0 -96
- data/test/lint/sorted_sets.rb +0 -201
- data/test/lint/strings.rb +0 -157
- data/test/lint/value_types.rb +0 -106
- data/test/persistence_control_commands_test.rb +0 -26
- data/test/pipelining_commands_test.rb +0 -195
- data/test/publish_subscribe_test.rb +0 -153
- data/test/remote_server_control_commands_test.rb +0 -104
- data/test/scripting_test.rb +0 -78
- data/test/sorting_test.rb +0 -45
- data/test/support/connection/hiredis.rb +0 -1
- data/test/support/connection/ruby.rb +0 -1
- data/test/support/connection/synchrony.rb +0 -17
- data/test/support/redis_mock.rb +0 -92
- data/test/support/wire/synchrony.rb +0 -24
- data/test/support/wire/thread.rb +0 -5
- data/test/synchrony_driver.rb +0 -57
- data/test/test.conf +0 -9
- data/test/thread_safety_test.rb +0 -32
- data/test/transactions_test.rb +0 -244
- data/test/unknown_commands_test.rb +0 -14
- data/test/url_param_test.rb +0 -64
data/test/helper_test.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "helper"
|
4
|
-
|
5
|
-
class TestHelper < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Helper
|
8
|
-
|
9
|
-
def test_version_comparison
|
10
|
-
v = Version.new("2.0.0")
|
11
|
-
|
12
|
-
assert v < "3"
|
13
|
-
assert v > "1"
|
14
|
-
assert v > "2"
|
15
|
-
|
16
|
-
assert v < "2.1"
|
17
|
-
assert v < "2.0.1"
|
18
|
-
assert v < "2.0.0.1"
|
19
|
-
|
20
|
-
assert v == "2.0.0"
|
21
|
-
end
|
22
|
-
end
|
data/test/internals_test.rb
DELETED
@@ -1,214 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "helper"
|
4
|
-
|
5
|
-
class TestInternals < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Helper::Client
|
8
|
-
|
9
|
-
def test_logger
|
10
|
-
r.ping
|
11
|
-
|
12
|
-
assert log.string =~ /Redis >> PING/
|
13
|
-
assert log.string =~ /Redis >> \d+\.\d+ms/
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_logger_with_pipelining
|
17
|
-
r.pipelined do
|
18
|
-
r.set "foo", "bar"
|
19
|
-
r.get "foo"
|
20
|
-
end
|
21
|
-
|
22
|
-
assert log.string["SET foo bar"]
|
23
|
-
assert log.string["GET foo"]
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_recovers_from_failed_commands
|
27
|
-
# See https://github.com/redis/redis-rb/issues#issue/28
|
28
|
-
|
29
|
-
assert_raise(Redis::CommandError) do
|
30
|
-
r.command_that_doesnt_exist
|
31
|
-
end
|
32
|
-
|
33
|
-
assert_nothing_raised do
|
34
|
-
r.info
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_raises_on_protocol_errors
|
39
|
-
redis_mock(:ping => lambda { |*_| "foo" }) do |redis|
|
40
|
-
assert_raise(Redis::ProtocolError) do
|
41
|
-
redis.ping
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_provides_a_meaningful_inspect
|
47
|
-
assert_equal "#<Redis client v#{Redis::VERSION} for redis://127.0.0.1:#{PORT}/15>", r.inspect
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_redis_current
|
51
|
-
assert_equal "127.0.0.1", Redis.current.client.host
|
52
|
-
assert_equal 6379, Redis.current.client.port
|
53
|
-
assert_equal 0, Redis.current.client.db
|
54
|
-
|
55
|
-
Redis.current = Redis.new(OPTIONS.merge(:port => 6380, :db => 1))
|
56
|
-
|
57
|
-
t = Thread.new do
|
58
|
-
assert_equal "127.0.0.1", Redis.current.client.host
|
59
|
-
assert_equal 6380, Redis.current.client.port
|
60
|
-
assert_equal 1, Redis.current.client.db
|
61
|
-
end
|
62
|
-
|
63
|
-
t.join
|
64
|
-
|
65
|
-
assert_equal "127.0.0.1", Redis.current.client.host
|
66
|
-
assert_equal 6380, Redis.current.client.port
|
67
|
-
assert_equal 1, Redis.current.client.db
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_default_id_with_host_and_port
|
71
|
-
redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0))
|
72
|
-
assert_equal "redis://host:1234/0", redis.client.id
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_default_id_with_host_and_port_and_explicit_scheme
|
76
|
-
redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0, :scheme => "foo"))
|
77
|
-
assert_equal "redis://host:1234/0", redis.client.id
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_default_id_with_path
|
81
|
-
redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0))
|
82
|
-
assert_equal "redis:///tmp/redis.sock/0", redis.client.id
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_default_id_with_path_and_explicit_scheme
|
86
|
-
redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0, :scheme => "foo"))
|
87
|
-
assert_equal "redis:///tmp/redis.sock/0", redis.client.id
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_override_id
|
91
|
-
redis = Redis.new(OPTIONS.merge(:id => "test"))
|
92
|
-
assert_equal redis.client.id, "test"
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_timeout
|
96
|
-
assert_nothing_raised do
|
97
|
-
Redis.new(OPTIONS.merge(:timeout => 0))
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_time
|
102
|
-
return if version < "2.5.4"
|
103
|
-
|
104
|
-
# Test that the difference between the time that Ruby reports and the time
|
105
|
-
# that Redis reports is minimal (prevents the test from being racy).
|
106
|
-
rv = r.time
|
107
|
-
|
108
|
-
redis_usec = rv[0] * 1_000_000 + rv[1]
|
109
|
-
ruby_usec = Integer(Time.now.to_f * 1_000_000)
|
110
|
-
|
111
|
-
assert 500_000 > (ruby_usec - redis_usec).abs
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_connection_timeout
|
115
|
-
assert_raise Redis::CannotConnectError do
|
116
|
-
Redis.new(OPTIONS.merge(:host => "10.255.255.254", :timeout => 0.1)).ping
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def close_on_ping(seq)
|
121
|
-
$request = 0
|
122
|
-
|
123
|
-
command = lambda do
|
124
|
-
idx = $request
|
125
|
-
$request += 1
|
126
|
-
|
127
|
-
rv = "+%d" % idx
|
128
|
-
rv = nil if seq.include?(idx)
|
129
|
-
rv
|
130
|
-
end
|
131
|
-
|
132
|
-
redis_mock(:ping => command, :timeout => 0.1) do |redis|
|
133
|
-
yield(redis)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_retry_by_default
|
138
|
-
close_on_ping([0]) do |redis|
|
139
|
-
assert_equal "1", redis.ping
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_retry_when_wrapped_in_with_reconnect_true
|
144
|
-
close_on_ping([0]) do |redis|
|
145
|
-
redis.with_reconnect(true) do
|
146
|
-
assert_equal "1", redis.ping
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_dont_retry_when_wrapped_in_with_reconnect_false
|
152
|
-
close_on_ping([0]) do |redis|
|
153
|
-
assert_raise Redis::ConnectionError do
|
154
|
-
redis.with_reconnect(false) do
|
155
|
-
redis.ping
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_dont_retry_when_wrapped_in_without_reconnect
|
162
|
-
close_on_ping([0]) do |redis|
|
163
|
-
assert_raise Redis::ConnectionError do
|
164
|
-
redis.without_reconnect do
|
165
|
-
redis.ping
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_retry_only_once_when_read_raises_econnreset
|
172
|
-
close_on_ping([0, 1]) do |redis|
|
173
|
-
assert_raise Redis::ConnectionError do
|
174
|
-
redis.ping
|
175
|
-
end
|
176
|
-
|
177
|
-
assert !redis.client.connected?
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_don_t_retry_when_second_read_in_pipeline_raises_econnreset
|
182
|
-
close_on_ping([1]) do |redis|
|
183
|
-
assert_raise Redis::ConnectionError do
|
184
|
-
redis.pipelined do
|
185
|
-
redis.ping
|
186
|
-
redis.ping # Second #read times out
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
assert !redis.client.connected?
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_connecting_to_unix_domain_socket
|
195
|
-
assert_nothing_raised do
|
196
|
-
Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock")).ping
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
driver(:ruby, :hiredis) do
|
201
|
-
def test_bubble_timeout_without_retrying
|
202
|
-
serv = TCPServer.new(6380)
|
203
|
-
|
204
|
-
redis = Redis.new(:port => 6380, :timeout => 0.1)
|
205
|
-
|
206
|
-
assert_raise(Redis::TimeoutError) do
|
207
|
-
redis.ping
|
208
|
-
end
|
209
|
-
|
210
|
-
ensure
|
211
|
-
serv.close if serv
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
@@ -1,124 +0,0 @@
|
|
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
DELETED
@@ -1,162 +0,0 @@
|
|
1
|
-
module Lint
|
2
|
-
|
3
|
-
module Hashes
|
4
|
-
|
5
|
-
def test_hset_and_hget
|
6
|
-
r.hset("foo", "f1", "s1")
|
7
|
-
|
8
|
-
assert_equal "s1", r.hget("foo", "f1")
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_hsetnx
|
12
|
-
r.hset("foo", "f1", "s1")
|
13
|
-
r.hsetnx("foo", "f1", "s2")
|
14
|
-
|
15
|
-
assert_equal "s1", r.hget("foo", "f1")
|
16
|
-
|
17
|
-
r.del("foo")
|
18
|
-
r.hsetnx("foo", "f1", "s2")
|
19
|
-
|
20
|
-
assert_equal "s2", r.hget("foo", "f1")
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_hdel
|
24
|
-
r.hset("foo", "f1", "s1")
|
25
|
-
|
26
|
-
assert_equal "s1", r.hget("foo", "f1")
|
27
|
-
|
28
|
-
assert_equal 1, r.hdel("foo", "f1")
|
29
|
-
|
30
|
-
assert_equal nil, r.hget("foo", "f1")
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_variadic_hdel
|
34
|
-
return if version < "2.3.9"
|
35
|
-
|
36
|
-
r.hset("foo", "f1", "s1")
|
37
|
-
r.hset("foo", "f2", "s2")
|
38
|
-
|
39
|
-
assert_equal "s1", r.hget("foo", "f1")
|
40
|
-
assert_equal "s2", r.hget("foo", "f2")
|
41
|
-
|
42
|
-
assert_equal 2, r.hdel("foo", ["f1", "f2"])
|
43
|
-
|
44
|
-
assert_equal nil, r.hget("foo", "f1")
|
45
|
-
assert_equal nil, r.hget("foo", "f2")
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_hexists
|
49
|
-
assert_equal false, r.hexists("foo", "f1")
|
50
|
-
|
51
|
-
r.hset("foo", "f1", "s1")
|
52
|
-
|
53
|
-
assert r.hexists("foo", "f1")
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_hlen
|
57
|
-
assert_equal 0, r.hlen("foo")
|
58
|
-
|
59
|
-
r.hset("foo", "f1", "s1")
|
60
|
-
|
61
|
-
assert_equal 1, r.hlen("foo")
|
62
|
-
|
63
|
-
r.hset("foo", "f2", "s2")
|
64
|
-
|
65
|
-
assert_equal 2, r.hlen("foo")
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_hkeys
|
69
|
-
assert_equal [], r.hkeys("foo")
|
70
|
-
|
71
|
-
r.hset("foo", "f1", "s1")
|
72
|
-
r.hset("foo", "f2", "s2")
|
73
|
-
|
74
|
-
assert_equal ["f1", "f2"], r.hkeys("foo")
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_hvals
|
78
|
-
assert_equal [], r.hvals("foo")
|
79
|
-
|
80
|
-
r.hset("foo", "f1", "s1")
|
81
|
-
r.hset("foo", "f2", "s2")
|
82
|
-
|
83
|
-
assert_equal ["s1", "s2"], r.hvals("foo")
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_hgetall
|
87
|
-
assert({} == r.hgetall("foo"))
|
88
|
-
|
89
|
-
r.hset("foo", "f1", "s1")
|
90
|
-
r.hset("foo", "f2", "s2")
|
91
|
-
|
92
|
-
assert({"f1" => "s1", "f2" => "s2"} == r.hgetall("foo"))
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_hmset
|
96
|
-
r.hmset("hash", "foo1", "bar1", "foo2", "bar2")
|
97
|
-
|
98
|
-
assert_equal "bar1", r.hget("hash", "foo1")
|
99
|
-
assert_equal "bar2", r.hget("hash", "foo2")
|
100
|
-
end
|
101
|
-
|
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
|
107
|
-
|
108
|
-
def test_mapped_hmset
|
109
|
-
r.mapped_hmset("foo", :f1 => "s1", :f2 => "s2")
|
110
|
-
|
111
|
-
assert_equal "s1", r.hget("foo", "f1")
|
112
|
-
assert_equal "s2", r.hget("foo", "f2")
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_hmget
|
116
|
-
r.hset("foo", "f1", "s1")
|
117
|
-
r.hset("foo", "f2", "s2")
|
118
|
-
r.hset("foo", "f3", "s3")
|
119
|
-
|
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")
|
136
|
-
|
137
|
-
r.hincrby("foo", "f1", 2)
|
138
|
-
|
139
|
-
assert_equal "3", r.hget("foo", "f1")
|
140
|
-
|
141
|
-
r.hincrby("foo", "f1", -1)
|
142
|
-
|
143
|
-
assert_equal "2", r.hget("foo", "f1")
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_hincrbyfloat
|
147
|
-
return if version < "2.5.4"
|
148
|
-
|
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
|
162
|
-
end
|
data/test/lint/lists.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
module Lint
|
2
|
-
|
3
|
-
module Lists
|
4
|
-
|
5
|
-
def test_lpush
|
6
|
-
r.lpush "foo", "s1"
|
7
|
-
r.lpush "foo", "s2"
|
8
|
-
|
9
|
-
assert_equal 2, r.llen("foo")
|
10
|
-
assert_equal "s2", r.lpop("foo")
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_variadic_lpush
|
14
|
-
return if version < "2.3.9" # 2.4-rc6
|
15
|
-
|
16
|
-
assert_equal 3, r.lpush("foo", ["s1", "s2", "s3"])
|
17
|
-
assert_equal 3, r.llen("foo")
|
18
|
-
assert_equal "s3", r.lpop("foo")
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_lpushx
|
22
|
-
r.lpushx "foo", "s1"
|
23
|
-
r.lpush "foo", "s2"
|
24
|
-
r.lpushx "foo", "s3"
|
25
|
-
|
26
|
-
assert_equal 2, r.llen("foo")
|
27
|
-
assert_equal ["s3", "s2"], r.lrange("foo", 0, -1)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_rpush
|
31
|
-
r.rpush "foo", "s1"
|
32
|
-
r.rpush "foo", "s2"
|
33
|
-
|
34
|
-
assert_equal 2, r.llen("foo")
|
35
|
-
assert_equal "s2", r.rpop("foo")
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_variadic_rpush
|
39
|
-
return if version < "2.3.9" # 2.4-rc6
|
40
|
-
|
41
|
-
assert_equal 3, r.rpush("foo", ["s1", "s2", "s3"])
|
42
|
-
assert_equal 3, r.llen("foo")
|
43
|
-
assert_equal "s3", r.rpop("foo")
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_rpushx
|
47
|
-
r.rpushx "foo", "s1"
|
48
|
-
r.rpush "foo", "s2"
|
49
|
-
r.rpushx "foo", "s3"
|
50
|
-
|
51
|
-
assert_equal 2, r.llen("foo")
|
52
|
-
assert_equal ["s2", "s3"], r.lrange("foo", 0, -1)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_llen
|
56
|
-
r.rpush "foo", "s1"
|
57
|
-
r.rpush "foo", "s2"
|
58
|
-
|
59
|
-
assert_equal 2, r.llen("foo")
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_lrange
|
63
|
-
r.rpush "foo", "s1"
|
64
|
-
r.rpush "foo", "s2"
|
65
|
-
r.rpush "foo", "s3"
|
66
|
-
|
67
|
-
assert_equal ["s2", "s3"], r.lrange("foo", 1, -1)
|
68
|
-
assert_equal ["s1", "s2"], r.lrange("foo", 0, 1)
|
69
|
-
|
70
|
-
assert_equal [], r.lrange("bar", 0, -1)
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_ltrim
|
74
|
-
r.rpush "foo", "s1"
|
75
|
-
r.rpush "foo", "s2"
|
76
|
-
r.rpush "foo", "s3"
|
77
|
-
|
78
|
-
r.ltrim "foo", 0, 1
|
79
|
-
|
80
|
-
assert_equal 2, r.llen("foo")
|
81
|
-
assert_equal ["s1", "s2"], r.lrange("foo", 0, -1)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_lindex
|
85
|
-
r.rpush "foo", "s1"
|
86
|
-
r.rpush "foo", "s2"
|
87
|
-
|
88
|
-
assert_equal "s1", r.lindex("foo", 0)
|
89
|
-
assert_equal "s2", r.lindex("foo", 1)
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_lset
|
93
|
-
r.rpush "foo", "s1"
|
94
|
-
r.rpush "foo", "s2"
|
95
|
-
|
96
|
-
assert_equal "s2", r.lindex("foo", 1)
|
97
|
-
assert r.lset("foo", 1, "s3")
|
98
|
-
assert_equal "s3", r.lindex("foo", 1)
|
99
|
-
|
100
|
-
assert_raise Redis::CommandError do
|
101
|
-
r.lset("foo", 4, "s3")
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_lrem
|
106
|
-
r.rpush "foo", "s1"
|
107
|
-
r.rpush "foo", "s2"
|
108
|
-
|
109
|
-
assert_equal 1, r.lrem("foo", 1, "s1")
|
110
|
-
assert_equal ["s2"], r.lrange("foo", 0, -1)
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_lpop
|
114
|
-
r.rpush "foo", "s1"
|
115
|
-
r.rpush "foo", "s2"
|
116
|
-
|
117
|
-
assert_equal 2, r.llen("foo")
|
118
|
-
assert_equal "s1", r.lpop("foo")
|
119
|
-
assert_equal 1, r.llen("foo")
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_rpop
|
123
|
-
r.rpush "foo", "s1"
|
124
|
-
r.rpush "foo", "s2"
|
125
|
-
|
126
|
-
assert_equal 2, r.llen("foo")
|
127
|
-
assert_equal "s2", r.rpop("foo")
|
128
|
-
assert_equal 1, r.llen("foo")
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_linsert
|
132
|
-
r.rpush "foo", "s1"
|
133
|
-
r.rpush "foo", "s3"
|
134
|
-
r.linsert "foo", :before, "s3", "s2"
|
135
|
-
|
136
|
-
assert_equal ["s1", "s2", "s3"], r.lrange("foo", 0, -1)
|
137
|
-
|
138
|
-
assert_raise(Redis::CommandError) do
|
139
|
-
r.linsert "foo", :anywhere, "s3", "s2"
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|