mock_redis 0.19.0 → 0.44.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 +4 -4
- data/CHANGELOG.md +161 -0
- data/LICENSE.md +21 -0
- data/README.md +41 -17
- data/lib/mock_redis/connection_method.rb +13 -0
- data/lib/mock_redis/database.rb +116 -41
- data/lib/mock_redis/expire_wrapper.rb +1 -1
- data/lib/mock_redis/future.rb +1 -1
- data/lib/mock_redis/geospatial_methods.rb +13 -21
- data/lib/mock_redis/hash_methods.rb +34 -15
- data/lib/mock_redis/indifferent_hash.rb +0 -8
- data/lib/mock_redis/info_method.rb +2 -2
- data/lib/mock_redis/list_methods.rb +39 -4
- data/lib/mock_redis/memory_method.rb +11 -0
- data/lib/mock_redis/multi_db_wrapper.rb +4 -4
- data/lib/mock_redis/pipelined_wrapper.rb +32 -15
- data/lib/mock_redis/set_methods.rb +34 -6
- data/lib/mock_redis/stream/id.rb +58 -0
- data/lib/mock_redis/stream.rb +88 -0
- data/lib/mock_redis/stream_methods.rb +102 -0
- data/lib/mock_redis/string_methods.rb +81 -30
- data/lib/mock_redis/transaction_wrapper.rb +32 -21
- data/lib/mock_redis/utility_methods.rb +9 -4
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +5 -8
- data/lib/mock_redis/zset_methods.rb +64 -12
- data/lib/mock_redis.rb +38 -10
- metadata +40 -336
- data/.gitignore +0 -5
- data/.mailmap +0 -2
- data/.overcommit.yml +0 -21
- data/.rspec +0 -1
- data/.rubocop.yml +0 -121
- data/.rubocop_todo.yml +0 -35
- data/.simplecov +0 -4
- data/.travis.yml +0 -33
- data/Gemfile +0 -12
- data/LICENSE +0 -19
- data/Rakefile +0 -2
- data/mock_redis.gemspec +0 -30
- data/spec/client_spec.rb +0 -17
- data/spec/cloning_spec.rb +0 -95
- data/spec/commands/append_spec.rb +0 -24
- data/spec/commands/auth_spec.rb +0 -7
- data/spec/commands/bgrewriteaof_spec.rb +0 -7
- data/spec/commands/bgsave_spec.rb +0 -7
- data/spec/commands/bitcount_spec.rb +0 -25
- data/spec/commands/bitfield_spec.rb +0 -169
- data/spec/commands/blpop_spec.rb +0 -59
- data/spec/commands/brpop_spec.rb +0 -58
- data/spec/commands/brpoplpush_spec.rb +0 -52
- data/spec/commands/connected_spec.rb +0 -7
- data/spec/commands/dbsize_spec.rb +0 -18
- data/spec/commands/decr_spec.rb +0 -34
- data/spec/commands/decrby_spec.rb +0 -34
- data/spec/commands/del_spec.rb +0 -35
- data/spec/commands/disconnect_spec.rb +0 -7
- data/spec/commands/echo_spec.rb +0 -11
- data/spec/commands/eval_spec.rb +0 -7
- data/spec/commands/evalsha_spec.rb +0 -10
- data/spec/commands/exists_spec.rb +0 -14
- data/spec/commands/expire_spec.rb +0 -111
- data/spec/commands/expireat_spec.rb +0 -47
- data/spec/commands/flushall_spec.rb +0 -38
- data/spec/commands/flushdb_spec.rb +0 -38
- data/spec/commands/future_spec.rb +0 -20
- data/spec/commands/geoadd_spec.rb +0 -58
- data/spec/commands/geodist_spec.rb +0 -114
- data/spec/commands/geohash_spec.rb +0 -52
- data/spec/commands/geopos_spec.rb +0 -55
- data/spec/commands/get_spec.rb +0 -30
- data/spec/commands/getbit_spec.rb +0 -34
- data/spec/commands/getrange_spec.rb +0 -22
- data/spec/commands/getset_spec.rb +0 -23
- data/spec/commands/hash_operator_spec.rb +0 -21
- data/spec/commands/hdel_spec.rb +0 -54
- data/spec/commands/hexists_spec.rb +0 -27
- data/spec/commands/hget_spec.rb +0 -28
- data/spec/commands/hgetall_spec.rb +0 -32
- data/spec/commands/hincrby_spec.rb +0 -58
- data/spec/commands/hincrbyfloat_spec.rb +0 -58
- data/spec/commands/hkeys_spec.rb +0 -19
- data/spec/commands/hlen_spec.rb +0 -19
- data/spec/commands/hmget_spec.rb +0 -40
- data/spec/commands/hmset_spec.rb +0 -43
- data/spec/commands/hscan_each_spec.rb +0 -48
- data/spec/commands/hscan_spec.rb +0 -27
- data/spec/commands/hset_spec.rb +0 -38
- data/spec/commands/hsetnx_spec.rb +0 -44
- data/spec/commands/hvals_spec.rb +0 -19
- data/spec/commands/incr_spec.rb +0 -34
- data/spec/commands/incrby_spec.rb +0 -44
- data/spec/commands/incrbyfloat_spec.rb +0 -44
- data/spec/commands/info_spec.rb +0 -62
- data/spec/commands/keys_spec.rb +0 -122
- data/spec/commands/lastsave_spec.rb +0 -8
- data/spec/commands/lindex_spec.rb +0 -49
- data/spec/commands/linsert_spec.rb +0 -68
- data/spec/commands/llen_spec.rb +0 -16
- data/spec/commands/lpop_spec.rb +0 -34
- data/spec/commands/lpush_spec.rb +0 -43
- data/spec/commands/lpushx_spec.rb +0 -46
- data/spec/commands/lrange_spec.rb +0 -51
- data/spec/commands/lrem_spec.rb +0 -80
- data/spec/commands/lset_spec.rb +0 -43
- data/spec/commands/ltrim_spec.rb +0 -45
- data/spec/commands/mapped_hmget_spec.rb +0 -29
- data/spec/commands/mapped_hmset_spec.rb +0 -47
- data/spec/commands/mapped_mget_spec.rb +0 -22
- data/spec/commands/mapped_mset_spec.rb +0 -19
- data/spec/commands/mapped_msetnx_spec.rb +0 -26
- data/spec/commands/mget_spec.rb +0 -34
- data/spec/commands/move_spec.rb +0 -147
- data/spec/commands/mset_spec.rb +0 -29
- data/spec/commands/msetnx_spec.rb +0 -40
- data/spec/commands/persist_spec.rb +0 -48
- data/spec/commands/pexpire_spec.rb +0 -86
- data/spec/commands/pexpireat_spec.rb +0 -48
- data/spec/commands/ping_spec.rb +0 -7
- data/spec/commands/pipelined_spec.rb +0 -42
- data/spec/commands/pttl_spec.rb +0 -41
- data/spec/commands/quit_spec.rb +0 -7
- data/spec/commands/randomkey_spec.rb +0 -20
- data/spec/commands/rename_spec.rb +0 -42
- data/spec/commands/renamenx_spec.rb +0 -41
- data/spec/commands/rpop_spec.rb +0 -34
- data/spec/commands/rpoplpush_spec.rb +0 -50
- data/spec/commands/rpush_spec.rb +0 -43
- data/spec/commands/rpushx_spec.rb +0 -46
- data/spec/commands/sadd_spec.rb +0 -45
- data/spec/commands/save_spec.rb +0 -7
- data/spec/commands/scan_each_spec.rb +0 -39
- data/spec/commands/scan_spec.rb +0 -55
- data/spec/commands/scard_spec.rb +0 -18
- data/spec/commands/script_spec.rb +0 -9
- data/spec/commands/sdiff_spec.rb +0 -47
- data/spec/commands/sdiffstore_spec.rb +0 -58
- data/spec/commands/select_spec.rb +0 -61
- data/spec/commands/set_spec.rb +0 -63
- data/spec/commands/setbit_spec.rb +0 -54
- data/spec/commands/setex_spec.rb +0 -22
- data/spec/commands/setnx_spec.rb +0 -25
- data/spec/commands/setrange_spec.rb +0 -30
- data/spec/commands/sinter_spec.rb +0 -39
- data/spec/commands/sinterstore_spec.rb +0 -53
- data/spec/commands/sismember_spec.rb +0 -29
- data/spec/commands/smembers_spec.rb +0 -28
- data/spec/commands/smove_spec.rb +0 -41
- data/spec/commands/sort_list_spec.rb +0 -21
- data/spec/commands/sort_set_spec.rb +0 -21
- data/spec/commands/sort_zset_spec.rb +0 -21
- data/spec/commands/spop_spec.rb +0 -25
- data/spec/commands/srandmember_spec.rb +0 -49
- data/spec/commands/srem_spec.rb +0 -40
- data/spec/commands/sscan_each_spec.rb +0 -48
- data/spec/commands/sscan_spec.rb +0 -39
- data/spec/commands/strlen_spec.rb +0 -18
- data/spec/commands/sunion_spec.rb +0 -42
- data/spec/commands/sunionstore_spec.rb +0 -59
- data/spec/commands/ttl_spec.rb +0 -40
- data/spec/commands/type_spec.rb +0 -36
- data/spec/commands/unwatch_spec.rb +0 -7
- data/spec/commands/watch_spec.rb +0 -16
- data/spec/commands/zadd_spec.rb +0 -123
- data/spec/commands/zcard_spec.rb +0 -19
- data/spec/commands/zcount_spec.rb +0 -39
- data/spec/commands/zincrby_spec.rb +0 -31
- data/spec/commands/zinterstore_spec.rb +0 -96
- data/spec/commands/zrange_spec.rb +0 -80
- data/spec/commands/zrangebyscore_spec.rb +0 -83
- data/spec/commands/zrank_spec.rb +0 -29
- data/spec/commands/zrem_spec.rb +0 -43
- data/spec/commands/zremrangebyrank_spec.rb +0 -27
- data/spec/commands/zremrangebyscore_spec.rb +0 -35
- data/spec/commands/zrevrange_spec.rb +0 -56
- data/spec/commands/zrevrangebyscore_spec.rb +0 -58
- data/spec/commands/zrevrank_spec.rb +0 -29
- data/spec/commands/zscan_each_spec.rb +0 -48
- data/spec/commands/zscan_spec.rb +0 -26
- data/spec/commands/zscore_spec.rb +0 -22
- data/spec/commands/zunionstore_spec.rb +0 -104
- data/spec/mock_redis_spec.rb +0 -86
- data/spec/spec_helper.rb +0 -63
- data/spec/support/redis_multiplexer.rb +0 -106
- data/spec/support/shared_examples/only_operates_on_hashes.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_lists.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_sets.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_strings.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_zsets.rb +0 -57
- data/spec/support/shared_examples/sorts_enumerables.rb +0 -56
- data/spec/transactions_spec.rb +0 -159
data/spec/commands/zadd_spec.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#zadd(key, score, member)' do
|
4
|
-
before { @key = 'mock-redis-test:zadd' }
|
5
|
-
|
6
|
-
it "returns true if member wasn't present in the set" do
|
7
|
-
@redises.zadd(@key, 1, 'foo').should == true
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns false if member was present in the set' do
|
11
|
-
@redises.zadd(@key, 1, 'foo')
|
12
|
-
@redises.zadd(@key, 1, 'foo').should == false
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'adds member to the set' do
|
16
|
-
@redises.zadd(@key, 1, 'foo')
|
17
|
-
@redises.zrange(@key, 0, -1).should == ['foo']
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'treats integer members as strings' do
|
21
|
-
member = 11
|
22
|
-
@redises.zadd(@key, 1, member)
|
23
|
-
@redises.zrange(@key, 0, -1).should == [member.to_s]
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'updates the score' do
|
27
|
-
@redises.zadd(@key, 1, 'foo')
|
28
|
-
@redises.zadd(@key, 2, 'foo')
|
29
|
-
|
30
|
-
@redises.zscore(@key, 'foo').should == 2.0
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'with XX option command do nothing if element not exist' do
|
34
|
-
@redises.zadd(@key, 1, 'foo')
|
35
|
-
@redises.zadd(@key, 2, 'bar', xx: true)
|
36
|
-
@redises.zrange(@key, 0, -1).should_not include 'bar'
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'with XX option command update index on exist element' do
|
40
|
-
@redises.zadd(@key, 1, 'foo')
|
41
|
-
@redises.zadd(@key, 2, 'foo', xx: true)
|
42
|
-
@redises.zscore(@key, 'foo').should == 2.0
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'with XX option and multiple elements command update index on exist element' do
|
46
|
-
@redises.zadd(@key, 1, 'foo')
|
47
|
-
added_count = @redises.zadd(@key, [[2, 'foo'], [2, 'bar']], xx: true)
|
48
|
-
added_count.should == 0
|
49
|
-
|
50
|
-
@redises.zscore(@key, 'foo').should == 2.0
|
51
|
-
@redises.zrange(@key, 0, -1).should_not include 'bar'
|
52
|
-
end
|
53
|
-
|
54
|
-
it "with NX option don't update current element" do
|
55
|
-
@redises.zadd(@key, 1, 'foo')
|
56
|
-
@redises.zadd(@key, 2, 'foo', nx: true)
|
57
|
-
@redises.zscore(@key, 'foo').should == 1.0
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'with NX option create new element' do
|
61
|
-
@redises.zadd(@key, 1, 'foo')
|
62
|
-
@redises.zadd(@key, 2, 'bar', nx: true)
|
63
|
-
@redises.zrange(@key, 0, -1).should include 'bar'
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'with NX option and multiple elements command only create element' do
|
67
|
-
@redises.zadd(@key, 1, 'foo')
|
68
|
-
added_count = @redises.zadd(@key, [[2, 'foo'], [2, 'bar']], nx: true)
|
69
|
-
added_count.should == 1
|
70
|
-
@redises.zscore(@key, 'bar').should == 2.0
|
71
|
-
@redises.zrange(@key, 0, -1).should eq %w[foo bar]
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'XX and NX options in same time raise error' do
|
75
|
-
lambda do
|
76
|
-
@redises.zadd(@key, 1, 'foo', nx: true, xx: true)
|
77
|
-
end.should raise_error(Redis::CommandError)
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'with INCR is act like zincrby' do
|
81
|
-
@redises.zadd(@key, 10, 'bert', incr: true).should == 10.0
|
82
|
-
@redises.zadd(@key, 3, 'bert', incr: true).should == 13.0
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'with INCR and XX not create element' do
|
86
|
-
@redises.zadd(@key, 10, 'bert', xx: true, incr: true).should be_nil
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'with INCR and XX increase score for exist element' do
|
90
|
-
@redises.zadd(@key, 2, 'bert')
|
91
|
-
@redises.zadd(@key, 10, 'bert', xx: true, incr: true).should == 12.0
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'with INCR and NX create element with score' do
|
95
|
-
@redises.zadd(@key, 11, 'bert', nx: true, incr: true).should == 11.0
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'with INCR and NX not update element' do
|
99
|
-
@redises.zadd(@key, 1, 'bert')
|
100
|
-
@redises.zadd(@key, 10, 'bert', nx: true, incr: true).should be_nil
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'with INCR with variable number of arguments raise error' do
|
104
|
-
lambda do
|
105
|
-
@redises.zadd(@key, [[1, 'one'], [2, 'two']], incr: true)
|
106
|
-
end.should raise_error(Redis::CommandError)
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'supports a variable number of arguments' do
|
110
|
-
@redises.zadd(@key, [[1, 'one'], [2, 'two']])
|
111
|
-
@redises.zadd(@key, [[3, 'three']])
|
112
|
-
@redises.zrange(@key, 0, -1).should == %w[one two three]
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'raises an error if an empty array is given' do
|
116
|
-
lambda do
|
117
|
-
@redises.zadd(@key, [])
|
118
|
-
end.should raise_error(Redis::CommandError)
|
119
|
-
end
|
120
|
-
|
121
|
-
it_should_behave_like 'arg 1 is a score'
|
122
|
-
it_should_behave_like 'a zset-only command'
|
123
|
-
end
|
data/spec/commands/zcard_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#zcard(key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:zcard'
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'returns the number of elements in the zset' do
|
9
|
-
@redises.zadd(@key, 1, 'Washington')
|
10
|
-
@redises.zadd(@key, 2, 'Adams')
|
11
|
-
@redises.zcard(@key).should == 2
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns 0 for nonexistent sets' do
|
15
|
-
@redises.zcard(@key).should == 0
|
16
|
-
end
|
17
|
-
|
18
|
-
it_should_behave_like 'a zset-only command'
|
19
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#zcount(key, min, max)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:zcount'
|
6
|
-
@redises.zadd(@key, 1, 'Washington')
|
7
|
-
@redises.zadd(@key, 2, 'Adams')
|
8
|
-
@redises.zadd(@key, 3, 'Jefferson')
|
9
|
-
@redises.zadd(@key, 4, 'Madison')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns the number of members in the zset with scores in (min..max)' do
|
13
|
-
@redises.zcount(@key, 3, 10).should == 2
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'returns 0 if there are no such members' do
|
17
|
-
@redises.zcount(@key, 100, 200).should == 0
|
18
|
-
end
|
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
|
-
|
28
|
-
it 'returns a proper count of elements using exclusive lower bound' do
|
29
|
-
@redises.zcount(@key, '(3', '+inf').should == 1
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns a proper count of elements using exclusive upper bound' do
|
33
|
-
@redises.zcount(@key, '-inf', '(3').should == 2
|
34
|
-
end
|
35
|
-
|
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
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#zincrby(key, increment, member)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:zincrby'
|
6
|
-
@redises.zadd(@key, 1, 'bert')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns the new score as a string' do
|
10
|
-
@redises.zincrby(@key, 10, 'bert').should == 11.0
|
11
|
-
end
|
12
|
-
|
13
|
-
it "updates the item's score" do
|
14
|
-
@redises.zincrby(@key, 10, 'bert')
|
15
|
-
@redises.zscore(@key, 'bert').should == 11.0
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'handles integer members correctly' do
|
19
|
-
member = 11
|
20
|
-
@redises.zadd(@key, 1, member)
|
21
|
-
@redises.zincrby(@key, 1, member)
|
22
|
-
@redises.zscore(@key, member).should == 2.0
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'adds missing members with score increment' do
|
26
|
-
@redises.zincrby(@key, 5.5, 'bigbird').should == 5.5
|
27
|
-
end
|
28
|
-
|
29
|
-
it_should_behave_like 'arg 1 is a score'
|
30
|
-
it_should_behave_like 'a zset-only command'
|
31
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#zinterstore(destination, keys, [:weights => [w,w,], [:aggregate => :sum|:min|:max])' do
|
4
|
-
before do
|
5
|
-
@odds = 'mock-redis-test:zinterstore:odds'
|
6
|
-
@primes = 'mock-redis-test:zinterstore:primes'
|
7
|
-
@dest = 'mock-redis-test:zinterstore:dest'
|
8
|
-
|
9
|
-
@redises.zadd(@odds, 1, 'one')
|
10
|
-
@redises.zadd(@odds, 3, 'three')
|
11
|
-
@redises.zadd(@odds, 5, 'five')
|
12
|
-
@redises.zadd(@odds, 7, 'seven')
|
13
|
-
@redises.zadd(@odds, 9, 'nine')
|
14
|
-
|
15
|
-
@redises.zadd(@primes, 2, 'two')
|
16
|
-
@redises.zadd(@primes, 3, 'three')
|
17
|
-
@redises.zadd(@primes, 5, 'five')
|
18
|
-
@redises.zadd(@primes, 7, 'seven')
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'returns the number of elements in the new set' do
|
22
|
-
@redises.zinterstore(@dest, [@odds, @primes]).should == 3
|
23
|
-
end
|
24
|
-
|
25
|
-
it "sums the members' scores by default" do
|
26
|
-
@redises.zinterstore(@dest, [@odds, @primes])
|
27
|
-
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
28
|
-
[['three', 6.0], ['five', 10.0], ['seven', 14.0]]
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'removes existing elements in destination' do
|
32
|
-
@redises.zadd(@dest, 10, 'ten')
|
33
|
-
|
34
|
-
@redises.zinterstore(@dest, [@primes])
|
35
|
-
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
36
|
-
[['two', 2.0], ['three', 3.0], ['five', 5.0], ['seven', 7.0]]
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'raises an error if keys is empty' do
|
40
|
-
lambda do
|
41
|
-
@redises.zinterstore(@dest, [])
|
42
|
-
end.should raise_error(Redis::CommandError)
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'the :weights argument' do
|
46
|
-
it 'multiplies the scores by the weights while aggregating' do
|
47
|
-
@redises.zinterstore(@dest, [@odds, @primes], :weights => [2, 3])
|
48
|
-
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
49
|
-
[['three', 15.0], ['five', 25.0], ['seven', 35.0]]
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'raises an error if the number of weights != the number of keys' do
|
53
|
-
lambda do
|
54
|
-
@redises.zinterstore(@dest, [@odds, @primes], :weights => [1, 2, 3])
|
55
|
-
end.should raise_error(Redis::CommandError)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'the :aggregate argument' do
|
60
|
-
before do
|
61
|
-
@smalls = 'mock-redis-test:zinterstore:smalls'
|
62
|
-
@bigs = 'mock-redis-test:zinterstore:bigs'
|
63
|
-
|
64
|
-
@redises.zadd(@smalls, 1, 'bert')
|
65
|
-
@redises.zadd(@smalls, 2, 'ernie')
|
66
|
-
@redises.zadd(@bigs, 100, 'bert')
|
67
|
-
@redises.zadd(@bigs, 200, 'ernie')
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'aggregates scores with min when :aggregate => :min is specified' do
|
71
|
-
@redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => :min)
|
72
|
-
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
73
|
-
[['bert', 1.0], ['ernie', 2.0]]
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'aggregates scores with max when :aggregate => :max is specified' do
|
77
|
-
@redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => :max)
|
78
|
-
@redises.zrange(@dest, 0, -1, :with_scores => true).should ==
|
79
|
-
[['bert', 100.0], ['ernie', 200.0]]
|
80
|
-
end
|
81
|
-
|
82
|
-
it "allows 'min', 'MIN', etc. as aliases for :min" do
|
83
|
-
@redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => 'min')
|
84
|
-
@redises.zscore(@dest, 'bert').should == 1.0
|
85
|
-
|
86
|
-
@redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => 'MIN')
|
87
|
-
@redises.zscore(@dest, 'bert').should == 1.0
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'raises an error for unknown aggregation function' do
|
91
|
-
lambda do
|
92
|
-
@redises.zinterstore(@dest, [@bigs, @smalls], :aggregate => :mix)
|
93
|
-
end.should raise_error(Redis::CommandError)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#zrange(key, start, stop [, :with_scores => true])' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:zrange'
|
6
|
-
@redises.zadd(@key, 3, 'Jefferson')
|
7
|
-
@redises.zadd(@key, 1, 'Washington')
|
8
|
-
@redises.zadd(@key, 2, 'Adams')
|
9
|
-
@redises.zadd(@key, 4, 'Madison')
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'when the zset is empty' do
|
13
|
-
before do
|
14
|
-
@redises.del(@key)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should return an empty array' do
|
18
|
-
@redises.exists(@key).should == false
|
19
|
-
@redises.zrange(@key, 0, 4).should == []
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns the elements when the range is given as strings' do
|
24
|
-
@redises.zrange(@key, '0', '1').should == %w[Washington Adams]
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'returns the elements in order by score' do
|
28
|
-
@redises.zrange(@key, 0, 1).should == %w[Washington Adams]
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'when a subset of elements have the same score' do
|
32
|
-
before do
|
33
|
-
@redises.zadd(@key, 1, 'Martha')
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns the elements in ascending lexicographical order' do
|
37
|
-
@redises.zrange(@key, 0, 1).should == %w[Martha Washington]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'returns the elements in order by score (negative indices)' do
|
42
|
-
@redises.zrange(@key, -2, -1).should == %w[Jefferson Madison]
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'returns empty list when start is too large' do
|
46
|
-
@redises.zrange(@key, 5, -1).should == []
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'returns entire list when start is out of bounds with negative end in bounds' do
|
50
|
-
@redises.zrange(@key, -5, -1).should == %w[Washington Adams Jefferson Madison]
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'returns correct subset when start is out of bounds with positive end in bounds' do
|
54
|
-
@redises.zrange(@key, -5, 1).should == %w[Washington Adams]
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'returns empty list when start is in bounds with negative end out of bounds' do
|
58
|
-
@redises.zrange(@key, 1, -5).should == []
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'returns empty list when start is 0 with negative end out of bounds' do
|
62
|
-
@redises.zrange(@key, 0, -5).should == []
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'returns correct subset when start is in bounds with negative end in bounds' do
|
66
|
-
@redises.zrange(@key, 1, -1).should == %w[Adams Jefferson Madison]
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'returns the scores when :with_scores is specified' do
|
70
|
-
@redises.zrange(@key, 0, 1, :with_scores => true).
|
71
|
-
should == [['Washington', 1.0], ['Adams', 2.0]]
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'returns the scores when :withscores is specified' do
|
75
|
-
@redises.zrange(@key, 0, 1, :withscores => true).
|
76
|
-
should == [['Washington', 1.0], ['Adams', 2.0]]
|
77
|
-
end
|
78
|
-
|
79
|
-
it_should_behave_like 'a zset-only command'
|
80
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#zrangebyscore(key, start, stop [:with_scores => true] [:limit => [offset count]])' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:zrangebyscore'
|
6
|
-
@redises.zadd(@key, 1, 'Washington')
|
7
|
-
@redises.zadd(@key, 2, 'Adams')
|
8
|
-
@redises.zadd(@key, 3, 'Jefferson')
|
9
|
-
@redises.zadd(@key, 4, 'Madison')
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'when the zset is empty' do
|
13
|
-
before do
|
14
|
-
@redises.del(@key)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should return an empty array' do
|
18
|
-
@redises.exists(@key).should == false
|
19
|
-
@redises.zrangebyscore(@key, 0, 4).should == []
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns the elements in order by score' do
|
24
|
-
@redises.zrangebyscore(@key, 1, 2).should == %w[Washington Adams]
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'returns the scores when :with_scores is specified' do
|
28
|
-
@redises.zrangebyscore(@key, 1, 2, :with_scores => true).
|
29
|
-
should == [['Washington', 1.0], ['Adams', 2.0]]
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns the scores when :withscores is specified' do
|
33
|
-
@redises.zrangebyscore(@key, 1, 2, :withscores => true).
|
34
|
-
should == [['Washington', 1.0], ['Adams', 2.0]]
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'honors the :limit => [offset count] argument' do
|
38
|
-
@redises.zrangebyscore(@key, -100, 100, :limit => [1, 2]).
|
39
|
-
should == %w[Adams Jefferson]
|
40
|
-
end
|
41
|
-
|
42
|
-
it "raises an error if :limit isn't a 2-tuple" do
|
43
|
-
lambda do
|
44
|
-
@redises.zrangebyscore(@key, -100, 100, :limit => [1, 2, 3])
|
45
|
-
end.should raise_error(Redis::CommandError)
|
46
|
-
|
47
|
-
lambda do
|
48
|
-
@redises.zrangebyscore(@key, -100, 100, :limit => '1, 2')
|
49
|
-
end.should raise_error(RedisMultiplexer::MismatchedResponse)
|
50
|
-
end
|
51
|
-
|
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
|
-
end
|
56
|
-
|
57
|
-
it 'treats -inf as negative infinity' do
|
58
|
-
@redises.zrangebyscore(@key, '-inf', 3).should ==
|
59
|
-
%w[Washington Adams Jefferson]
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'treats +inf as positive infinity' do
|
63
|
-
@redises.zrangebyscore(@key, 3, '+inf').should == %w[Jefferson Madison]
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'treats +inf as positive infinity' do
|
67
|
-
@redises.zrangebyscore(@key, 3, '+inf').should == %w[Jefferson Madison]
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'honors exclusive ranges on the left' do
|
71
|
-
@redises.zrangebyscore(@key, '(3', 4).should == ['Madison']
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'honors exclusive ranges on the right' do
|
75
|
-
@redises.zrangebyscore(@key, '3', '(4').should == ['Jefferson']
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'honors exclusive ranges on the left and the right simultaneously' do
|
79
|
-
@redises.zrangebyscore(@key, '(1', '(4').should == %w[Adams Jefferson]
|
80
|
-
end
|
81
|
-
|
82
|
-
it_should_behave_like 'a zset-only command'
|
83
|
-
end
|
data/spec/commands/zrank_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#zrank(key, member)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:zrank'
|
6
|
-
|
7
|
-
@redises.zadd(@key, 1, 'one')
|
8
|
-
@redises.zadd(@key, 2, 'two')
|
9
|
-
@redises.zadd(@key, 3, 'three')
|
10
|
-
end
|
11
|
-
|
12
|
-
it "returns nil if member wasn't present in the set" do
|
13
|
-
@redises.zrank(@key, 'foo').should be_nil
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'returns the index of the member in the set' do
|
17
|
-
@redises.zrank(@key, 'one').should == 0
|
18
|
-
@redises.zrank(@key, 'two').should == 1
|
19
|
-
@redises.zrank(@key, 'three').should == 2
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'handles integer members correctly' do
|
23
|
-
member = 11
|
24
|
-
@redises.zadd(@key, 4, member)
|
25
|
-
@redises.zrank(@key, member).should == 3
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like 'a zset-only command'
|
29
|
-
end
|
data/spec/commands/zrem_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#zrem(key, member)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:zrem'
|
6
|
-
|
7
|
-
@redises.zadd(@key, 1, 'one')
|
8
|
-
@redises.zadd(@key, 2, 'two')
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'returns true if member is present in the set' do
|
12
|
-
@redises.zrem(@key, 'one').should == true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns false if member is not present in the set' do
|
16
|
-
@redises.zrem(@key, 'nobody home').should == false
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'removes member from the set' do
|
20
|
-
@redises.zrem(@key, 'one')
|
21
|
-
@redises.zrange(@key, 0, -1).should == ['two']
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'removes integer member from the set' do
|
25
|
-
member = 11
|
26
|
-
@redises.zadd(@key, 3, member)
|
27
|
-
@redises.zrem(@key, member).should == true
|
28
|
-
@redises.zrange(@key, 0, -1).should == %w[one two]
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'supports a variable number of arguments' do
|
32
|
-
@redises.zrem(@key, %w[one two])
|
33
|
-
@redises.zrange(@key, 0, -1).should be_empty
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'raises an error if member is an empty array' do
|
37
|
-
lambda do
|
38
|
-
@redises.zrem(@key, [])
|
39
|
-
end.should raise_error(Redis::CommandError)
|
40
|
-
end
|
41
|
-
|
42
|
-
it_should_behave_like 'a zset-only command'
|
43
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#zremrangebyrank(key, start, stop)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:zremrangebyrank'
|
6
|
-
@redises.zadd(@key, 1, 'Washington')
|
7
|
-
@redises.zadd(@key, 2, 'Adams')
|
8
|
-
@redises.zadd(@key, 3, 'Jefferson')
|
9
|
-
@redises.zadd(@key, 4, 'Madison')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns the number of elements in range' do
|
13
|
-
@redises.zremrangebyrank(@key, 2, 3).should == 2
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'removes the elements' do
|
17
|
-
@redises.zremrangebyrank(@key, 2, 3)
|
18
|
-
@redises.zrange(@key, 0, -1).should == %w[Washington Adams]
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'does nothing if start is greater than cardinality of set' do
|
22
|
-
@redises.zremrangebyrank(@key, 5, -1)
|
23
|
-
@redises.zrange(@key, 0, -1).should == %w[Washington Adams Jefferson Madison]
|
24
|
-
end
|
25
|
-
|
26
|
-
it_should_behave_like 'a zset-only command'
|
27
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'date'
|
3
|
-
|
4
|
-
describe '#zremrangebyscore(key, min, max)' do
|
5
|
-
before do
|
6
|
-
@key = 'mock-redis-test:zremrangebyscore'
|
7
|
-
@redises.zadd(@key, 1, 'Washington')
|
8
|
-
@redises.zadd(@key, 2, 'Adams')
|
9
|
-
@redises.zadd(@key, 3, 'Jefferson')
|
10
|
-
@redises.zadd(@key, 4, 'Madison')
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns the number of elements in range' do
|
14
|
-
@redises.zremrangebyscore(@key, 2, 3).should == 2
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'removes the elements' do
|
18
|
-
@redises.zremrangebyscore(@key, 2, 3)
|
19
|
-
@redises.zrange(@key, 0, -1).should == %w[Washington Madison]
|
20
|
-
end
|
21
|
-
|
22
|
-
# As seen in http://redis.io/commands/zremrangebyscore
|
23
|
-
it 'removes the elements for complex statements' do
|
24
|
-
@redises.zremrangebyscore(@key, '-inf', '(4')
|
25
|
-
@redises.zrange(@key, 0, -1).should == %w[Madison]
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like 'a zset-only command'
|
29
|
-
|
30
|
-
it 'throws a command error' do
|
31
|
-
expect do
|
32
|
-
@redises.zrevrangebyscore(@key, DateTime.now, '-inf')
|
33
|
-
end.to raise_error(Redis::CommandError)
|
34
|
-
end
|
35
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#zrevrange(key, start, stop [, :with_scores => true])' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:zrevrange'
|
6
|
-
@redises.zadd(@key, 1, 'Washington')
|
7
|
-
@redises.zadd(@key, 2, 'Adams')
|
8
|
-
@redises.zadd(@key, 3, 'Jefferson')
|
9
|
-
@redises.zadd(@key, 4, 'Madison')
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'when the zset is empty' do
|
13
|
-
before do
|
14
|
-
@redises.del(@key)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should return an empty array' do
|
18
|
-
@redises.exists(@key).should == false
|
19
|
-
@redises.zrevrange(@key, 0, 4).should == []
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns the elements in order by score' do
|
24
|
-
@redises.zrevrange(@key, 0, 1).should == %w[Madison Jefferson]
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when a subset of elements have the same score' do
|
28
|
-
before do
|
29
|
-
@redises.zadd(@key, 1, 'Martha')
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns the elements in descending lexicographical order' do
|
33
|
-
@redises.zrevrange(@key, 3, 4).should == %w[Washington Martha]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'returns the elements in order by score (negative indices)' do
|
38
|
-
@redises.zrevrange(@key, -2, -1).should == %w[Adams Washington]
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'returns empty list when start is too large' do
|
42
|
-
@redises.zrevrange(@key, 5, -1).should == []
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'returns the scores when :with_scores is specified' do
|
46
|
-
@redises.zrevrange(@key, 2, 3, :with_scores => true).
|
47
|
-
should == [['Adams', 2.0], ['Washington', 1.0]]
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'returns the scores when :withscores is specified' do
|
51
|
-
@redises.zrevrange(@key, 2, 3, :withscores => true).
|
52
|
-
should == [['Adams', 2.0], ['Washington', 1.0]]
|
53
|
-
end
|
54
|
-
|
55
|
-
it_should_behave_like 'a zset-only command'
|
56
|
-
end
|