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,114 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
shared_examples 'a distance calculator' do
|
4
|
-
it 'returns distance between two points in specified unit' do
|
5
|
-
dist = @redises.geodist(key, 'SF', 'LA', unit)
|
6
|
-
expect(dist).to be == expected_result
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#geodist' do
|
11
|
-
let(:key) { 'cities' }
|
12
|
-
|
13
|
-
context 'with existing key' do
|
14
|
-
let(:san_francisco) { [-122.5076404, 37.757815, 'SF'] }
|
15
|
-
let(:los_angeles) { [-118.6919259, 34.0207305, 'LA'] }
|
16
|
-
|
17
|
-
before { @redises.geoadd(key, *san_francisco, *los_angeles) }
|
18
|
-
|
19
|
-
after { @redises.zrem(key, %w[SF LA]) }
|
20
|
-
|
21
|
-
context 'with existing points only' do
|
22
|
-
context 'using m as unit' do
|
23
|
-
let(:unit) { 'm' }
|
24
|
-
let(:expected_result) { '539327.9659' }
|
25
|
-
|
26
|
-
it 'returns distance between two points in meters' do
|
27
|
-
dist = @redises.geodist(key, 'SF', 'LA')
|
28
|
-
expect(dist).to be == expected_result
|
29
|
-
end
|
30
|
-
|
31
|
-
it_behaves_like 'a distance calculator'
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'using km as unit' do
|
35
|
-
let(:unit) { 'km' }
|
36
|
-
let(:expected_result) { '539.3280' }
|
37
|
-
|
38
|
-
it_behaves_like 'a distance calculator'
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'using ft as unit' do
|
42
|
-
let(:unit) { 'ft' }
|
43
|
-
let(:expected_result) { '1769448.7069' }
|
44
|
-
|
45
|
-
it_behaves_like 'a distance calculator'
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'using mi as unit' do
|
49
|
-
let(:unit) { 'mi' }
|
50
|
-
let(:expected_result) { '335.1237' }
|
51
|
-
|
52
|
-
it_behaves_like 'a distance calculator'
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'with non-existing points only' do
|
56
|
-
it 'returns nil' do
|
57
|
-
dist = @redises.geodist(key, 'FF', 'FA')
|
58
|
-
expect(dist).to be_nil
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'with both existing and non-existing points' do
|
63
|
-
it 'returns nil' do
|
64
|
-
dist = @redises.geodist(key, 'SF', 'FA')
|
65
|
-
expect(dist).to be_nil
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'with non-existing key' do
|
72
|
-
it 'returns empty string' do
|
73
|
-
dist = @redises.geodist(key, 'SF', 'LA')
|
74
|
-
expect(dist).to be_nil
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'with wrong number of arguments' do
|
79
|
-
let(:list) { [key, 'SF', 'LA', 'm', 'smth'] }
|
80
|
-
|
81
|
-
context 'with less than 3 arguments' do
|
82
|
-
[1, 2].each do |count|
|
83
|
-
let(:message) { "ERR wrong number of arguments for 'geodist' command" }
|
84
|
-
|
85
|
-
context "with #{count} arguments" do
|
86
|
-
it 'raises an error' do
|
87
|
-
args = list.slice(0, count)
|
88
|
-
expect { @redises.geodist(*args) }
|
89
|
-
.to raise_error(Redis::CommandError, message)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'with more than 3 arguments' do
|
96
|
-
let(:message) { 'ERR syntax error' }
|
97
|
-
|
98
|
-
it 'raises an error' do
|
99
|
-
args = list.slice(0, 5)
|
100
|
-
expect { @redises.geodist(*args) }
|
101
|
-
.to raise_error(Redis::CommandError, message)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
context 'with wrong unit' do
|
107
|
-
let(:message) { 'ERR unsupported unit provided. please use m, km, ft, mi' }
|
108
|
-
|
109
|
-
it 'raises an error' do
|
110
|
-
expect { @redises.geodist(key, 'SF', 'LA', 'a') }
|
111
|
-
.to raise_error(Redis::CommandError, message)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#geohash' do
|
4
|
-
let(:key) { 'cities' }
|
5
|
-
|
6
|
-
context 'with existing key' do
|
7
|
-
let(:san_francisco) { [-122.5076404, 37.757815, 'SF'] }
|
8
|
-
let(:los_angeles) { [-118.6919259, 34.0207305, 'LA'] }
|
9
|
-
|
10
|
-
before { @redises.geoadd(key, *san_francisco, *los_angeles) }
|
11
|
-
|
12
|
-
after { @redises.zrem(key, %w[SF LA]) }
|
13
|
-
|
14
|
-
context 'with existing points only' do
|
15
|
-
let(:expected_result) do
|
16
|
-
%w[9q8yu38ejp0 9q59e171je0]
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns decoded coordinates pairs for each point' do
|
20
|
-
results = @redises.geohash(key, 'SF', 'LA')
|
21
|
-
expect(results).to be == expected_result
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with non-existing points only' do
|
25
|
-
it 'returns array filled with nils' do
|
26
|
-
results = @redises.geohash(key, 'FF', 'FA')
|
27
|
-
expect(results).to be == [nil, nil]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with both existing and non-existing points' do
|
32
|
-
let(:expected_result) do
|
33
|
-
['9q8yu38ejp0', nil]
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns mixture of nil and coordinates pair' do
|
37
|
-
results = @redises.geohash(key, 'SF', 'FA')
|
38
|
-
expect(results).to be == expected_result
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'with non-existing key' do
|
45
|
-
before { @redises.del(key) }
|
46
|
-
|
47
|
-
it 'returns empty array' do
|
48
|
-
results = @redises.geohash(key, 'SF', 'LA')
|
49
|
-
expect(results).to be == [nil, nil]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#geopos' do
|
4
|
-
let(:key) { 'cities' }
|
5
|
-
|
6
|
-
context 'with existing key' do
|
7
|
-
let(:san_francisco) { [-122.5076404, 37.757815, 'SF'] }
|
8
|
-
let(:los_angeles) { [-118.6919259, 34.0207305, 'LA'] }
|
9
|
-
|
10
|
-
before { @redises.geoadd(key, *san_francisco, *los_angeles) }
|
11
|
-
|
12
|
-
after { @redises.zrem(key, %w[SF LA]) }
|
13
|
-
|
14
|
-
context 'with existing points only' do
|
15
|
-
let(:expected_result) do
|
16
|
-
[
|
17
|
-
%w[-122.5076410174369812 37.75781598995183685],
|
18
|
-
%w[-118.69192510843276978 34.020729570911179]
|
19
|
-
]
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns decoded coordinates pairs for each point' do
|
23
|
-
coords = @redises.geopos(key, 'SF', 'LA')
|
24
|
-
expect(coords).to be == expected_result
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'with non-existing points only' do
|
28
|
-
it 'returns array filled with nils' do
|
29
|
-
coords = @redises.geopos(key, 'FF', 'FA')
|
30
|
-
expect(coords).to be == [nil, nil]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'with both existing and non-existing points' do
|
35
|
-
let(:expected_result) do
|
36
|
-
[%w[-122.5076410174369812 37.75781598995183685], nil]
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'returns mixture of nil and coordinates pair' do
|
40
|
-
coords = @redises.geopos(key, 'SF', 'FA')
|
41
|
-
expect(coords).to be == expected_result
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'with non-existing key' do
|
48
|
-
before { @redises.del(key) }
|
49
|
-
|
50
|
-
it 'returns empty array' do
|
51
|
-
coords = @redises.geopos(key, 'SF', 'LA')
|
52
|
-
expect(coords).to be == [nil, nil]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/spec/commands/get_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#get(key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:73288'
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'returns nil for a nonexistent value' do
|
9
|
-
@redises.get('mock-redis-test:does-not-exist').should be_nil
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns a stored string value' do
|
13
|
-
@redises.set(@key, 'forsooth')
|
14
|
-
@redises.get(@key).should == 'forsooth'
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'treats integers as strings' do
|
18
|
-
@redises.set(@key, 100)
|
19
|
-
@redises.get(@key).should == '100'
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'stringifies key' do
|
23
|
-
key = :a_symbol
|
24
|
-
|
25
|
-
@redises.set(key, 'hello')
|
26
|
-
@redises.get(key.to_s).should == 'hello'
|
27
|
-
end
|
28
|
-
|
29
|
-
it_should_behave_like 'a string-only command'
|
30
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#getbit(key, offset)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:getbit'
|
6
|
-
@redises.set(@key, 'h') # ASCII 0x68
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'gets the bits from the key' do
|
10
|
-
@redises.getbit(@key, 0).should == 0
|
11
|
-
@redises.getbit(@key, 1).should == 1
|
12
|
-
@redises.getbit(@key, 2).should == 1
|
13
|
-
@redises.getbit(@key, 3).should == 0
|
14
|
-
@redises.getbit(@key, 4).should == 1
|
15
|
-
@redises.getbit(@key, 5).should == 0
|
16
|
-
@redises.getbit(@key, 6).should == 0
|
17
|
-
@redises.getbit(@key, 7).should == 0
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns 0 for out-of-range bits' do
|
21
|
-
@redises.getbit(@key, 100).should == 0
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'does not modify the stored value for out-of-range bits' do
|
25
|
-
@redises.getbit(@key, 100)
|
26
|
-
@redises.get(@key).should == 'h'
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'treats nonexistent keys as empty strings' do
|
30
|
-
@redises.getbit('mock-redis-test:not-found', 0).should == 0
|
31
|
-
end
|
32
|
-
|
33
|
-
it_should_behave_like 'a string-only command'
|
34
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#getrange(key, start, stop)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:getrange'
|
6
|
-
@redises.set(@key, 'This is a string')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns a substring' do
|
10
|
-
@redises.getrange(@key, 0, 3).should == 'This'
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'works with negative indices' do
|
14
|
-
@redises.getrange(@key, -3, -1).should == 'ing'
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'limits the result to the actual length of the string' do
|
18
|
-
@redises.getrange(@key, 10, 100).should == 'string'
|
19
|
-
end
|
20
|
-
|
21
|
-
it_should_behave_like 'a string-only command'
|
22
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#getrange(key, value)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:getset'
|
6
|
-
@redises.set(@key, 'oldvalue')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns the old value' do
|
10
|
-
@redises.getset(@key, 'newvalue').should == 'oldvalue'
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'sets the value to the new value' do
|
14
|
-
@redises.getset(@key, 'newvalue')
|
15
|
-
@redises.get(@key).should == 'newvalue'
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'returns nil for nonexistent keys' do
|
19
|
-
@redises.getset('mock-redis-test:not-found', 1).should be_nil
|
20
|
-
end
|
21
|
-
|
22
|
-
it_should_behave_like 'a string-only command'
|
23
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#[](key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hash_operator'
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'returns nil for a nonexistent value' do
|
9
|
-
@redises['mock-redis-test:does-not-exist'].should be_nil
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns a stored string value' do
|
13
|
-
@redises[@key] = 'forsooth'
|
14
|
-
@redises[@key].should == 'forsooth'
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'treats integers as strings' do
|
18
|
-
@redises[@key] = 100
|
19
|
-
@redises[@key].should == '100'
|
20
|
-
end
|
21
|
-
end
|
data/spec/commands/hdel_spec.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hdel(key, field)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hdel'
|
6
|
-
@redises.hset(@key, 'k1', 'v1')
|
7
|
-
@redises.hset(@key, 'k2', 'v2')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns 1 when it removes a field' do
|
11
|
-
@redises.hdel(@key, 'k1').should == 1
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns 0 when it does not remove a field' do
|
15
|
-
@redises.hdel(@key, 'nonesuch').should == 0
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'actually removes the field' do
|
19
|
-
@redises.hdel(@key, 'k1')
|
20
|
-
@redises.hget(@key, 'k1').should be_nil
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'treats the field as a string' do
|
24
|
-
field = 2
|
25
|
-
@redises.hset(@key, field, 'two')
|
26
|
-
@redises.hdel(@key, field)
|
27
|
-
@redises.hget(@key, field).should be_nil
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'removes only the field specified' do
|
31
|
-
@redises.hdel(@key, 'k1')
|
32
|
-
@redises.hget(@key, 'k2').should == 'v2'
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'cleans up empty hashes' do
|
36
|
-
@redises.hdel(@key, 'k1')
|
37
|
-
@redises.hdel(@key, 'k2')
|
38
|
-
@redises.get(@key).should be_nil
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'supports a variable number of arguments' do
|
42
|
-
@redises.hdel(@key, %w[k1 k2])
|
43
|
-
@redises.get(@key).should be_nil
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'treats variable arguments as strings' do
|
47
|
-
field = 2
|
48
|
-
@redises.hset(@key, field, 'two')
|
49
|
-
@redises.hdel(@key, [field])
|
50
|
-
@redises.hget(@key, field).should be_nil
|
51
|
-
end
|
52
|
-
|
53
|
-
it_should_behave_like 'a hash-only command'
|
54
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hexists(key, field)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hexists'
|
6
|
-
@redises.hset(@key, 'field', 'value')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns true if the hash has that field' do
|
10
|
-
@redises.hexists(@key, 'field').should == true
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns false if the hash lacks that field' do
|
14
|
-
@redises.hexists(@key, 'nonesuch').should == false
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'treats the field as a string' do
|
18
|
-
@redises.hset(@key, 1, 'one')
|
19
|
-
@redises.hexists(@key, 1).should == true
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns nil when there is no such key' do
|
23
|
-
@redises.hexists('mock-redis-test:nonesuch', 'key').should == false
|
24
|
-
end
|
25
|
-
|
26
|
-
it_should_behave_like 'a hash-only command'
|
27
|
-
end
|
data/spec/commands/hget_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hget(key, field)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hget'
|
6
|
-
@redises.hset(@key, 'k1', 'v1')
|
7
|
-
@redises.hset(@key, 'k2', 'v2')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns the value stored at field' do
|
11
|
-
@redises.hget(@key, 'k1').should == 'v1'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'treats the field as a string' do
|
15
|
-
@redises.hset(@key, '3', 'v3')
|
16
|
-
@redises.hget(@key, 3).should == 'v3'
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns nil when there is no such field' do
|
20
|
-
@redises.hget(@key, 'nonesuch').should be_nil
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns nil when there is no such key' do
|
24
|
-
@redises.hget('mock-redis-test:nonesuch', 'k1').should be_nil
|
25
|
-
end
|
26
|
-
|
27
|
-
it_should_behave_like 'a hash-only command'
|
28
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hgetall(key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hgetall'
|
6
|
-
@redises.hset(@key, 'k1', 'v1')
|
7
|
-
@redises.hset(@key, 'k2', 'v2')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns the (key, value) pairs stored in the hash' do
|
11
|
-
@redises.hgetall(@key).should == {
|
12
|
-
'k1' => 'v1',
|
13
|
-
'k2' => 'v2',
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'returns [] when there is no such key' do
|
18
|
-
@redises.hgetall('mock-redis-test:nonesuch').should == {}
|
19
|
-
end
|
20
|
-
|
21
|
-
it "doesn't return a mutable reference to the returned data" do
|
22
|
-
mr = MockRedis.new
|
23
|
-
mr.hset(@key, 'k1', 'v1')
|
24
|
-
mr.hset(@key, 'k2', 'v2')
|
25
|
-
hash = mr.hgetall(@key)
|
26
|
-
hash['dont'] = 'mutate'
|
27
|
-
new_hash = mr.hgetall(@key)
|
28
|
-
new_hash.keys.sort.should == %w[k1 k2]
|
29
|
-
end
|
30
|
-
|
31
|
-
it_should_behave_like 'a hash-only command'
|
32
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hincrby(key, field, increment)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hincrby'
|
6
|
-
@field = 'count'
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns the value after the increment' do
|
10
|
-
@redises.hset(@key, @field, 2)
|
11
|
-
@redises.hincrby(@key, @field, 2).should == 4
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'treats a missing key like 0' do
|
15
|
-
@redises.hincrby(@key, @field, 1).should == 1
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'creates a hash if nothing is present' do
|
19
|
-
@redises.hincrby(@key, @field, 1)
|
20
|
-
@redises.hget(@key, @field).should == '1'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'increments negative numbers' do
|
24
|
-
@redises.hset(@key, @field, -10)
|
25
|
-
@redises.hincrby(@key, @field, 2).should == -8
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'works multiple times' do
|
29
|
-
@redises.hincrby(@key, @field, 2).should == 2
|
30
|
-
@redises.hincrby(@key, @field, 2).should == 4
|
31
|
-
@redises.hincrby(@key, @field, 2).should == 6
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'accepts an integer-ish string' do
|
35
|
-
@redises.hincrby(@key, @field, '2').should == 2
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'treats the field as a string' do
|
39
|
-
field = 11
|
40
|
-
@redises.hset(@key, field, 2)
|
41
|
-
@redises.hincrby(@key, field, 2).should == 4
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'raises an error if the value does not look like an integer' do
|
45
|
-
@redises.hset(@key, @field, 'one')
|
46
|
-
lambda do
|
47
|
-
@redises.hincrby(@key, @field, 1)
|
48
|
-
end.should raise_error(Redis::CommandError)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'raises an error if the delta does not look like an integer' do
|
52
|
-
lambda do
|
53
|
-
@redises.hincrby(@key, @field, 'foo')
|
54
|
-
end.should raise_error(Redis::CommandError)
|
55
|
-
end
|
56
|
-
|
57
|
-
it_should_behave_like 'a hash-only command'
|
58
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hincrbyfloat(key, field, increment)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hincrbyfloat'
|
6
|
-
@field = 'count'
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns the value after the increment' do
|
10
|
-
@redises.hset(@key, @field, 2.0)
|
11
|
-
@redises.hincrbyfloat(@key, @field, 2.1).should be_within(0.0001).of(4.1)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'treats a missing key like 0' do
|
15
|
-
@redises.hincrbyfloat(@key, @field, 1.2).should be_within(0.0001).of(1.2)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'creates a hash if nothing is present' do
|
19
|
-
@redises.hincrbyfloat(@key, @field, 1.0)
|
20
|
-
@redises.hget(@key, @field).should == '1'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'increments negative numbers' do
|
24
|
-
@redises.hset(@key, @field, -10.4)
|
25
|
-
@redises.hincrbyfloat(@key, @field, 2.3).should be_within(0.0001).of(-8.1)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'works multiple times' do
|
29
|
-
@redises.hincrbyfloat(@key, @field, 2.1).should be_within(0.0001).of(2.1)
|
30
|
-
@redises.hincrbyfloat(@key, @field, 2.2).should be_within(0.0001).of(4.3)
|
31
|
-
@redises.hincrbyfloat(@key, @field, 2.3).should be_within(0.0001).of(6.6)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'accepts a float-ish string' do
|
35
|
-
@redises.hincrbyfloat(@key, @field, '2.2').should be_within(0.0001).of(2.2)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'treats the field as a string' do
|
39
|
-
field = 11
|
40
|
-
@redises.hset(@key, field, 2)
|
41
|
-
@redises.hincrbyfloat(@key, field, 2).should == 4.0
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'raises an error if the value does not look like a float' do
|
45
|
-
@redises.hset(@key, @field, 'one.two')
|
46
|
-
lambda do
|
47
|
-
@redises.hincrbyfloat(@key, @field, 1)
|
48
|
-
end.should raise_error(Redis::CommandError)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'raises an error if the delta does not look like a float' do
|
52
|
-
lambda do
|
53
|
-
@redises.hincrbyfloat(@key, @field, 'foobar.baz')
|
54
|
-
end.should raise_error(Redis::CommandError)
|
55
|
-
end
|
56
|
-
|
57
|
-
it_should_behave_like 'a hash-only command'
|
58
|
-
end
|
data/spec/commands/hkeys_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hkeys(key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hkeys'
|
6
|
-
@redises.hset(@key, 'k1', 'v1')
|
7
|
-
@redises.hset(@key, 'k2', 'v2')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns the keys stored in the hash' do
|
11
|
-
@redises.hkeys(@key).sort.should == %w[k1 k2]
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns [] when there is no such key' do
|
15
|
-
@redises.hkeys('mock-redis-test:nonesuch').should == []
|
16
|
-
end
|
17
|
-
|
18
|
-
it_should_behave_like 'a hash-only command'
|
19
|
-
end
|
data/spec/commands/hlen_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hlen(key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hlen'
|
6
|
-
@redises.hset(@key, 'k1', 'v1')
|
7
|
-
@redises.hset(@key, 'k2', 'v2')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns the number of keys stored in the hash' do
|
11
|
-
@redises.hlen(@key).should == 2
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns [] when there is no such key' do
|
15
|
-
@redises.hlen('mock-redis-test:nonesuch').should == 0
|
16
|
-
end
|
17
|
-
|
18
|
-
it_should_behave_like 'a hash-only command'
|
19
|
-
end
|