mock_redis 0.19.0 → 0.44.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#linsert(key, :before|:after, pivot, value)' do
|
4
|
-
before { @key = 'mock-redis-test:48733' }
|
5
|
-
|
6
|
-
it 'returns the new size of the list when the pivot is found' do
|
7
|
-
@redises.lpush(@key, 'X')
|
8
|
-
|
9
|
-
@redises.linsert(@key, :before, 'X', 'Y').should == 2
|
10
|
-
@redises.lpushx(@key, 'X').should == 3
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'does nothing when run against a nonexistent key' do
|
14
|
-
@redises.linsert(@key, :before, 1, 2).should == 0
|
15
|
-
@redises.get(@key).should be_nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'returns -1 if the pivot is not found' do
|
19
|
-
@redises.lpush(@key, 1)
|
20
|
-
@redises.linsert(@key, :after, 'X', 'Y').should == -1
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'inserts elements before the pivot when given :before as position' do
|
24
|
-
@redises.lpush(@key, 'bert')
|
25
|
-
@redises.linsert(@key, :before, 'bert', 'ernie')
|
26
|
-
|
27
|
-
@redises.lindex(@key, 0).should == 'ernie'
|
28
|
-
@redises.lindex(@key, 1).should == 'bert'
|
29
|
-
end
|
30
|
-
|
31
|
-
it "inserts elements before the pivot when given 'before' as position" do
|
32
|
-
@redises.lpush(@key, 'bert')
|
33
|
-
@redises.linsert(@key, 'before', 'bert', 'ernie')
|
34
|
-
|
35
|
-
@redises.lindex(@key, 0).should == 'ernie'
|
36
|
-
@redises.lindex(@key, 1).should == 'bert'
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'inserts elements after the pivot when given :after as position' do
|
40
|
-
@redises.lpush(@key, 'bert')
|
41
|
-
@redises.linsert(@key, :after, 'bert', 'ernie')
|
42
|
-
|
43
|
-
@redises.lindex(@key, 0).should == 'bert'
|
44
|
-
@redises.lindex(@key, 1).should == 'ernie'
|
45
|
-
end
|
46
|
-
|
47
|
-
it "inserts elements after the pivot when given 'after' as position" do
|
48
|
-
@redises.lpush(@key, 'bert')
|
49
|
-
@redises.linsert(@key, 'after', 'bert', 'ernie')
|
50
|
-
|
51
|
-
@redises.lindex(@key, 0).should == 'bert'
|
52
|
-
@redises.lindex(@key, 1).should == 'ernie'
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'raises an error when given a position that is neither before nor after' do
|
56
|
-
lambda do
|
57
|
-
@redises.linsert(@key, :near, 1, 2)
|
58
|
-
end.should raise_error(Redis::CommandError)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'stores values as strings' do
|
62
|
-
@redises.lpush(@key, 1)
|
63
|
-
@redises.linsert(@key, :before, 1, 2)
|
64
|
-
@redises.lindex(@key, 0).should == '2'
|
65
|
-
end
|
66
|
-
|
67
|
-
it_should_behave_like 'a list-only command'
|
68
|
-
end
|
data/spec/commands/llen_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#llen(key)' do
|
4
|
-
before { @key = 'mock-redis-test:78407' }
|
5
|
-
|
6
|
-
it 'returns 0 for a nonexistent key' do
|
7
|
-
@redises.llen(@key).should == 0
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns the length of the list' do
|
11
|
-
5.times { @redises.lpush(@key, 'X') }
|
12
|
-
@redises.llen(@key).should == 5
|
13
|
-
end
|
14
|
-
|
15
|
-
it_should_behave_like 'a list-only command'
|
16
|
-
end
|
data/spec/commands/lpop_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#lpop(key)' do
|
4
|
-
before { @key = 'mock-redis-test:65374' }
|
5
|
-
|
6
|
-
it 'returns and removes the first element of a list' do
|
7
|
-
@redises.lpush(@key, 1)
|
8
|
-
@redises.lpush(@key, 2)
|
9
|
-
|
10
|
-
@redises.lpop(@key).should == '2'
|
11
|
-
|
12
|
-
@redises.llen(@key).should == 1
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns nil if the list is empty' do
|
16
|
-
@redises.lpush(@key, 'foo')
|
17
|
-
@redises.lpop(@key)
|
18
|
-
|
19
|
-
@redises.lpop(@key).should be_nil
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns nil for nonexistent values' do
|
23
|
-
@redises.lpop(@key).should be_nil
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'removes empty lists' do
|
27
|
-
@redises.lpush(@key, 'foo')
|
28
|
-
@redises.lpop(@key)
|
29
|
-
|
30
|
-
@redises.get(@key).should be_nil
|
31
|
-
end
|
32
|
-
|
33
|
-
it_should_behave_like 'a list-only command'
|
34
|
-
end
|
data/spec/commands/lpush_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#lpush(key, value)' do
|
4
|
-
before { @key = 'mock-redis-test:57367' }
|
5
|
-
|
6
|
-
it 'returns the new size of the list' do
|
7
|
-
@redises.lpush(@key, 'X').should == 1
|
8
|
-
@redises.lpush(@key, 'X').should == 2
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'creates a new list when run against a nonexistent key' do
|
12
|
-
@redises.lpush(@key, 'value')
|
13
|
-
@redises.llen(@key).should == 1
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'prepends items to the list' do
|
17
|
-
@redises.lpush(@key, 'bert')
|
18
|
-
@redises.lpush(@key, 'ernie')
|
19
|
-
|
20
|
-
@redises.lindex(@key, 0).should == 'ernie'
|
21
|
-
@redises.lindex(@key, 1).should == 'bert'
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'stores values as strings' do
|
25
|
-
@redises.lpush(@key, 1)
|
26
|
-
@redises.lindex(@key, 0).should == '1'
|
27
|
-
end
|
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
|
-
|
36
|
-
it 'raises an error if an empty array is given' do
|
37
|
-
lambda do
|
38
|
-
@redises.lpush(@key, [])
|
39
|
-
end.should raise_error(Redis::CommandError)
|
40
|
-
end
|
41
|
-
|
42
|
-
it_should_behave_like 'a list-only command'
|
43
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#lpushx(key, value)' do
|
4
|
-
before { @key = 'mock-redis-test:81267' }
|
5
|
-
|
6
|
-
it 'returns the new size of the list' do
|
7
|
-
@redises.lpush(@key, 'X')
|
8
|
-
|
9
|
-
@redises.lpushx(@key, 'X').should == 2
|
10
|
-
@redises.lpushx(@key, 'X').should == 3
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'does nothing when run against a nonexistent key' do
|
14
|
-
@redises.lpushx(@key, 'value')
|
15
|
-
@redises.get(@key).should be_nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'prepends items to the list' do
|
19
|
-
@redises.lpush(@key, 'bert')
|
20
|
-
@redises.lpushx(@key, 'ernie')
|
21
|
-
|
22
|
-
@redises.lindex(@key, 0).should == 'ernie'
|
23
|
-
@redises.lindex(@key, 1).should == 'bert'
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'stores values as strings' do
|
27
|
-
@redises.lpush(@key, 1)
|
28
|
-
@redises.lpushx(@key, 2)
|
29
|
-
@redises.lindex(@key, 0).should == '2'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'raises an error if an empty array is given' do
|
33
|
-
@redises.lpush(@key, 'X')
|
34
|
-
lambda do
|
35
|
-
@redises.lpushx(@key, [])
|
36
|
-
end.should raise_error(Redis::CommandError)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'stores multiple items if an array of more than one item is given' do
|
40
|
-
@redises.lpush(@key, 'X')
|
41
|
-
@redises.lpushx(@key, [1, 2]).should == 3
|
42
|
-
@redises.lrange(@key, 0, -1).should == %w[2 1 X]
|
43
|
-
end
|
44
|
-
|
45
|
-
it_should_behave_like 'a list-only command'
|
46
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#lrange(key, start, stop)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:68036'
|
6
|
-
|
7
|
-
@redises.lpush(@key, 'v4')
|
8
|
-
@redises.lpush(@key, 'v3')
|
9
|
-
@redises.lpush(@key, 'v2')
|
10
|
-
@redises.lpush(@key, 'v1')
|
11
|
-
@redises.lpush(@key, 'v0')
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns a subset of the list inclusive of the right end' do
|
15
|
-
@redises.lrange(@key, 0, 2).should == %w[v0 v1 v2]
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'returns a subset of the list when start and end are strings' do
|
19
|
-
@redises.lrange(@key, '0', '2').should == %w[v0 v1 v2]
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns an empty list when start > end' do
|
23
|
-
@redises.lrange(@key, 3, 2).should == []
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'works with a negative stop index' do
|
27
|
-
@redises.lrange(@key, 2, -1).should == %w[v2 v3 v4]
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'works with negative start and stop indices' do
|
31
|
-
@redises.lrange(@key, -2, -1).should == %w[v3 v4]
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'works with negative start indices less than list length' do
|
35
|
-
@redises.lrange(@key, -10, -2).should == %w[v0 v1 v2 v3]
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'returns [] when run against a nonexistent value' do
|
39
|
-
@redises.lrange('mock-redis-test:bogus-key', 0, 1).should == []
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'returns [] when start is too large' do
|
43
|
-
@redises.lrange(@key, 100, 100).should == []
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'finds the end of the list correctly when end is too large' do
|
47
|
-
@redises.lrange(@key, 4, 10).should == %w[v4]
|
48
|
-
end
|
49
|
-
|
50
|
-
it_should_behave_like 'a list-only command'
|
51
|
-
end
|
data/spec/commands/lrem_spec.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#lrem(key, count, value)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:66767'
|
6
|
-
|
7
|
-
%w[99 bottles of beer on the wall
|
8
|
-
99 bottles of beer
|
9
|
-
take one down
|
10
|
-
pass it around
|
11
|
-
98 bottles of beer on the wall].reverse_each do |x|
|
12
|
-
@redises.lpush(@key, x)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'deletes the first count instances of key when count > 0' do
|
17
|
-
@redises.lrem(@key, 2, 'bottles')
|
18
|
-
|
19
|
-
@redises.lrange(@key, 0, 8).should == %w[
|
20
|
-
99 of beer on the wall
|
21
|
-
99 of beer
|
22
|
-
]
|
23
|
-
|
24
|
-
@redises.lrange(@key, -7, -1).should == %w[98 bottles of beer on the wall]
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'deletes the last count instances of key when count < 0' do
|
28
|
-
@redises.lrem(@key, -2, 'bottles')
|
29
|
-
|
30
|
-
@redises.lrange(@key, 0, 9).should == %w[
|
31
|
-
99 bottles of beer on the wall
|
32
|
-
99 of beer
|
33
|
-
]
|
34
|
-
|
35
|
-
@redises.lrange(@key, -6, -1).should == %w[98 of beer on the wall]
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'deletes all instances of key when count == 0' do
|
39
|
-
@redises.lrem(@key, 0, 'bottles')
|
40
|
-
@redises.lrange(@key, 0, -1).grep(/bottles/).should be_empty
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'returns the number of elements deleted' do
|
44
|
-
@redises.lrem(@key, 2, 'bottles').should == 2
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'returns the number of elements deleted even if you ask for more' do
|
48
|
-
@redises.lrem(@key, 10, 'bottles').should == 3
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'stringifies value' do
|
52
|
-
@redises.lrem(@key, 0, 99).should == 2
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'returns 0 when run against a nonexistent value' do
|
56
|
-
@redises.lrem('mock-redis-test:bogus-key', 0, 1).should == 0
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'returns 0 when run against an empty list' do
|
60
|
-
@redises.llen(@key).times { @redises.lpop(@key) } # empty the list
|
61
|
-
@redises.lrem(@key, 0, 'beer').should == 0
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'raises an error if the value does not look like an integer' do
|
65
|
-
lambda do
|
66
|
-
@redises.lrem(@key, 'foo', 'bottles')
|
67
|
-
end.should raise_error(Redis::CommandError)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'removes empty lists' do
|
71
|
-
other_key = "mock-redis-test:lrem-#{__LINE__}"
|
72
|
-
|
73
|
-
@redises.lpush(other_key, 'foo')
|
74
|
-
@redises.lrem(other_key, 0, 'foo')
|
75
|
-
|
76
|
-
@redises.get(other_key).should be_nil
|
77
|
-
end
|
78
|
-
|
79
|
-
it_should_behave_like 'a list-only command'
|
80
|
-
end
|
data/spec/commands/lset_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#lset(key, index, value)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:21522'
|
6
|
-
|
7
|
-
@redises.lpush(@key, 'v1')
|
8
|
-
@redises.lpush(@key, 'v0')
|
9
|
-
end
|
10
|
-
|
11
|
-
it "returns 'OK'" do
|
12
|
-
@redises.lset(@key, 0, 'newthing').should == 'OK'
|
13
|
-
end
|
14
|
-
|
15
|
-
it "sets the list's value at index to value" do
|
16
|
-
@redises.lset(@key, 0, 'newthing')
|
17
|
-
@redises.lindex(@key, 0).should == 'newthing'
|
18
|
-
end
|
19
|
-
|
20
|
-
it "sets the list's value at index to value when the index is a string" do
|
21
|
-
@redises.lset(@key, '0', 'newthing')
|
22
|
-
@redises.lindex(@key, 0).should == 'newthing'
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'stringifies value' do
|
26
|
-
@redises.lset(@key, 0, 12_345)
|
27
|
-
@redises.lindex(@key, 0).should == '12345'
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'raises an exception for nonexistent keys' do
|
31
|
-
lambda do
|
32
|
-
@redises.lset('mock-redis-test:bogus-key', 100, 'value')
|
33
|
-
end.should raise_error(Redis::CommandError)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'raises an exception for out-of-range indices' do
|
37
|
-
lambda do
|
38
|
-
@redises.lset(@key, 100, 'value')
|
39
|
-
end.should raise_error(Redis::CommandError)
|
40
|
-
end
|
41
|
-
|
42
|
-
it_should_behave_like 'a list-only command'
|
43
|
-
end
|
data/spec/commands/ltrim_spec.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#ltrim(key, start, stop)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:22310'
|
6
|
-
|
7
|
-
%w[v0 v1 v2 v3 v4].reverse_each { |v| @redises.lpush(@key, v) }
|
8
|
-
end
|
9
|
-
|
10
|
-
it "returns 'OK'" do
|
11
|
-
@redises.ltrim(@key, 1, 3).should == 'OK'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'trims the list to include only the specified elements' do
|
15
|
-
@redises.ltrim(@key, 1, 3)
|
16
|
-
@redises.lrange(@key, 0, -1).should == %w[v1 v2 v3]
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'trims the list when start and stop are strings' do
|
20
|
-
@redises.ltrim(@key, '1', '3')
|
21
|
-
@redises.lrange(@key, 0, -1).should == %w[v1 v2 v3]
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'trims the list to include only the specified elements (negative indices)' do
|
25
|
-
@redises.ltrim(@key, -2, -1)
|
26
|
-
@redises.lrange(@key, 0, -1).should == %w[v3 v4]
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'trims the list to include only the specified elements (out of range negative indices)' do
|
30
|
-
@redises.ltrim(@key, -10, -2)
|
31
|
-
@redises.lrange(@key, 0, -1).should == %w[v0 v1 v2 v3]
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'does not crash on overly-large indices' do
|
35
|
-
@redises.ltrim(@key, 100, 200)
|
36
|
-
@redises.lrange(@key, 0, -1).should == %w[]
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'removes empty lists' do
|
40
|
-
@redises.ltrim(@key, 1, 0)
|
41
|
-
@redises.get(@key).should be_nil
|
42
|
-
end
|
43
|
-
|
44
|
-
it_should_behave_like 'a list-only command'
|
45
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mapped_hmget(key, *fields)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:mapped_hmget'
|
6
|
-
@redises.hmset(@key, 'k1', 'v1', 'k2', 'v2')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns values stored at key' do
|
10
|
-
@redises.mapped_hmget(@key, 'k1', 'k2').should == { 'k1' => 'v1', 'k2' => 'v2' }
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns nils for missing fields' do
|
14
|
-
@redises.mapped_hmget(@key, 'k1', 'mock-redis-test:nonesuch').
|
15
|
-
should == { 'k1' => 'v1', 'mock-redis-test:nonesuch' => nil }
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'treats an array as the first key' do
|
19
|
-
@redises.mapped_hmget(@key, %w[k1 k2]).should == { %w[k1 k2] => 'v1' }
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'raises an error if given no fields' do
|
23
|
-
lambda do
|
24
|
-
@redises.mapped_hmget(@key)
|
25
|
-
end.should raise_error(Redis::CommandError)
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like 'a hash-only command'
|
29
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mapped_hmset(key, hash={})' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:mapped_hmset'
|
6
|
-
end
|
7
|
-
|
8
|
-
it "returns 'OK'" do
|
9
|
-
@redises.mapped_hmset(@key, 'k1' => 'v1', 'k2' => 'v2').should == 'OK'
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'sets the values' do
|
13
|
-
@redises.mapped_hmset(@key, 'k1' => 'v1', 'k2' => 'v2')
|
14
|
-
@redises.hmget(@key, 'k1', 'k2').should == %w[v1 v2]
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'updates an existing hash' do
|
18
|
-
@redises.hmset(@key, 'foo', 'bar')
|
19
|
-
@redises.mapped_hmset(@key, 'bert' => 'ernie', 'diet' => 'coke')
|
20
|
-
|
21
|
-
@redises.hmget(@key, 'foo', 'bert', 'diet').
|
22
|
-
should == %w[bar ernie coke]
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'stores the values as strings' do
|
26
|
-
@redises.mapped_hmset(@key, 'one' => 1)
|
27
|
-
@redises.hget(@key, 'one').should == '1'
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'raises an error if given no hash' do
|
31
|
-
lambda do
|
32
|
-
@redises.mapped_hmset(@key)
|
33
|
-
end.should raise_error(ArgumentError)
|
34
|
-
end
|
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
|
-
|
42
|
-
it 'raises an error if given a non-hash value' do
|
43
|
-
lambda do
|
44
|
-
@redises.mapped_hmset(@key, 1)
|
45
|
-
end.should raise_error(NoMethodError)
|
46
|
-
end
|
47
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mapped_mget(*keys)' do
|
4
|
-
before do
|
5
|
-
@key1 = 'mock-redis-test:a'
|
6
|
-
@key2 = 'mock-redis-test:b'
|
7
|
-
@key3 = 'mock-redis-test:c'
|
8
|
-
|
9
|
-
@redises.set(@key1, '1')
|
10
|
-
@redises.set(@key2, '2')
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns a hash' do
|
14
|
-
@redises.mapped_mget(@key1, @key2, @key3).should eq(@key1 => '1',
|
15
|
-
@key2 => '2',
|
16
|
-
@key3 => nil)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns a hash even when no matches' do
|
20
|
-
@redises.mapped_mget('qwer').should eq('qwer' => nil)
|
21
|
-
end
|
22
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mapped_mset(hash)' do
|
4
|
-
before do
|
5
|
-
@key1 = 'mock-redis-test:a'
|
6
|
-
@key2 = 'mock-redis-test:b'
|
7
|
-
@key3 = 'mock-redis-test:c'
|
8
|
-
|
9
|
-
@redises.set(@key1, '1')
|
10
|
-
@redises.set(@key2, '2')
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'sets the values properly' do
|
14
|
-
@redises.mapped_mset(@key1 => 'one', @key3 => 'three').should eq('OK')
|
15
|
-
@redises.get(@key1).should eq('one')
|
16
|
-
@redises.get(@key2).should eq('2') # left alone
|
17
|
-
@redises.get(@key3).should eq('three')
|
18
|
-
end
|
19
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mapped_msetnx(hash)' do
|
4
|
-
before do
|
5
|
-
@key1 = 'mock-redis-test:a'
|
6
|
-
@key2 = 'mock-redis-test:b'
|
7
|
-
@key3 = 'mock-redis-test:c'
|
8
|
-
|
9
|
-
@redises.set(@key1, '1')
|
10
|
-
@redises.set(@key2, '2')
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'sets properly when none collide' do
|
14
|
-
@redises.mapped_msetnx(@key3 => 'three').should eq(true)
|
15
|
-
@redises.get(@key1).should eq('1') # existed; untouched
|
16
|
-
@redises.get(@key2).should eq('2') # existed; untouched
|
17
|
-
@redises.get(@key3).should eq('three')
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'does not set any when any collide' do
|
21
|
-
@redises.mapped_msetnx(@key1 => 'one', @key3 => 'three').should eq(false)
|
22
|
-
@redises.get(@key1).should eq('1') # existed; untouched
|
23
|
-
@redises.get(@key2).should eq('2') # existed; untouched
|
24
|
-
@redises.get(@key3).should be_nil
|
25
|
-
end
|
26
|
-
end
|
data/spec/commands/mget_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mget(key [, key, ...])' do
|
4
|
-
before do
|
5
|
-
@key1 = 'mock-redis-test:mget1'
|
6
|
-
@key2 = 'mock-redis-test:mget2'
|
7
|
-
|
8
|
-
@redises.set(@key1, 1)
|
9
|
-
@redises.set(@key2, 2)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns an array of values' do
|
13
|
-
@redises.mget(@key1, @key2).should == %w[1 2]
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'returns nil for missing keys' do
|
17
|
-
@redises.mget(@key1, 'mock-redis-test:not-found', @key2).
|
18
|
-
should == ['1', nil, '2']
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'returns nil for non-string keys' do
|
22
|
-
list = 'mock-redis-test:mget-list'
|
23
|
-
|
24
|
-
@redises.lpush(list, 'bork bork bork')
|
25
|
-
|
26
|
-
@redises.mget(@key1, @key2, list).should == ['1', '2', nil]
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'raises an error if you pass it 0 arguments' do
|
30
|
-
lambda do
|
31
|
-
@redises.mget
|
32
|
-
end.should raise_error(Redis::CommandError)
|
33
|
-
end
|
34
|
-
end
|