mock_redis 0.4.1 → 0.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.
- data/CHANGELOG.md +11 -0
- data/Gemfile +1 -1
- data/lib/mock_redis/assertions.rb +2 -2
- data/lib/mock_redis/database.rb +16 -8
- data/lib/mock_redis/expire_wrapper.rb +2 -2
- data/lib/mock_redis/hash_methods.rb +12 -6
- data/lib/mock_redis/list_methods.rb +10 -8
- data/lib/mock_redis/multi_db_wrapper.rb +3 -3
- data/lib/mock_redis/pipelined_wrapper.rb +45 -0
- data/lib/mock_redis/set_methods.rb +14 -5
- data/lib/mock_redis/string_methods.rb +6 -6
- data/lib/mock_redis/transaction_wrapper.rb +13 -8
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset_methods.rb +52 -22
- data/lib/mock_redis.rb +92 -5
- data/mock_redis.gemspec +1 -1
- data/spec/cloning_spec.rb +1 -1
- data/spec/commands/blpop_spec.rb +3 -3
- data/spec/commands/brpop_spec.rb +3 -3
- data/spec/commands/brpoplpush_spec.rb +3 -3
- data/spec/commands/hdel_spec.rb +5 -0
- data/spec/commands/lpush_spec.rb +7 -0
- data/spec/commands/mapped_hmset_spec.rb +7 -1
- data/spec/commands/move_spec.rb +2 -2
- data/spec/commands/msetnx_spec.rb +2 -2
- data/spec/commands/pipelined_spec.rb +12 -0
- data/spec/commands/rename_spec.rb +7 -0
- data/spec/commands/renamenx_spec.rb +7 -0
- data/spec/commands/rpush_spec.rb +7 -0
- data/spec/commands/sadd_spec.rb +1 -1
- data/spec/commands/sdiff_spec.rb +1 -1
- data/spec/commands/sdiffstore_spec.rb +3 -3
- data/spec/commands/sinterstore_spec.rb +2 -2
- data/spec/commands/smembers_spec.rb +4 -4
- data/spec/commands/srem_spec.rb +5 -0
- data/spec/commands/sunion_spec.rb +2 -2
- data/spec/commands/sunionstore_spec.rb +3 -3
- data/spec/commands/watch_spec.rb +2 -2
- data/spec/commands/zadd_spec.rb +6 -1
- data/spec/commands/zcount_spec.rb +8 -0
- data/spec/commands/zincrby_spec.rb +4 -4
- data/spec/commands/zinterstore_spec.rb +7 -7
- data/spec/commands/zrange_spec.rb +6 -2
- data/spec/commands/zrangebyscore_spec.rb +2 -2
- data/spec/commands/zrem_spec.rb +5 -0
- data/spec/commands/zrevrange_spec.rb +2 -2
- data/spec/commands/zrevrangebyscore_spec.rb +2 -2
- data/spec/commands/zscore_spec.rb +2 -2
- data/spec/commands/zunionstore_spec.rb +9 -9
- data/spec/mock_redis_spec.rb +21 -0
- data/spec/support/redis_multiplexer.rb +23 -19
- data/spec/transactions_spec.rb +17 -0
- metadata +67 -84
- data/lib/mock_redis/distributed.rb +0 -6
data/lib/mock_redis.rb
CHANGED
@@ -2,20 +2,59 @@ require 'set'
|
|
2
2
|
|
3
3
|
require 'mock_redis/assertions'
|
4
4
|
require 'mock_redis/database'
|
5
|
-
require 'mock_redis/distributed'
|
6
5
|
require 'mock_redis/expire_wrapper'
|
7
6
|
require 'mock_redis/multi_db_wrapper'
|
7
|
+
require 'mock_redis/pipelined_wrapper'
|
8
8
|
require 'mock_redis/transaction_wrapper'
|
9
9
|
require 'mock_redis/undef_redis_methods'
|
10
10
|
|
11
11
|
class MockRedis
|
12
12
|
include UndefRedisMethods
|
13
13
|
|
14
|
+
attr_reader :options
|
15
|
+
|
16
|
+
DEFAULTS = {
|
17
|
+
:scheme => "redis",
|
18
|
+
:host => "127.0.0.1",
|
19
|
+
:port => 6379,
|
20
|
+
:path => nil,
|
21
|
+
:timeout => 5.0,
|
22
|
+
:password => nil,
|
23
|
+
:db => 0,
|
24
|
+
}
|
25
|
+
|
14
26
|
def initialize(*args)
|
15
|
-
@
|
16
|
-
|
17
|
-
|
18
|
-
|
27
|
+
@options = _parse_options(args.first)
|
28
|
+
|
29
|
+
@db = PipelinedWrapper.new(
|
30
|
+
TransactionWrapper.new(
|
31
|
+
ExpireWrapper.new(
|
32
|
+
MultiDbWrapper.new(
|
33
|
+
Database.new(*args)))))
|
34
|
+
end
|
35
|
+
|
36
|
+
def id
|
37
|
+
"redis://#{self.host}:#{self.port}/#{self.db}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def call(command, &block)
|
41
|
+
self.send(*command)
|
42
|
+
end
|
43
|
+
|
44
|
+
def host
|
45
|
+
self.options[:host]
|
46
|
+
end
|
47
|
+
|
48
|
+
def port
|
49
|
+
self.options[:port]
|
50
|
+
end
|
51
|
+
|
52
|
+
def db
|
53
|
+
self.options[:db]
|
54
|
+
end
|
55
|
+
|
56
|
+
def client
|
57
|
+
self
|
19
58
|
end
|
20
59
|
|
21
60
|
def respond_to?(method, include_private=false)
|
@@ -30,4 +69,52 @@ class MockRedis
|
|
30
69
|
super
|
31
70
|
@db = @db.clone
|
32
71
|
end
|
72
|
+
|
73
|
+
|
74
|
+
protected
|
75
|
+
|
76
|
+
def _parse_options(options)
|
77
|
+
return {} if options.nil?
|
78
|
+
|
79
|
+
defaults = DEFAULTS.dup
|
80
|
+
|
81
|
+
url = options[:url] || ENV["REDIS_URL"]
|
82
|
+
|
83
|
+
# Override defaults from URL if given
|
84
|
+
if url
|
85
|
+
require "uri"
|
86
|
+
|
87
|
+
uri = URI(url)
|
88
|
+
|
89
|
+
if uri.scheme == "unix"
|
90
|
+
defaults[:path] = uri.path
|
91
|
+
else
|
92
|
+
# Require the URL to have at least a host
|
93
|
+
raise ArgumentError, "invalid url" unless uri.host
|
94
|
+
|
95
|
+
defaults[:scheme] = uri.scheme
|
96
|
+
defaults[:host] = uri.host
|
97
|
+
defaults[:port] = uri.port if uri.port
|
98
|
+
defaults[:password] = uri.password if uri.password
|
99
|
+
defaults[:db] = uri.path[1..-1].to_i if uri.path
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
options = defaults.merge(options)
|
104
|
+
|
105
|
+
if options[:path]
|
106
|
+
options[:scheme] = "unix"
|
107
|
+
options.delete(:host)
|
108
|
+
options.delete(:port)
|
109
|
+
else
|
110
|
+
options[:host] = options[:host].to_s
|
111
|
+
options[:port] = options[:port].to_i
|
112
|
+
end
|
113
|
+
|
114
|
+
options[:timeout] = options[:timeout].to_f
|
115
|
+
options[:db] = options[:db].to_i
|
116
|
+
|
117
|
+
options
|
118
|
+
end
|
119
|
+
|
33
120
|
end
|
data/mock_redis.gemspec
CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.add_development_dependency "rake", "~> 0.9.2"
|
22
|
-
s.add_development_dependency "redis", "~>
|
22
|
+
s.add_development_dependency "redis", "~> 3.0.0"
|
23
23
|
s.add_development_dependency "rspec", "~> 2.6.0"
|
24
24
|
end
|
data/spec/cloning_spec.rb
CHANGED
data/spec/commands/blpop_spec.rb
CHANGED
@@ -27,16 +27,16 @@ describe '#blpop(key [, key, ...,], timeout)' do
|
|
27
27
|
[@list1, 'one']
|
28
28
|
end
|
29
29
|
|
30
|
-
it "
|
30
|
+
it "allows subsecond timeouts" do
|
31
31
|
lambda do
|
32
32
|
@redises.blpop(@list1, @list2, 0.5)
|
33
|
-
end.
|
33
|
+
end.should_not raise_error(Redis::CommandError)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "raises an error on negative timeout" do
|
37
37
|
lambda do
|
38
38
|
@redises.blpop(@list1, @list2, -1)
|
39
|
-
end.should raise_error(
|
39
|
+
end.should raise_error(Redis::CommandError)
|
40
40
|
end
|
41
41
|
|
42
42
|
it_should_behave_like "a list-only command"
|
data/spec/commands/brpop_spec.rb
CHANGED
@@ -26,16 +26,16 @@ describe '#brpop(key [, key, ...,], timeout)' do
|
|
26
26
|
[@list1, 'two']
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
29
|
+
it "allows subsecond timeouts" do
|
30
30
|
lambda do
|
31
31
|
@redises.brpop(@list1, @list2, 0.5)
|
32
|
-
end.
|
32
|
+
end.should_not raise_error(Redis::CommandError)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "raises an error on negative timeout" do
|
36
36
|
lambda do
|
37
37
|
@redises.brpop(@list1, @list2, -1)
|
38
|
-
end.should raise_error(
|
38
|
+
end.should raise_error(Redis::CommandError)
|
39
39
|
end
|
40
40
|
|
41
41
|
it_should_behave_like "a list-only command"
|
@@ -24,16 +24,16 @@ describe '#brpoplpush(source, destination, timeout)' do
|
|
24
24
|
@redises.brpoplpush(@list1, @list2, 0).should == "B"
|
25
25
|
end
|
26
26
|
|
27
|
-
it "
|
27
|
+
it "allows subsecond timeout" do
|
28
28
|
lambda do
|
29
29
|
@redises.brpoplpush(@list1, @list2, 0.5)
|
30
|
-
end.
|
30
|
+
end.should_not raise_error(Redis::CommandError)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "raises an error on negative timeout" do
|
34
34
|
lambda do
|
35
35
|
@redises.brpoplpush(@list1, @list2, -1)
|
36
|
-
end.should raise_error(
|
36
|
+
end.should raise_error(Redis::CommandError)
|
37
37
|
end
|
38
38
|
|
39
39
|
it_should_behave_like "a list-only command"
|
data/spec/commands/hdel_spec.rb
CHANGED
@@ -38,5 +38,10 @@ describe "#hdel(key, field)" do
|
|
38
38
|
@redises.get(@key).should be_nil
|
39
39
|
end
|
40
40
|
|
41
|
+
it "supports a variable number of arguments" do
|
42
|
+
@redises.hdel(@key, ['k1', 'k2'])
|
43
|
+
@redises.get(@key).should be_nil
|
44
|
+
end
|
45
|
+
|
41
46
|
it_should_behave_like "a hash-only command"
|
42
47
|
end
|
data/spec/commands/lpush_spec.rb
CHANGED
@@ -26,5 +26,12 @@ describe "#lpush(key, value)" do
|
|
26
26
|
@redises.lindex(@key, 0).should == "1"
|
27
27
|
end
|
28
28
|
|
29
|
+
it "supports a variable number of arguments" do
|
30
|
+
@redises.lpush(@key, [1, 2, 3]).should == 3
|
31
|
+
@redises.lindex(@key, 0).should == "3"
|
32
|
+
@redises.lindex(@key, 1).should == "2"
|
33
|
+
@redises.lindex(@key, 2).should == "1"
|
34
|
+
end
|
35
|
+
|
29
36
|
it_should_behave_like "a list-only command"
|
30
37
|
end
|
@@ -33,9 +33,15 @@ describe "#mapped_hmset(key, hash={})" do
|
|
33
33
|
end.should raise_error(ArgumentError)
|
34
34
|
end
|
35
35
|
|
36
|
+
it "raises an error if given a an odd length array" do
|
37
|
+
lambda do
|
38
|
+
@redises.mapped_hmset(@key, [1])
|
39
|
+
end.should raise_error(Redis::CommandError)
|
40
|
+
end
|
41
|
+
|
36
42
|
it "raises an error if given a non-hash value" do
|
37
43
|
lambda do
|
38
44
|
@redises.mapped_hmset(@key, 1)
|
39
|
-
end.should raise_error(
|
45
|
+
end.should raise_error(NoMethodError)
|
40
46
|
end
|
41
47
|
end
|
data/spec/commands/move_spec.rb
CHANGED
@@ -122,7 +122,7 @@ describe '#move(key, db)' do
|
|
122
122
|
|
123
123
|
it "copies key to destdb" do
|
124
124
|
@redises.select(@destdb)
|
125
|
-
@redises.smembers(@key).should == %w[beer
|
125
|
+
@redises.smembers(@key).should == %w[wine beer]
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
@@ -141,7 +141,7 @@ describe '#move(key, db)' do
|
|
141
141
|
it "copies key to destdb" do
|
142
142
|
@redises.select(@destdb)
|
143
143
|
@redises.zrange(@key, 0, -1, :with_scores => true).should ==
|
144
|
-
|
144
|
+
[["beer", 1.0], ["wine", 2.0]]
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
@@ -7,7 +7,7 @@ describe '#msetnx(key, value [, key, value, ...])' do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "responds with 1 if any keys were set" do
|
10
|
-
@redises.msetnx(@key1, 1).should
|
10
|
+
@redises.msetnx(@key1, 1).should be_true
|
11
11
|
end
|
12
12
|
|
13
13
|
it "sets the values" do
|
@@ -23,7 +23,7 @@ describe '#msetnx(key, value [, key, value, ...])' do
|
|
23
23
|
|
24
24
|
it "responds with 0 if any value is already set" do
|
25
25
|
@redises.set(@key1, "old1")
|
26
|
-
@redises.msetnx(@key1, 'value1', @key2, 'value2').should
|
26
|
+
@redises.msetnx(@key1, 'value1', @key2, 'value2').should be_false
|
27
27
|
end
|
28
28
|
|
29
29
|
it "raises an error if given an odd number of arguments" do
|
@@ -8,4 +8,16 @@ describe '#pipelined' do
|
|
8
8
|
end
|
9
9
|
res.should == true
|
10
10
|
end
|
11
|
+
|
12
|
+
it "returns results of pipelined operations" do
|
13
|
+
@redises.set "hello", "world"
|
14
|
+
@redises.set "foo", "bar"
|
15
|
+
|
16
|
+
results = @redises.pipelined do
|
17
|
+
@redises.get "hello"
|
18
|
+
@redises.get "foo"
|
19
|
+
end
|
20
|
+
|
21
|
+
results.should == ["world", "bar"]
|
22
|
+
end
|
11
23
|
end
|
@@ -17,6 +17,13 @@ describe '#rename(key, newkey)' do
|
|
17
17
|
@redises.get(@newkey).should == "oof"
|
18
18
|
end
|
19
19
|
|
20
|
+
it "raises an error when the source key is nonexistant" do
|
21
|
+
@redises.del(@key)
|
22
|
+
lambda do
|
23
|
+
@redises.rename(@key, @newkey)
|
24
|
+
end.should raise_error(Redis::CommandError)
|
25
|
+
end
|
26
|
+
|
20
27
|
it "raises an error when key == newkey" do
|
21
28
|
lambda do
|
22
29
|
@redises.rename(@key, @key)
|
@@ -22,6 +22,13 @@ describe '#renamenx(key, newkey)' do
|
|
22
22
|
@redises.get(@newkey).should == "oof"
|
23
23
|
end
|
24
24
|
|
25
|
+
it "raises an error when the source key is nonexistant" do
|
26
|
+
@redises.del(@key)
|
27
|
+
lambda do
|
28
|
+
@redises.rename(@key, @newkey)
|
29
|
+
end.should raise_error(Redis::CommandError)
|
30
|
+
end
|
31
|
+
|
25
32
|
it "raises an error when key == newkey" do
|
26
33
|
lambda do
|
27
34
|
@redises.renamenx(@key, @key)
|
data/spec/commands/rpush_spec.rb
CHANGED
@@ -26,5 +26,12 @@ describe "#rpush(key)" do
|
|
26
26
|
@redises.lindex(@key, 0).should == "1"
|
27
27
|
end
|
28
28
|
|
29
|
+
it "supports a variable number of arguments" do
|
30
|
+
@redises.rpush(@key, [1, 2, 3]).should == 3
|
31
|
+
@redises.lindex(@key, 0).should == "1"
|
32
|
+
@redises.lindex(@key, 1).should == "2"
|
33
|
+
@redises.lindex(@key, 2).should == "3"
|
34
|
+
end
|
35
|
+
|
29
36
|
it_should_behave_like "a list-only command"
|
30
37
|
end
|
data/spec/commands/sadd_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe '#sadd(key, member)' do
|
|
15
15
|
it "adds member to the set" do
|
16
16
|
@redises.sadd(@key, 1)
|
17
17
|
@redises.sadd(@key, 2)
|
18
|
-
@redises.smembers(@key).should == %w[1
|
18
|
+
@redises.smembers(@key).should == %w[2 1]
|
19
19
|
end
|
20
20
|
|
21
21
|
it_should_behave_like "a set-only command"
|
data/spec/commands/sdiff_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe '#sdiff(key [, key, ...])' do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "treats missing keys as empty sets" do
|
23
|
-
@redises.sdiff(@evens, 'mock-redis-test:nonesuch').should == %w[
|
23
|
+
@redises.sdiff(@evens, 'mock-redis-test:nonesuch').should == %w[2 4 6 8 10]
|
24
24
|
end
|
25
25
|
|
26
26
|
it "returns the first set when called with a single argument" do
|
@@ -18,7 +18,7 @@ describe '#sdiffstore(destination, key [, key, ...])' do
|
|
18
18
|
|
19
19
|
it "stores the resulting set" do
|
20
20
|
@redises.sdiffstore(@destination, @numbers, @evens)
|
21
|
-
@redises.smembers(@destination).should == %w[
|
21
|
+
@redises.smembers(@destination).should == %w[9 7 5 3 1]
|
22
22
|
end
|
23
23
|
|
24
24
|
it "does not store empty sets" do
|
@@ -28,14 +28,14 @@ describe '#sdiffstore(destination, key [, key, ...])' do
|
|
28
28
|
|
29
29
|
it "treats missing keys as empty sets" do
|
30
30
|
@redises.sdiffstore(@destination, @evens, 'mock-redis-test:nonesuch')
|
31
|
-
@redises.smembers(@destination).should == %w[10
|
31
|
+
@redises.smembers(@destination).should == %w[10 8 6 4 2]
|
32
32
|
end
|
33
33
|
|
34
34
|
it "removes existing elements in destination" do
|
35
35
|
@redises.sadd(@destination, 42)
|
36
36
|
|
37
37
|
@redises.sdiffstore(@destination, @primes)
|
38
|
-
@redises.smembers(@destination).should == %w[
|
38
|
+
@redises.smembers(@destination).should == %w[7 5 3 2]
|
39
39
|
end
|
40
40
|
|
41
41
|
it "raises an error if given 0 sets" do
|
@@ -18,7 +18,7 @@ describe '#sinterstore(destination, key [, key, ...])' do
|
|
18
18
|
|
19
19
|
it "stores the resulting set" do
|
20
20
|
@redises.sinterstore(@destination, @numbers, @evens)
|
21
|
-
@redises.smembers(@destination).should == %w[10
|
21
|
+
@redises.smembers(@destination).should == %w[10 8 6 4 2]
|
22
22
|
end
|
23
23
|
|
24
24
|
it "does not store empty sets" do
|
@@ -30,7 +30,7 @@ describe '#sinterstore(destination, key [, key, ...])' do
|
|
30
30
|
@redises.sadd(@destination, 42)
|
31
31
|
|
32
32
|
@redises.sinterstore(@destination, @primes)
|
33
|
-
@redises.smembers(@destination).should == %w[
|
33
|
+
@redises.smembers(@destination).should == %w[7 5 3 2]
|
34
34
|
end
|
35
35
|
|
36
36
|
it "raises an error if given 0 sets" do
|
@@ -8,10 +8,10 @@ describe '#smembers(key)' do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "returns the set's members" do
|
11
|
-
@redises.sadd(@key,
|
12
|
-
@redises.sadd(@key,
|
13
|
-
@redises.sadd(@key,
|
14
|
-
@redises.smembers(@key).should == %w[
|
11
|
+
@redises.sadd(@key, "Hello")
|
12
|
+
@redises.sadd(@key, "World")
|
13
|
+
@redises.sadd(@key, "Test")
|
14
|
+
@redises.smembers(@key).should == %w[Test World Hello]
|
15
15
|
end
|
16
16
|
|
17
17
|
it_should_behave_like "a set-only command"
|
data/spec/commands/srem_spec.rb
CHANGED
@@ -31,5 +31,10 @@ describe '#srem(key, member)' do
|
|
31
31
|
@redises.get(@key).should be_nil
|
32
32
|
end
|
33
33
|
|
34
|
+
it "supports a variable number of arguments" do
|
35
|
+
@redises.srem(@key, ['bert', 'ernie']).should == 2
|
36
|
+
@redises.get(@key).should be_nil
|
37
|
+
end
|
38
|
+
|
34
39
|
it_should_behave_like "a set-only command"
|
35
40
|
end
|
@@ -10,7 +10,7 @@ describe '#sunion(key [, key, ...])' do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "returns the elements in the resulting set" do
|
13
|
-
@redises.sunion(@evens, @primes).should == %w[10
|
13
|
+
@redises.sunion(@evens, @primes).should == %w[2 4 6 8 10 3 5 7]
|
14
14
|
end
|
15
15
|
|
16
16
|
it "treats missing keys as empty sets" do
|
@@ -37,4 +37,4 @@ describe '#sunion(key [, key, ...])' do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
|
@@ -16,7 +16,7 @@ describe '#sunionstore(destination, key [, key, ...])' do
|
|
16
16
|
|
17
17
|
it "stores the resulting set" do
|
18
18
|
@redises.sunionstore(@destination, @primes, @evens)
|
19
|
-
@redises.smembers(@destination).should == %w[10
|
19
|
+
@redises.smembers(@destination).should == %w[10 8 6 4 7 5 3 2]
|
20
20
|
end
|
21
21
|
|
22
22
|
it "does not store empty sets" do
|
@@ -30,13 +30,13 @@ describe '#sunionstore(destination, key [, key, ...])' do
|
|
30
30
|
@redises.sadd(@destination, 42)
|
31
31
|
|
32
32
|
@redises.sunionstore(@destination, @primes)
|
33
|
-
@redises.smembers(@destination).should == %w[
|
33
|
+
@redises.smembers(@destination).should == %w[7 5 3 2]
|
34
34
|
end
|
35
35
|
|
36
36
|
it "correctly unions and stores when the destination is empty and is one of the arguments" do
|
37
37
|
@redises.sunionstore(@destination, @destination, @primes)
|
38
38
|
|
39
|
-
@redises.smembers(@destination).should == %w[
|
39
|
+
@redises.smembers(@destination).should == %w[7 5 3 2]
|
40
40
|
end
|
41
41
|
|
42
42
|
it "raises an error if given 0 sets" do
|
data/spec/commands/watch_spec.rb
CHANGED
data/spec/commands/zadd_spec.rb
CHANGED
@@ -27,7 +27,12 @@ describe "#zadd(key, score, member)" do
|
|
27
27
|
@redises.zadd(@key, 1, 'foo')
|
28
28
|
@redises.zadd(@key, 2, 'foo')
|
29
29
|
|
30
|
-
@redises.zscore(@key, 'foo').should ==
|
30
|
+
@redises.zscore(@key, 'foo').should == 2.0
|
31
|
+
end
|
32
|
+
|
33
|
+
it "supports a variable number of arguments" do
|
34
|
+
@redises.zadd(@key, [[1, 'one'], [2, 'two']])
|
35
|
+
@redises.zrange(@key, 0, -1).should == ['one', 'two']
|
31
36
|
end
|
32
37
|
|
33
38
|
it_should_behave_like "arg 1 is a score"
|
@@ -17,6 +17,14 @@ describe "#zcount(key, min, max)" do
|
|
17
17
|
@redises.zcount(@key, 100, 200).should == 0
|
18
18
|
end
|
19
19
|
|
20
|
+
it "returns count of all elements when -inf to +inf" do
|
21
|
+
@redises.zcount(@key, "-inf", '+inf').should == 4
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns a proper count of elements using +inf upper bound" do
|
25
|
+
@redises.zcount(@key, 3, "+inf").should == 2
|
26
|
+
end
|
27
|
+
|
20
28
|
it_should_behave_like "arg 1 is a score"
|
21
29
|
it_should_behave_like "arg 2 is a score"
|
22
30
|
it_should_behave_like "a zset-only command"
|
@@ -7,23 +7,23 @@ describe "#zincrby(key, increment, member)" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "returns the new score as a string" do
|
10
|
-
@redises.zincrby(@key, 10, 'bert').should ==
|
10
|
+
@redises.zincrby(@key, 10, 'bert').should == 11.0
|
11
11
|
end
|
12
12
|
|
13
13
|
it "updates the item's score" do
|
14
14
|
@redises.zincrby(@key, 10, 'bert')
|
15
|
-
@redises.zscore(@key, 'bert').should ==
|
15
|
+
@redises.zscore(@key, 'bert').should == 11.0
|
16
16
|
end
|
17
17
|
|
18
18
|
it "handles integer members correctly" do
|
19
19
|
member = 11
|
20
20
|
@redises.zadd(@key, 1, member)
|
21
21
|
@redises.zincrby(@key, 1, member)
|
22
|
-
@redises.zscore(@key, member).should ==
|
22
|
+
@redises.zscore(@key, member).should == 2.0
|
23
23
|
end
|
24
24
|
|
25
25
|
it "adds missing members with score increment" do
|
26
|
-
@redises.zincrby(@key, 5.5, 'bigbird').should ==
|
26
|
+
@redises.zincrby(@key, 5.5, 'bigbird').should == 5.5
|
27
27
|
end
|
28
28
|
|
29
29
|
it_should_behave_like "arg 1 is a score"
|
@@ -25,7 +25,7 @@ describe "#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
|
|
25
25
|
it "sums the members' scores by default" do
|
26
26
|
@redises.zinterstore(@dest, [@odds, @primes])
|
27
27
|
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
28
|
-
|
28
|
+
[["three", 6.0], ["five", 10.0], ["seven", 14.0]]
|
29
29
|
end
|
30
30
|
|
31
31
|
it "removes existing elements in destination" do
|
@@ -33,7 +33,7 @@ describe "#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
|
|
33
33
|
|
34
34
|
@redises.zinterstore(@dest, [@primes])
|
35
35
|
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
36
|
-
|
36
|
+
[["two", 2.0], ["three", 3.0], ["five", 5.0], ["seven", 7.0]]
|
37
37
|
end
|
38
38
|
|
39
39
|
it "raises an error if keys is empty" do
|
@@ -46,7 +46,7 @@ describe "#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
|
|
46
46
|
it "multiplies the scores by the weights while aggregating" do
|
47
47
|
@redises.zinterstore(@dest, [@odds, @primes], :weights => [2, 3])
|
48
48
|
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
49
|
-
|
49
|
+
[["three", 15.0], ["five", 25.0], ["seven", 35.0]]
|
50
50
|
end
|
51
51
|
|
52
52
|
it "raises an error if the number of weights != the number of keys" do
|
@@ -70,21 +70,21 @@ describe "#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
|
|
70
70
|
it "aggregates scores with min when :aggregate => :min is specified" do
|
71
71
|
@redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => :min)
|
72
72
|
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
73
|
-
|
73
|
+
[["bert", 1.0], ["ernie", 2.0]]
|
74
74
|
end
|
75
75
|
|
76
76
|
it "aggregates scores with max when :aggregate => :max is specified" do
|
77
77
|
@redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => :max)
|
78
78
|
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
79
|
-
|
79
|
+
[["bert", 100.0], ["ernie", 200.0]]
|
80
80
|
end
|
81
81
|
|
82
82
|
it "allows 'min', 'MIN', etc. as aliases for :min" do
|
83
83
|
@redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => 'min')
|
84
|
-
@redises.zscore(@dest, 'bert').should ==
|
84
|
+
@redises.zscore(@dest, 'bert').should == 1.0
|
85
85
|
|
86
86
|
@redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => 'MIN')
|
87
|
-
@redises.zscore(@dest, 'bert').should ==
|
87
|
+
@redises.zscore(@dest, 'bert').should == 1.0
|
88
88
|
end
|
89
89
|
|
90
90
|
it "raises an error for unknown aggregation function" do
|
@@ -9,6 +9,10 @@ describe "#zrange(key, start, stop [, :with_scores => true])" do
|
|
9
9
|
@redises.zadd(@key, 4, 'Madison')
|
10
10
|
end
|
11
11
|
|
12
|
+
it "returns the elements when the range is given as strings" do
|
13
|
+
@redises.zrange(@key, "0", "1").should == ['Washington', 'Adams']
|
14
|
+
end
|
15
|
+
|
12
16
|
it "returns the elements in order by score" do
|
13
17
|
@redises.zrange(@key, 0, 1).should == ['Washington', 'Adams']
|
14
18
|
end
|
@@ -23,12 +27,12 @@ describe "#zrange(key, start, stop [, :with_scores => true])" do
|
|
23
27
|
|
24
28
|
it "returns the scores when :with_scores is specified" do
|
25
29
|
@redises.zrange(@key, 0, 1, :with_scores => true).
|
26
|
-
should == ["Washington",
|
30
|
+
should == [["Washington", 1.0], ["Adams", 2.0]]
|
27
31
|
end
|
28
32
|
|
29
33
|
it "returns the scores when :withscores is specified" do
|
30
34
|
@redises.zrange(@key, 0, 1, :withscores => true).
|
31
|
-
should == ["Washington",
|
35
|
+
should == [["Washington", 1.0], ["Adams", 2.0]]
|
32
36
|
end
|
33
37
|
|
34
38
|
it_should_behave_like "a zset-only command"
|
@@ -15,12 +15,12 @@ describe "#zrangebyscore(key, start, stop [:with_scores => true] [:limit => [off
|
|
15
15
|
|
16
16
|
it "returns the scores when :with_scores is specified" do
|
17
17
|
@redises.zrangebyscore(@key, 1, 2, :with_scores => true).
|
18
|
-
should == ["Washington",
|
18
|
+
should == [["Washington", 1.0], ["Adams", 2.0]]
|
19
19
|
end
|
20
20
|
|
21
21
|
it "returns the scores when :withscores is specified" do
|
22
22
|
@redises.zrangebyscore(@key, 1, 2, :withscores => true).
|
23
|
-
should == ["Washington",
|
23
|
+
should == [["Washington", 1.0], ["Adams", 2.0]]
|
24
24
|
end
|
25
25
|
|
26
26
|
it "honors the :limit => [offset count] argument" do
|
data/spec/commands/zrem_spec.rb
CHANGED
@@ -28,5 +28,10 @@ describe "#zrem(key, member)" do
|
|
28
28
|
@redises.zrange(@key, 0, -1).should == ['one', 'two']
|
29
29
|
end
|
30
30
|
|
31
|
+
it "supports a variable number of arguments" do
|
32
|
+
@redises.zrem(@key, ['one', 'two'])
|
33
|
+
@redises.zrange(@key, 0, -1).should be_empty
|
34
|
+
end
|
35
|
+
|
31
36
|
it_should_behave_like "a zset-only command"
|
32
37
|
end
|