mock_redis 0.14.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.overcommit.yml +1 -1
- data/.rubocop.yml +91 -0
- data/.simplecov +4 -0
- data/.travis.yml +14 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -2
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/lib/mock_redis.rb +25 -26
- data/lib/mock_redis/assertions.rb +0 -1
- data/lib/mock_redis/database.rb +35 -28
- data/lib/mock_redis/expire_wrapper.rb +1 -1
- data/lib/mock_redis/future.rb +1 -1
- data/lib/mock_redis/hash_methods.rb +18 -17
- data/lib/mock_redis/indifferent_hash.rb +4 -0
- data/lib/mock_redis/info_method.rb +109 -108
- data/lib/mock_redis/list_methods.rb +17 -16
- data/lib/mock_redis/multi_db_wrapper.rb +5 -4
- data/lib/mock_redis/pipelined_wrapper.rb +3 -3
- data/lib/mock_redis/set_methods.rb +10 -9
- data/lib/mock_redis/sort_method.rb +11 -12
- data/lib/mock_redis/string_methods.rb +26 -29
- data/lib/mock_redis/transaction_wrapper.rb +7 -8
- data/lib/mock_redis/utility_methods.rb +9 -12
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +22 -23
- data/lib/mock_redis/zset_methods.rb +25 -25
- data/spec/cloning_spec.rb +17 -18
- data/spec/commands/append_spec.rb +4 -4
- data/spec/commands/auth_spec.rb +1 -1
- data/spec/commands/bgrewriteaof_spec.rb +2 -2
- data/spec/commands/bgsave_spec.rb +2 -2
- data/spec/commands/bitcount_spec.rb +3 -3
- data/spec/commands/blpop_spec.rb +10 -10
- data/spec/commands/brpop_spec.rb +10 -10
- data/spec/commands/brpoplpush_spec.rb +9 -9
- data/spec/commands/connected_spec.rb +2 -2
- data/spec/commands/dbsize_spec.rb +3 -3
- data/spec/commands/decr_spec.rb +7 -7
- data/spec/commands/decrby_spec.rb +7 -7
- data/spec/commands/del_spec.rb +4 -4
- data/spec/commands/disconnect_spec.rb +2 -2
- data/spec/commands/echo_spec.rb +4 -4
- data/spec/commands/exists_spec.rb +3 -3
- data/spec/commands/expire_spec.rb +13 -13
- data/spec/commands/expireat_spec.rb +6 -7
- data/spec/commands/flushall_spec.rb +5 -5
- data/spec/commands/flushdb_spec.rb +5 -5
- data/spec/commands/future_spec.rb +2 -2
- data/spec/commands/get_spec.rb +7 -7
- data/spec/commands/getbit_spec.rb +6 -6
- data/spec/commands/getrange_spec.rb +9 -9
- data/spec/commands/getset_spec.rb +7 -7
- data/spec/commands/hash_operator_spec.rb +5 -5
- data/spec/commands/hdel_spec.rb +12 -12
- data/spec/commands/hexists_spec.rb +7 -7
- data/spec/commands/hget_spec.rb +7 -7
- data/spec/commands/hgetall_spec.rb +6 -6
- data/spec/commands/hincrby_spec.rb +14 -14
- data/spec/commands/hincrbyfloat_spec.rb +14 -14
- data/spec/commands/hkeys_spec.rb +5 -5
- data/spec/commands/hlen_spec.rb +5 -5
- data/spec/commands/hmget_spec.rb +8 -8
- data/spec/commands/hmset_spec.rb +10 -10
- data/spec/commands/hset_spec.rb +11 -11
- data/spec/commands/hsetnx_spec.rb +14 -14
- data/spec/commands/hvals_spec.rb +5 -5
- data/spec/commands/incr_spec.rb +7 -7
- data/spec/commands/incrby_spec.rb +11 -11
- data/spec/commands/incrbyfloat_spec.rb +11 -11
- data/spec/commands/info_spec.rb +30 -30
- data/spec/commands/keys_spec.rb +42 -43
- data/spec/commands/lastsave_spec.rb +2 -2
- data/spec/commands/lindex_spec.rb +15 -15
- data/spec/commands/linsert_spec.rb +13 -13
- data/spec/commands/llen_spec.rb +4 -4
- data/spec/commands/lpop_spec.rb +6 -6
- data/spec/commands/lpush_spec.rb +16 -16
- data/spec/commands/lpushx_spec.rb +13 -13
- data/spec/commands/lrange_spec.rb +12 -12
- data/spec/commands/lrem_spec.rb +15 -15
- data/spec/commands/lset_spec.rb +12 -12
- data/spec/commands/ltrim_spec.rb +9 -9
- data/spec/commands/mapped_hmget_spec.rb +8 -8
- data/spec/commands/mapped_hmset_spec.rb +12 -12
- data/spec/commands/mapped_mget_spec.rb +4 -4
- data/spec/commands/mapped_mset_spec.rb +1 -1
- data/spec/commands/mget_spec.rb +11 -11
- data/spec/commands/move_spec.rb +29 -29
- data/spec/commands/mset_spec.rb +4 -4
- data/spec/commands/msetnx_spec.rb +10 -10
- data/spec/commands/persist_spec.rb +9 -10
- data/spec/commands/pexpire_spec.rb +12 -13
- data/spec/commands/pexpireat_spec.rb +6 -6
- data/spec/commands/ping_spec.rb +1 -1
- data/spec/commands/pipelined_spec.rb +5 -5
- data/spec/commands/pttl_spec.rb +5 -5
- data/spec/commands/randomkey_spec.rb +3 -3
- data/spec/commands/rename_spec.rb +9 -9
- data/spec/commands/renamenx_spec.rb +10 -10
- data/spec/commands/rpop_spec.rb +6 -6
- data/spec/commands/rpoplpush_spec.rb +7 -7
- data/spec/commands/rpush_spec.rb +16 -16
- data/spec/commands/rpushx_spec.rb +13 -13
- data/spec/commands/sadd_spec.rb +8 -9
- data/spec/commands/scan_spec.rb +6 -7
- data/spec/commands/scard_spec.rb +3 -3
- data/spec/commands/sdiff_spec.rb +10 -10
- data/spec/commands/sdiffstore_spec.rb +10 -10
- data/spec/commands/select_spec.rb +7 -7
- data/spec/commands/setbit_spec.rb +13 -13
- data/spec/commands/setex_spec.rb +4 -4
- data/spec/commands/setnx_spec.rb +4 -4
- data/spec/commands/setrange_spec.rb +12 -12
- data/spec/commands/sinter_spec.rb +8 -10
- data/spec/commands/sinterstore_spec.rb +9 -9
- data/spec/commands/sismember_spec.rb +5 -5
- data/spec/commands/smembers_spec.rb +5 -5
- data/spec/commands/smove_spec.rb +7 -7
- data/spec/commands/sort_list_spec.rb +3 -3
- data/spec/commands/sort_set_spec.rb +3 -3
- data/spec/commands/sort_zset_spec.rb +3 -3
- data/spec/commands/spop_spec.rb +4 -4
- data/spec/commands/srandmember_spec.rb +8 -8
- data/spec/commands/srem_spec.rb +9 -9
- data/spec/commands/strlen_spec.rb +4 -4
- data/spec/commands/sunion_spec.rb +7 -9
- data/spec/commands/sunionstore_spec.rb +9 -9
- data/spec/commands/ttl_spec.rb +5 -5
- data/spec/commands/type_spec.rb +1 -1
- data/spec/commands/zadd_spec.rb +10 -10
- data/spec/commands/zcard_spec.rb +4 -4
- data/spec/commands/zcount_spec.rb +14 -14
- data/spec/commands/zincrby_spec.rb +6 -6
- data/spec/commands/zinterstore_spec.rb +17 -17
- data/spec/commands/zrange_spec.rb +12 -12
- data/spec/commands/zrangebyscore_spec.rb +26 -26
- data/spec/commands/zrank_spec.rb +4 -4
- data/spec/commands/zrem_spec.rb +9 -9
- data/spec/commands/zremrangebyrank_spec.rb +5 -5
- data/spec/commands/zremrangebyscore_spec.rb +9 -7
- data/spec/commands/zrevrange_spec.rb +10 -10
- data/spec/commands/zrevrangebyscore_spec.rb +14 -14
- data/spec/commands/zrevrank_spec.rb +4 -4
- data/spec/commands/zscore_spec.rb +5 -5
- data/spec/commands/zunionstore_spec.rb +18 -18
- data/spec/mock_redis_spec.rb +11 -1
- data/spec/spec_helper.rb +13 -4
- data/spec/support/redis_multiplexer.rb +39 -31
- data/spec/support/shared_examples/only_operates_on_hashes.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_lists.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_sets.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_strings.rb +3 -3
- data/spec/support/shared_examples/only_operates_on_zsets.rb +12 -12
- data/spec/support/shared_examples/sorts_enumerables.rb +12 -12
- data/spec/transactions_spec.rb +18 -18
- metadata +5 -3
data/spec/commands/zcard_spec.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zcard(key)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zcard'
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'returns the number of elements in the zset' do
|
9
9
|
@redises.zadd(@key, 1, 'Washington')
|
10
10
|
@redises.zadd(@key, 2, 'Adams')
|
11
11
|
@redises.zcard(@key).should == 2
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'returns 0 for nonexistent sets' do
|
15
15
|
@redises.zcard(@key).should == 0
|
16
16
|
end
|
17
17
|
|
18
|
-
it_should_behave_like
|
18
|
+
it_should_behave_like 'a zset-only command'
|
19
19
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zcount(key, min, max)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zcount'
|
6
6
|
@redises.zadd(@key, 1, 'Washington')
|
@@ -9,31 +9,31 @@ describe "#zcount(key, min, max)" do
|
|
9
9
|
@redises.zadd(@key, 4, 'Madison')
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'returns the number of members in the zset with scores in (min..max)' do
|
13
13
|
@redises.zcount(@key, 3, 10).should == 2
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'returns 0 if there are no such members' do
|
17
17
|
@redises.zcount(@key, 100, 200).should == 0
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
@redises.zcount(@key,
|
20
|
+
it 'returns count of all elements when -inf to +inf' do
|
21
|
+
@redises.zcount(@key, '-inf', '+inf').should == 4
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
@redises.zcount(@key, 3,
|
24
|
+
it 'returns a proper count of elements using +inf upper bound' do
|
25
|
+
@redises.zcount(@key, 3, '+inf').should == 2
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
29
|
-
@redises.zcount(@key, '(3',
|
28
|
+
it 'returns a proper count of elements using exclusive lower bound' do
|
29
|
+
@redises.zcount(@key, '(3', '+inf').should == 1
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
33
|
-
@redises.zcount(@key, '-inf',
|
32
|
+
it 'returns a proper count of elements using exclusive upper bound' do
|
33
|
+
@redises.zcount(@key, '-inf', '(3').should == 2
|
34
34
|
end
|
35
35
|
|
36
|
-
it_should_behave_like
|
37
|
-
it_should_behave_like
|
38
|
-
it_should_behave_like
|
36
|
+
it_should_behave_like 'arg 1 is a score'
|
37
|
+
it_should_behave_like 'arg 2 is a score'
|
38
|
+
it_should_behave_like 'a zset-only command'
|
39
39
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zincrby(key, increment, member)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zincrby'
|
6
6
|
@redises.zadd(@key, 1, 'bert')
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'returns the new score as a string' do
|
10
10
|
@redises.zincrby(@key, 10, 'bert').should == 11.0
|
11
11
|
end
|
12
12
|
|
@@ -15,17 +15,17 @@ describe "#zincrby(key, increment, member)" do
|
|
15
15
|
@redises.zscore(@key, 'bert').should == 11.0
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
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
22
|
@redises.zscore(@key, member).should == 2.0
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it 'adds missing members with score increment' do
|
26
26
|
@redises.zincrby(@key, 5.5, 'bigbird').should == 5.5
|
27
27
|
end
|
28
28
|
|
29
|
-
it_should_behave_like
|
30
|
-
it_should_behave_like
|
29
|
+
it_should_behave_like 'arg 1 is a score'
|
30
|
+
it_should_behave_like 'a zset-only command'
|
31
31
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :sum|:min|:max])' do
|
4
4
|
before do
|
5
5
|
@odds = 'mock-redis-test:zinterstore:odds'
|
6
6
|
@primes = 'mock-redis-test:zinterstore:primes'
|
@@ -18,45 +18,45 @@ describe "#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
|
|
18
18
|
@redises.zadd(@primes, 7, 'seven')
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it 'returns the number of elements in the new set' do
|
22
22
|
@redises.zinterstore(@dest, [@odds, @primes]).should == 3
|
23
23
|
end
|
24
24
|
|
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
|
-
it
|
31
|
+
it 'removes existing elements in destination' do
|
32
32
|
@redises.zadd(@dest, 10, 'ten')
|
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
|
-
it
|
39
|
+
it 'raises an error if keys is empty' do
|
40
40
|
lambda do
|
41
41
|
@redises.zinterstore(@dest, [])
|
42
42
|
end.should raise_error(RuntimeError)
|
43
43
|
end
|
44
44
|
|
45
|
-
context
|
46
|
-
it
|
45
|
+
context 'the :weights argument' do
|
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
|
-
it
|
52
|
+
it 'raises an error if the number of weights != the number of keys' do
|
53
53
|
lambda do
|
54
|
-
@redises.zinterstore(@dest, [@odds, @primes], :weights => [1,2,3])
|
54
|
+
@redises.zinterstore(@dest, [@odds, @primes], :weights => [1, 2, 3])
|
55
55
|
end.should raise_error(RuntimeError)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
context
|
59
|
+
context 'the :aggregate argument' do
|
60
60
|
before do
|
61
61
|
@smalls = 'mock-redis-test:zinterstore:smalls'
|
62
62
|
@bigs = 'mock-redis-test:zinterstore:bigs'
|
@@ -67,16 +67,16 @@ describe "#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
|
|
67
67
|
@redises.zadd(@bigs, 200, 'ernie')
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
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
|
-
it
|
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
|
@@ -87,7 +87,7 @@ describe "#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :s
|
|
87
87
|
@redises.zscore(@dest, 'bert').should == 1.0
|
88
88
|
end
|
89
89
|
|
90
|
-
it
|
90
|
+
it 'raises an error for unknown aggregation function' do
|
91
91
|
lambda do
|
92
92
|
@redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => :mix)
|
93
93
|
end.should raise_error(RuntimeError)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zrange(key, start, stop [, :with_scores => true])' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zrange'
|
6
6
|
@redises.zadd(@key, 1, 'Washington')
|
@@ -20,31 +20,31 @@ describe "#zrange(key, start, stop [, :with_scores => true])" do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
@redises.zrange(@key,
|
23
|
+
it 'returns the elements when the range is given as strings' do
|
24
|
+
@redises.zrange(@key, '0', '1').should == %w[Washington Adams]
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
@redises.zrange(@key, 0, 1).should == [
|
27
|
+
it 'returns the elements in order by score' do
|
28
|
+
@redises.zrange(@key, 0, 1).should == %w[Washington Adams]
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
32
|
-
@redises.zrange(@key, -2, -1).should == [
|
31
|
+
it 'returns the elements in order by score (negative indices)' do
|
32
|
+
@redises.zrange(@key, -2, -1).should == %w[Jefferson Madison]
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'returns empty list when start is too large' do
|
36
36
|
@redises.zrange(@key, 5, -1).should == []
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it 'returns the scores when :with_scores is specified' do
|
40
40
|
@redises.zrange(@key, 0, 1, :with_scores => true).
|
41
|
-
should == [[
|
41
|
+
should == [['Washington', 1.0], ['Adams', 2.0]]
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
44
|
+
it 'returns the scores when :withscores is specified' do
|
45
45
|
@redises.zrange(@key, 0, 1, :withscores => true).
|
46
|
-
should == [[
|
46
|
+
should == [['Washington', 1.0], ['Adams', 2.0]]
|
47
47
|
end
|
48
48
|
|
49
|
-
it_should_behave_like
|
49
|
+
it_should_behave_like 'a zset-only command'
|
50
50
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zrangebyscore(key, start, stop [:with_scores => true] [:limit => [offset count]])' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zrangebyscore'
|
6
6
|
@redises.zadd(@key, 1, 'Washington')
|
@@ -20,23 +20,23 @@ describe "#zrangebyscore(key, start, stop [:with_scores => true] [:limit => [off
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
@redises.zrangebyscore(@key, 1, 2).should == [
|
23
|
+
it 'returns the elements in order by score' do
|
24
|
+
@redises.zrangebyscore(@key, 1, 2).should == %w[Washington Adams]
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'returns the scores when :with_scores is specified' do
|
28
28
|
@redises.zrangebyscore(@key, 1, 2, :with_scores => true).
|
29
|
-
should == [[
|
29
|
+
should == [['Washington', 1.0], ['Adams', 2.0]]
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
32
|
+
it 'returns the scores when :withscores is specified' do
|
33
33
|
@redises.zrangebyscore(@key, 1, 2, :withscores => true).
|
34
|
-
should == [[
|
34
|
+
should == [['Washington', 1.0], ['Adams', 2.0]]
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it 'honors the :limit => [offset count] argument' do
|
38
38
|
@redises.zrangebyscore(@key, -100, 100, :limit => [1, 2]).
|
39
|
-
should == [
|
39
|
+
should == %w[Adams Jefferson]
|
40
40
|
end
|
41
41
|
|
42
42
|
it "raises an error if :limit isn't a 2-tuple" do
|
@@ -45,35 +45,35 @@ describe "#zrangebyscore(key, start, stop [:with_scores => true] [:limit => [off
|
|
45
45
|
end.should raise_error(RuntimeError)
|
46
46
|
|
47
47
|
lambda do
|
48
|
-
@redises.zrangebyscore(@key, -100, 100, :limit =>
|
49
|
-
end.should raise_error
|
48
|
+
@redises.zrangebyscore(@key, -100, 100, :limit => '1, 2')
|
49
|
+
end.should raise_error(RedisMultiplexer::MismatchedResponse)
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
53
|
-
@redises.zadd(@key,
|
54
|
-
@redises.zrangebyscore(@key, 1, 2).should == [
|
52
|
+
it 'treats scores like floats, not strings' do
|
53
|
+
@redises.zadd(@key, '10', 'Tyler')
|
54
|
+
@redises.zrangebyscore(@key, 1, 2).should == %w[Washington Adams]
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
58
|
-
@redises.zrangebyscore(@key,
|
59
|
-
[
|
57
|
+
it 'treats -inf as negative infinity' do
|
58
|
+
@redises.zrangebyscore(@key, '-inf', 3).should ==
|
59
|
+
%w[Washington Adams Jefferson]
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
63
|
-
@redises.zrangebyscore(@key, 3,
|
62
|
+
it 'treats +inf as positive infinity' do
|
63
|
+
@redises.zrangebyscore(@key, 3, '+inf').should == %w[Jefferson Madison]
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
67
|
-
@redises.zrangebyscore(@key, 3,
|
66
|
+
it 'treats +inf as positive infinity' do
|
67
|
+
@redises.zrangebyscore(@key, 3, '+inf').should == %w[Jefferson Madison]
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
71
|
-
@redises.zrangebyscore(@key,
|
70
|
+
it 'honors exclusive ranges on the left' do
|
71
|
+
@redises.zrangebyscore(@key, '(3', 4).should == ['Madison']
|
72
72
|
end
|
73
73
|
|
74
|
-
it
|
75
|
-
@redises.zrangebyscore(@key,
|
74
|
+
it 'honors exclusive ranges on the right' do
|
75
|
+
@redises.zrangebyscore(@key, '3', '(4').should == ['Jefferson']
|
76
76
|
end
|
77
77
|
|
78
|
-
it_should_behave_like
|
78
|
+
it_should_behave_like 'a zset-only command'
|
79
79
|
end
|
data/spec/commands/zrank_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zrank(key, member)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zrank'
|
6
6
|
|
@@ -13,17 +13,17 @@ describe "#zrank(key, member)" do
|
|
13
13
|
@redises.zrank(@key, 'foo').should be_nil
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'returns the index of the member in the set' do
|
17
17
|
@redises.zrank(@key, 'one').should == 0
|
18
18
|
@redises.zrank(@key, 'two').should == 1
|
19
19
|
@redises.zrank(@key, 'three').should == 2
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'handles integer members correctly' do
|
23
23
|
member = 11
|
24
24
|
@redises.zadd(@key, 4, member)
|
25
25
|
@redises.zrank(@key, member).should == 3
|
26
26
|
end
|
27
27
|
|
28
|
-
it_should_behave_like
|
28
|
+
it_should_behave_like 'a zset-only command'
|
29
29
|
end
|
data/spec/commands/zrem_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zrem(key, member)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zrem'
|
6
6
|
|
@@ -8,30 +8,30 @@ describe "#zrem(key, member)" do
|
|
8
8
|
@redises.zadd(@key, 2, 'two')
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'returns true if member is present in the set' do
|
12
12
|
@redises.zrem(@key, 'one').should == true
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'returns false if member is not present in the set' do
|
16
16
|
@redises.zrem(@key, 'nobody home').should == false
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'removes member from the set' do
|
20
20
|
@redises.zrem(@key, 'one')
|
21
21
|
@redises.zrange(@key, 0, -1).should == ['two']
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'removes integer member from the set' do
|
25
25
|
member = 11
|
26
26
|
@redises.zadd(@key, 3, member)
|
27
27
|
@redises.zrem(@key, member).should == true
|
28
|
-
@redises.zrange(@key, 0, -1).should == [
|
28
|
+
@redises.zrange(@key, 0, -1).should == %w[one two]
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
32
|
-
@redises.zrem(@key, [
|
31
|
+
it 'supports a variable number of arguments' do
|
32
|
+
@redises.zrem(@key, %w[one two])
|
33
33
|
@redises.zrange(@key, 0, -1).should be_empty
|
34
34
|
end
|
35
35
|
|
36
|
-
it_should_behave_like
|
36
|
+
it_should_behave_like 'a zset-only command'
|
37
37
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zremrangebyrank(key, start, stop)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zremrangebyrank'
|
6
6
|
@redises.zadd(@key, 1, 'Washington')
|
@@ -9,19 +9,19 @@ describe "#zremrangebyrank(key, start, stop)" do
|
|
9
9
|
@redises.zadd(@key, 4, 'Madison')
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'returns the number of elements in range' do
|
13
13
|
@redises.zremrangebyrank(@key, 2, 3).should == 2
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'removes the elements' do
|
17
17
|
@redises.zremrangebyrank(@key, 2, 3)
|
18
18
|
@redises.zrange(@key, 0, -1).should == %w[Washington Adams]
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it 'does nothing if start is greater than cardinality of set' do
|
22
22
|
@redises.zremrangebyrank(@key, 5, -1)
|
23
23
|
@redises.zrange(@key, 0, -1).should == %w[Washington Adams Jefferson Madison]
|
24
24
|
end
|
25
25
|
|
26
|
-
it_should_behave_like
|
26
|
+
it_should_behave_like 'a zset-only command'
|
27
27
|
end
|