mock_redis 0.5.4 → 0.31.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/lint.yml +31 -0
- data/.github/workflows/tests.yml +63 -0
- data/.gitignore +1 -1
- data/.overcommit.yml +21 -0
- data/.rspec +1 -1
- data/.rubocop.yml +148 -0
- data/.rubocop_todo.yml +35 -0
- data/.simplecov +4 -0
- data/CHANGELOG.md +278 -0
- data/Gemfile +9 -5
- data/LICENSE.md +21 -0
- data/README.md +52 -16
- data/Rakefile +0 -8
- data/lib/mock_redis/assertions.rb +0 -1
- data/lib/mock_redis/connection_method.rb +13 -0
- data/lib/mock_redis/database.rb +193 -257
- data/lib/mock_redis/expire_wrapper.rb +2 -2
- data/lib/mock_redis/future.rb +23 -0
- data/lib/mock_redis/geospatial_methods.rb +240 -0
- data/lib/mock_redis/hash_methods.rb +83 -24
- data/lib/mock_redis/indifferent_hash.rb +11 -0
- data/lib/mock_redis/info_method.rb +160 -0
- data/lib/mock_redis/list_methods.rb +34 -19
- data/lib/mock_redis/multi_db_wrapper.rb +8 -7
- data/lib/mock_redis/pipelined_wrapper.rb +42 -16
- data/lib/mock_redis/set_methods.rb +62 -19
- data/lib/mock_redis/sort_method.rb +81 -0
- 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 +235 -42
- data/lib/mock_redis/transaction_wrapper.rb +62 -28
- data/lib/mock_redis/utility_methods.rb +62 -11
- data/lib/mock_redis/version.rb +4 -1
- data/lib/mock_redis/zset.rb +24 -29
- data/lib/mock_redis/zset_methods.rb +187 -59
- data/lib/mock_redis.rb +77 -27
- data/mock_redis.gemspec +23 -15
- data/spec/client_spec.rb +29 -0
- 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 +25 -0
- data/spec/commands/bitfield_spec.rb +169 -0
- data/spec/commands/blpop_spec.rb +19 -21
- data/spec/commands/brpop_spec.rb +25 -20
- data/spec/commands/brpoplpush_spec.rb +16 -17
- data/spec/commands/connected_spec.rb +7 -0
- data/spec/commands/connection_spec.rb +15 -0
- data/spec/commands/dbsize_spec.rb +3 -3
- data/spec/commands/decr_spec.rb +8 -8
- data/spec/commands/decrby_spec.rb +8 -8
- data/spec/commands/del_spec.rb +35 -3
- data/spec/commands/disconnect_spec.rb +7 -0
- data/spec/commands/dump_spec.rb +19 -0
- data/spec/commands/echo_spec.rb +4 -4
- data/spec/commands/eval_spec.rb +7 -0
- data/spec/commands/evalsha_spec.rb +10 -0
- data/spec/commands/exists_spec.rb +36 -7
- data/spec/commands/expire_spec.rb +48 -20
- data/spec/commands/expireat_spec.rb +12 -13
- data/spec/commands/flushall_spec.rb +5 -5
- data/spec/commands/flushdb_spec.rb +5 -5
- data/spec/commands/future_spec.rb +30 -0
- data/spec/commands/geoadd_spec.rb +58 -0
- data/spec/commands/geodist_spec.rb +118 -0
- data/spec/commands/geohash_spec.rb +52 -0
- data/spec/commands/geopos_spec.rb +55 -0
- data/spec/commands/get_spec.rb +14 -6
- data/spec/commands/getbit_spec.rb +7 -7
- data/spec/commands/getrange_spec.rb +9 -9
- data/spec/commands/getset_spec.rb +7 -7
- data/spec/commands/hdel_spec.rb +41 -11
- data/spec/commands/hexists_spec.rb +11 -11
- data/spec/commands/hget_spec.rb +7 -7
- data/spec/commands/hgetall_spec.rb +15 -5
- data/spec/commands/hincrby_spec.rb +16 -16
- data/spec/commands/hincrbyfloat_spec.rb +58 -0
- data/spec/commands/hkeys_spec.rb +5 -5
- data/spec/commands/hlen_spec.rb +5 -5
- data/spec/commands/hmget_spec.rb +19 -9
- data/spec/commands/hmset_spec.rb +38 -12
- data/spec/commands/hscan_each_spec.rb +48 -0
- data/spec/commands/hscan_spec.rb +27 -0
- data/spec/commands/hset_spec.rb +26 -12
- data/spec/commands/hsetnx_spec.rb +16 -16
- data/spec/commands/hvals_spec.rb +5 -5
- data/spec/commands/incr_spec.rb +8 -8
- data/spec/commands/incrby_spec.rb +13 -13
- data/spec/commands/incrbyfloat_spec.rb +13 -13
- data/spec/commands/info_spec.rb +54 -5
- data/spec/commands/keys_spec.rb +83 -31
- data/spec/commands/lastsave_spec.rb +2 -2
- data/spec/commands/lindex_spec.rb +20 -10
- data/spec/commands/linsert_spec.rb +14 -14
- data/spec/commands/llen_spec.rb +4 -4
- data/spec/commands/lpop_spec.rb +6 -6
- data/spec/commands/lpush_spec.rb +21 -15
- data/spec/commands/lpushx_spec.rb +24 -11
- data/spec/commands/lrange_spec.rb +24 -8
- data/spec/commands/lrem_spec.rb +16 -16
- data/spec/commands/lset_spec.rb +17 -12
- data/spec/commands/ltrim_spec.rb +17 -7
- data/spec/commands/mapped_hmget_spec.rb +13 -9
- data/spec/commands/mapped_hmset_spec.rb +12 -12
- data/spec/commands/mapped_mget_spec.rb +22 -0
- data/spec/commands/mapped_mset_spec.rb +19 -0
- data/spec/commands/mapped_msetnx_spec.rb +26 -0
- data/spec/commands/mget_spec.rb +48 -17
- data/spec/commands/move_spec.rb +37 -37
- data/spec/commands/mset_spec.rb +20 -6
- data/spec/commands/msetnx_spec.rb +14 -14
- data/spec/commands/persist_spec.rb +15 -16
- data/spec/commands/pexpire_spec.rb +86 -0
- data/spec/commands/pexpireat_spec.rb +48 -0
- data/spec/commands/ping_spec.rb +6 -2
- data/spec/commands/pipelined_spec.rb +98 -7
- data/spec/commands/pttl_spec.rb +41 -0
- data/spec/commands/randomkey_spec.rb +3 -3
- data/spec/commands/rename_spec.rb +16 -12
- data/spec/commands/renamenx_spec.rb +13 -15
- data/spec/commands/restore_spec.rb +47 -0
- data/spec/commands/rpop_spec.rb +6 -6
- data/spec/commands/rpoplpush_spec.rb +13 -8
- data/spec/commands/rpush_spec.rb +21 -15
- data/spec/commands/rpushx_spec.rb +24 -11
- data/spec/commands/sadd_spec.rb +14 -10
- data/spec/commands/scan_each_spec.rb +39 -0
- data/spec/commands/scan_spec.rb +64 -0
- data/spec/commands/scard_spec.rb +3 -3
- data/spec/commands/script_spec.rb +9 -0
- data/spec/commands/sdiff_spec.rb +13 -13
- data/spec/commands/sdiffstore_spec.rb +13 -13
- data/spec/commands/select_spec.rb +13 -5
- data/spec/commands/set_spec.rb +112 -0
- data/spec/commands/setbit_spec.rb +25 -16
- data/spec/commands/setex_spec.rb +20 -4
- data/spec/commands/setnx_spec.rb +6 -6
- data/spec/commands/setrange_spec.rb +12 -12
- data/spec/commands/sinter_spec.rb +11 -13
- data/spec/commands/sinterstore_spec.rb +12 -12
- data/spec/commands/sismember_spec.rb +10 -10
- data/spec/commands/smembers_spec.rb +15 -5
- data/spec/commands/smove_spec.rb +13 -13
- data/spec/commands/sort_list_spec.rb +21 -0
- data/spec/commands/sort_set_spec.rb +21 -0
- data/spec/commands/sort_zset_spec.rb +21 -0
- data/spec/commands/spop_spec.rb +19 -4
- data/spec/commands/srandmember_spec.rb +28 -4
- data/spec/commands/srem_spec.rb +17 -12
- data/spec/commands/sscan_each_spec.rb +48 -0
- data/spec/commands/sscan_spec.rb +39 -0
- data/spec/commands/strlen_spec.rb +4 -5
- data/spec/commands/sunion_spec.rb +13 -11
- data/spec/commands/sunionstore_spec.rb +12 -12
- data/spec/commands/ttl_spec.rb +11 -6
- data/spec/commands/type_spec.rb +1 -1
- data/spec/commands/watch_spec.rb +9 -4
- data/spec/commands/xadd_spec.rb +122 -0
- data/spec/commands/xlen_spec.rb +22 -0
- data/spec/commands/xrange_spec.rb +164 -0
- data/spec/commands/xread_spec.rb +66 -0
- data/spec/commands/xrevrange_spec.rb +130 -0
- data/spec/commands/xtrim_spec.rb +36 -0
- data/spec/commands/zadd_spec.rb +100 -11
- data/spec/commands/zcard_spec.rb +4 -4
- data/spec/commands/zcount_spec.rb +18 -10
- data/spec/commands/zincrby_spec.rb +6 -6
- data/spec/commands/zinterstore_spec.rb +54 -20
- data/spec/commands/zpopmax_spec.rb +60 -0
- data/spec/commands/zpopmin_spec.rb +60 -0
- data/spec/commands/zrange_spec.rb +54 -13
- data/spec/commands/zrangebyscore_spec.rb +42 -27
- data/spec/commands/zrank_spec.rb +4 -4
- data/spec/commands/zrem_spec.rb +18 -12
- data/spec/commands/zremrangebyrank_spec.rb +5 -5
- data/spec/commands/zremrangebyscore_spec.rb +12 -5
- data/spec/commands/zrevrange_spec.rb +35 -10
- data/spec/commands/zrevrangebyscore_spec.rb +26 -15
- data/spec/commands/zrevrank_spec.rb +4 -4
- data/spec/commands/zscan_each_spec.rb +48 -0
- data/spec/commands/zscan_spec.rb +26 -0
- data/spec/commands/zscore_spec.rb +7 -7
- data/spec/commands/zunionstore_spec.rb +54 -21
- data/spec/mock_redis_spec.rb +61 -0
- data/spec/spec_helper.rb +35 -8
- data/spec/support/redis_multiplexer.rb +62 -37
- data/spec/support/shared_examples/does_not_cleanup_empty_strings.rb +14 -0
- data/spec/support/shared_examples/only_operates_on_hashes.rb +5 -3
- data/spec/support/shared_examples/only_operates_on_lists.rb +5 -3
- data/spec/support/shared_examples/only_operates_on_sets.rb +5 -3
- data/spec/support/shared_examples/only_operates_on_strings.rb +4 -4
- data/spec/support/shared_examples/only_operates_on_zsets.rb +18 -16
- data/spec/support/shared_examples/sorts_enumerables.rb +56 -0
- data/spec/transactions_spec.rb +79 -29
- metadata +162 -42
- data/LICENSE +0 -19
- data/spec/commands/hash_operator_spec.rb +0 -21
data/spec/commands/incr_spec.rb
CHANGED
@@ -3,32 +3,32 @@ require 'spec_helper'
|
|
3
3
|
describe '#incr(key)' do
|
4
4
|
before { @key = 'mock-redis-test:33888' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns the value after the increment' do
|
7
7
|
@redises.set(@key, 1)
|
8
8
|
@redises.incr(@key).should == 2
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'treats a missing key like 0' do
|
12
12
|
@redises.incr(@key).should == 1
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'increments negative numbers' do
|
16
16
|
@redises.set(@key, -10)
|
17
17
|
@redises.incr(@key).should == -9
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'works multiple times' do
|
21
21
|
@redises.incr(@key).should == 1
|
22
22
|
@redises.incr(@key).should == 2
|
23
23
|
@redises.incr(@key).should == 3
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
27
|
-
@redises.set(@key,
|
26
|
+
it 'raises an error if the value does not look like an integer' do
|
27
|
+
@redises.set(@key, 'one')
|
28
28
|
lambda do
|
29
29
|
@redises.incr(@key)
|
30
|
-
end.should raise_error(
|
30
|
+
end.should raise_error(Redis::CommandError)
|
31
31
|
end
|
32
32
|
|
33
|
-
it_should_behave_like
|
33
|
+
it_should_behave_like 'a string-only command'
|
34
34
|
end
|
@@ -3,42 +3,42 @@ require 'spec_helper'
|
|
3
3
|
describe '#incrby(key, increment)' do
|
4
4
|
before { @key = 'mock-redis-test:65374' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns the value after the increment' do
|
7
7
|
@redises.set(@key, 2)
|
8
8
|
@redises.incrby(@key, 2).should == 4
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'treats a missing key like 0' do
|
12
12
|
@redises.incrby(@key, 1).should == 1
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'increments negative numbers' do
|
16
16
|
@redises.set(@key, -10)
|
17
17
|
@redises.incrby(@key, 2).should == -8
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'works multiple times' do
|
21
21
|
@redises.incrby(@key, 2).should == 2
|
22
22
|
@redises.incrby(@key, 2).should == 4
|
23
23
|
@redises.incrby(@key, 2).should == 6
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
27
|
-
@redises.incrby(@key,
|
26
|
+
it 'accepts an integer-ish string' do
|
27
|
+
@redises.incrby(@key, '2').should == 2
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
31
|
-
@redises.set(@key,
|
30
|
+
it 'raises an error if the value does not look like an integer' do
|
31
|
+
@redises.set(@key, 'one')
|
32
32
|
lambda do
|
33
33
|
@redises.incrby(@key, 1)
|
34
|
-
end.should raise_error(
|
34
|
+
end.should raise_error(Redis::CommandError)
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it 'raises an error if the delta does not look like an integer' do
|
38
38
|
lambda do
|
39
|
-
@redises.incrby(@key,
|
40
|
-
end.should raise_error(
|
39
|
+
@redises.incrby(@key, 'foo')
|
40
|
+
end.should raise_error(Redis::CommandError)
|
41
41
|
end
|
42
42
|
|
43
|
-
it_should_behave_like
|
43
|
+
it_should_behave_like 'a string-only command'
|
44
44
|
end
|
@@ -3,42 +3,42 @@ require 'spec_helper'
|
|
3
3
|
describe '#incrbyfloat(key, increment)' do
|
4
4
|
before { @key = 'mock-redis-test:65374' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns the value after the increment' do
|
7
7
|
@redises.set(@key, 2.0)
|
8
8
|
@redises.incrbyfloat(@key, 2.1).should be_within(0.0001).of(4.1)
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'treats a missing key like 0' do
|
12
12
|
@redises.incrbyfloat(@key, 1.2).should be_within(0.0001).of(1.2)
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'increments negative numbers' do
|
16
16
|
@redises.set(@key, -10.4)
|
17
17
|
@redises.incrbyfloat(@key, 2.3).should be_within(0.0001).of(-8.1)
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'works multiple times' do
|
21
21
|
@redises.incrbyfloat(@key, 2.1).should be_within(0.0001).of(2.1)
|
22
22
|
@redises.incrbyfloat(@key, 2.2).should be_within(0.0001).of(4.3)
|
23
23
|
@redises.incrbyfloat(@key, 2.3).should be_within(0.0001).of(6.6)
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
27
|
-
@redises.incrbyfloat(@key,
|
26
|
+
it 'accepts an float-ish string' do
|
27
|
+
@redises.incrbyfloat(@key, '2.2').should be_within(0.0001).of(2.2)
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
31
|
-
@redises.set(@key,
|
30
|
+
it 'raises an error if the value does not look like an float' do
|
31
|
+
@redises.set(@key, 'one.two')
|
32
32
|
lambda do
|
33
33
|
@redises.incrbyfloat(@key, 1)
|
34
|
-
end.should raise_error(
|
34
|
+
end.should raise_error(Redis::CommandError)
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it 'raises an error if the delta does not look like an float' do
|
38
38
|
lambda do
|
39
|
-
@redises.incrbyfloat(@key,
|
40
|
-
end.should raise_error(
|
39
|
+
@redises.incrbyfloat(@key, 'foobar.baz')
|
40
|
+
end.should raise_error(Redis::CommandError)
|
41
41
|
end
|
42
42
|
|
43
|
-
it_should_behave_like
|
43
|
+
it_should_behave_like 'a string-only command'
|
44
44
|
end
|
data/spec/commands/info_spec.rb
CHANGED
@@ -1,13 +1,62 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe '#info [mock only]' do
|
4
|
-
|
4
|
+
let(:redis) { @redises.mock }
|
5
5
|
|
6
|
-
it
|
7
|
-
|
6
|
+
it 'responds with a config hash' do
|
7
|
+
redis.info.should be_a(Hash)
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
11
|
-
|
10
|
+
it 'gets default set of info' do
|
11
|
+
info = redis.info
|
12
|
+
info['arch_bits'].should be_a(String)
|
13
|
+
info['connected_clients'].should be_a(String)
|
14
|
+
info['aof_rewrite_scheduled'].should be_a(String)
|
15
|
+
info['used_cpu_sys'].should be_a(String)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'gets all info' do
|
19
|
+
info = redis.info(:all)
|
20
|
+
info['arch_bits'].should be_a(String)
|
21
|
+
info['connected_clients'].should be_a(String)
|
22
|
+
info['aof_rewrite_scheduled'].should be_a(String)
|
23
|
+
info['used_cpu_sys'].should be_a(String)
|
24
|
+
info['cmdstat_slowlog'].should be_a(String)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'gets server info' do
|
28
|
+
redis.info(:server)['arch_bits'].should be_a(String)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'gets clients info' do
|
32
|
+
redis.info(:clients)['connected_clients'].should be_a(String)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'gets memory info' do
|
36
|
+
redis.info(:memory)['used_memory'].should be_a(String)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'gets persistence info' do
|
40
|
+
redis.info(:persistence)['aof_rewrite_scheduled'].should be_a(String)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'gets stats info' do
|
44
|
+
redis.info(:stats)['keyspace_hits'].should be_a(String)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'gets replication info' do
|
48
|
+
redis.info(:replication)['role'].should be_a(String)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'gets cpu info' do
|
52
|
+
redis.info(:cpu)['used_cpu_sys'].should be_a(String)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'gets keyspace info' do
|
56
|
+
redis.info(:keyspace)['db0'].should be_a(String)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'gets commandstats info' do
|
60
|
+
redis.info(:commandstats)['sunionstore']['usec'].should be_a(String)
|
12
61
|
end
|
13
62
|
end
|
data/spec/commands/keys_spec.rb
CHANGED
@@ -1,55 +1,81 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe '#keys()' do
|
4
|
-
|
5
|
-
|
6
|
-
@redises.keys("mock-redis-test:29016").should == []
|
4
|
+
it 'returns [] when no keys are found (no regex characters)' do
|
5
|
+
@redises.keys('mock-redis-test:29016').should == []
|
7
6
|
end
|
8
7
|
|
9
|
-
it
|
10
|
-
@redises.keys(
|
8
|
+
it 'returns [] when no keys are found (some regex characters)' do
|
9
|
+
@redises.keys('mock-redis-test:29016*').should == []
|
11
10
|
end
|
12
11
|
|
13
|
-
describe
|
12
|
+
describe 'with pattern matching' do
|
14
13
|
before do
|
15
|
-
@redises.set(
|
16
|
-
@redises.set(
|
17
|
-
@redises.set(
|
18
|
-
@redises.set(
|
19
|
-
@redises.set(
|
20
|
-
@redises.set(
|
21
|
-
|
22
|
-
|
23
|
-
@redises.set(
|
14
|
+
@redises.set('mock-redis-test:key', 0)
|
15
|
+
@redises.set('mock-redis-test:key1', 1)
|
16
|
+
@redises.set('mock-redis-test:key2', 2)
|
17
|
+
@redises.set('mock-redis-test:key3', 3)
|
18
|
+
@redises.set('mock-redis-test:key10', 10)
|
19
|
+
@redises.set('mock-redis-test:key20', 20)
|
20
|
+
@redises.set('mock-redis-test:key30', 30)
|
21
|
+
|
22
|
+
@redises.set('mock-redis-test:regexp-key(1|22)', 40)
|
23
|
+
@redises.set('mock-redis-test:regexp-key3+', 40)
|
24
|
+
@redises.set('mock-redis-test:regexp-key33', 40)
|
25
|
+
@redises.set('mock-redis-test:regexp-key4a', 40)
|
26
|
+
@redises.set('mock-redis-test:regexp-key4-', 40)
|
27
|
+
@redises.set('mock-redis-test:regexp-key4b', 40)
|
28
|
+
@redises.set('mock-redis-test:regexp-key4c', 40)
|
29
|
+
|
30
|
+
@redises.set('mock-redis-test:special-key?', 'true')
|
31
|
+
@redises.set('mock-redis-test:special-key*', 'true')
|
32
|
+
@redises.set('mock-redis-test:special-key-!?*', 'true')
|
24
33
|
end
|
25
34
|
|
26
|
-
describe
|
27
|
-
it
|
28
|
-
@redises.keys(
|
35
|
+
describe 'the ? character' do
|
36
|
+
it 'is treated as a single character (at the end of the pattern)' do
|
37
|
+
@redises.keys('mock-redis-test:key?').sort.should == [
|
29
38
|
'mock-redis-test:key1',
|
30
39
|
'mock-redis-test:key2',
|
31
40
|
'mock-redis-test:key3',
|
32
41
|
]
|
33
42
|
end
|
34
43
|
|
35
|
-
it
|
36
|
-
@redises.keys(
|
44
|
+
it 'is treated as a single character (in the middle of the pattern)' do
|
45
|
+
@redises.keys('mock-redis-test:key?0').sort.should == [
|
37
46
|
'mock-redis-test:key10',
|
38
47
|
'mock-redis-test:key20',
|
39
48
|
'mock-redis-test:key30',
|
40
49
|
]
|
41
50
|
end
|
42
51
|
|
43
|
-
it
|
52
|
+
it 'treats \\? as a literal ?' do
|
44
53
|
@redises.keys('mock-redis-test:special-key\?').sort.should == [
|
45
|
-
'mock-redis-test:special-key?'
|
54
|
+
'mock-redis-test:special-key?',
|
46
55
|
]
|
47
56
|
end
|
57
|
+
|
58
|
+
context 'multiple ? characters' do
|
59
|
+
it "properly handles multiple consequtive '?' characters" do
|
60
|
+
@redises.keys('mock-redis-test:special-key-???').sort.should == [
|
61
|
+
'mock-redis-test:special-key-!?*',
|
62
|
+
]
|
63
|
+
end
|
64
|
+
|
65
|
+
context '\\? as a literal ' do
|
66
|
+
it 'handles multiple ? as both literal and special character' do
|
67
|
+
@redises.keys('mock-redis-test:special-key-?\??').sort.should == [
|
68
|
+
'mock-redis-test:special-key-!?*',
|
69
|
+
]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
48
73
|
end
|
49
74
|
|
50
|
-
describe
|
51
|
-
it
|
52
|
-
@redises.keys(
|
75
|
+
describe 'the * character' do
|
76
|
+
it 'is treated as 0 or more characters' do
|
77
|
+
@redises.keys('mock-redis-test:key*').sort.should == [
|
78
|
+
'mock-redis-test:key',
|
53
79
|
'mock-redis-test:key1',
|
54
80
|
'mock-redis-test:key10',
|
55
81
|
'mock-redis-test:key2',
|
@@ -59,15 +85,15 @@ describe '#keys()' do
|
|
59
85
|
]
|
60
86
|
end
|
61
87
|
|
62
|
-
it
|
88
|
+
it 'treats \\* as a literal *' do
|
63
89
|
@redises.keys('mock-redis-test:special-key\*').sort.should == [
|
64
|
-
'mock-redis-test:special-key*'
|
90
|
+
'mock-redis-test:special-key*',
|
65
91
|
]
|
66
92
|
end
|
67
93
|
end
|
68
94
|
|
69
|
-
describe
|
70
|
-
it
|
95
|
+
describe 'character classes ([abcde])' do
|
96
|
+
it 'matches any one of those characters' do
|
71
97
|
@redises.keys('mock-redis-test:key[12]').sort.should == [
|
72
98
|
'mock-redis-test:key1',
|
73
99
|
'mock-redis-test:key2',
|
@@ -75,8 +101,34 @@ describe '#keys()' do
|
|
75
101
|
end
|
76
102
|
end
|
77
103
|
|
78
|
-
describe
|
79
|
-
it "
|
104
|
+
describe 'the | character' do
|
105
|
+
it "is treated as literal (not 'or')" do
|
106
|
+
@redises.keys('mock-redis-test:regexp-key(1|22)').sort.should == [
|
107
|
+
'mock-redis-test:regexp-key(1|22)',
|
108
|
+
]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'the + character' do
|
113
|
+
it "is treated as literal (not 'one or more' quantifier)" do
|
114
|
+
@redises.keys('mock-redis-test:regexp-key3+').sort.should == [
|
115
|
+
'mock-redis-test:regexp-key3+',
|
116
|
+
]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'character classes ([a-c])' do
|
121
|
+
it 'specifies a range which matches any lowercase letter from "a" to "c"' do
|
122
|
+
@redises.keys('mock-redis-test:regexp-key4[a-c]').sort.should == [
|
123
|
+
'mock-redis-test:regexp-key4a',
|
124
|
+
'mock-redis-test:regexp-key4b',
|
125
|
+
'mock-redis-test:regexp-key4c',
|
126
|
+
]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'combining metacharacters' do
|
131
|
+
it 'works with different metacharacters simultaneously' do
|
80
132
|
@redises.keys('mock-redis-test:k*[12]?').sort.should == [
|
81
133
|
'mock-redis-test:key10',
|
82
134
|
'mock-redis-test:key20',
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#lastsave [mock only]' do
|
4
4
|
# can't test against both since it's timing-dependent
|
5
|
-
it
|
5
|
+
it 'returns a Unix time' do
|
6
6
|
@redises.mock.lastsave.to_s.should =~ /^\d+$/
|
7
7
|
end
|
8
8
|
end
|
@@ -3,37 +3,47 @@ require 'spec_helper'
|
|
3
3
|
describe '#lindex(key, index)' do
|
4
4
|
before { @key = 'mock-redis-test:69312' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'gets an element from the list by its index' do
|
7
7
|
@redises.lpush(@key, 20)
|
8
8
|
@redises.lpush(@key, 10)
|
9
9
|
|
10
|
-
@redises.lindex(@key, 0).should ==
|
11
|
-
@redises.lindex(@key, 1).should ==
|
10
|
+
@redises.lindex(@key, 0).should == '10'
|
11
|
+
@redises.lindex(@key, 1).should == '20'
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'treats negative indices as coming from the right' do
|
15
15
|
@redises.lpush(@key, 20)
|
16
16
|
@redises.lpush(@key, 10)
|
17
17
|
|
18
|
-
@redises.lindex(@key, -1).should ==
|
19
|
-
@redises.lindex(@key, -2).should ==
|
18
|
+
@redises.lindex(@key, -1).should == '20'
|
19
|
+
@redises.lindex(@key, -2).should == '10'
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'gets an element from the list by its index when index is a string' do
|
23
|
+
@redises.lpush(@key, 20)
|
24
|
+
@redises.lpush(@key, 10)
|
25
|
+
|
26
|
+
@redises.lindex(@key, '0').should == '10'
|
27
|
+
@redises.lindex(@key, '1').should == '20'
|
28
|
+
@redises.lindex(@key, '-1').should == '20'
|
29
|
+
@redises.lindex(@key, '-2').should == '10'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns nil if the index is too large (and positive)' do
|
23
33
|
@redises.lpush(@key, 20)
|
24
34
|
|
25
35
|
@redises.lindex(@key, 100).should be_nil
|
26
36
|
end
|
27
37
|
|
28
|
-
it
|
38
|
+
it 'returns nil if the index is too large (and negative)' do
|
29
39
|
@redises.lpush(@key, 20)
|
30
40
|
|
31
41
|
@redises.lindex(@key, -100).should be_nil
|
32
42
|
end
|
33
43
|
|
34
|
-
it
|
44
|
+
it 'returns nil for nonexistent values' do
|
35
45
|
@redises.lindex(@key, 0).should be_nil
|
36
46
|
end
|
37
47
|
|
38
|
-
it_should_behave_like
|
48
|
+
it_should_behave_like 'a list-only command'
|
39
49
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#linsert(key, :before|:after, pivot, value)' do
|
4
4
|
before { @key = 'mock-redis-test:48733' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns the new size of the list when the pivot is found' do
|
7
7
|
@redises.lpush(@key, 'X')
|
8
8
|
|
9
9
|
@redises.linsert(@key, :before, 'X', 'Y').should == 2
|
10
10
|
@redises.lpushx(@key, 'X').should == 3
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'does nothing when run against a nonexistent key' do
|
14
14
|
@redises.linsert(@key, :before, 1, 2).should == 0
|
15
15
|
@redises.get(@key).should be_nil
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'returns -1 if the pivot is not found' do
|
19
19
|
@redises.lpush(@key, 1)
|
20
20
|
@redises.linsert(@key, :after, 'X', 'Y').should == -1
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
23
|
+
it 'inserts elements before the pivot when given :before as position' do
|
24
24
|
@redises.lpush(@key, 'bert')
|
25
25
|
@redises.linsert(@key, :before, 'bert', 'ernie')
|
26
26
|
|
@@ -36,33 +36,33 @@ describe "#linsert(key, :before|:after, pivot, value)" do
|
|
36
36
|
@redises.lindex(@key, 1).should == 'bert'
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it 'inserts elements after the pivot when given :after as position' do
|
40
40
|
@redises.lpush(@key, 'bert')
|
41
41
|
@redises.linsert(@key, :after, 'bert', 'ernie')
|
42
|
-
|
42
|
+
|
43
43
|
@redises.lindex(@key, 0).should == 'bert'
|
44
44
|
@redises.lindex(@key, 1).should == 'ernie'
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
it "inserts elements after the pivot when given 'after' as position" do
|
48
48
|
@redises.lpush(@key, 'bert')
|
49
49
|
@redises.linsert(@key, 'after', 'bert', 'ernie')
|
50
|
-
|
50
|
+
|
51
51
|
@redises.lindex(@key, 0).should == 'bert'
|
52
52
|
@redises.lindex(@key, 1).should == 'ernie'
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
55
|
+
it 'raises an error when given a position that is neither before nor after' do
|
56
56
|
lambda do
|
57
57
|
@redises.linsert(@key, :near, 1, 2)
|
58
|
-
end.should raise_error(
|
58
|
+
end.should raise_error(Redis::CommandError)
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it 'stores values as strings' do
|
62
62
|
@redises.lpush(@key, 1)
|
63
63
|
@redises.linsert(@key, :before, 1, 2)
|
64
|
-
@redises.lindex(@key, 0).should ==
|
64
|
+
@redises.lindex(@key, 0).should == '2'
|
65
65
|
end
|
66
66
|
|
67
|
-
it_should_behave_like
|
67
|
+
it_should_behave_like 'a list-only command'
|
68
68
|
end
|
data/spec/commands/llen_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#llen(key)' do
|
4
4
|
before { @key = 'mock-redis-test:78407' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns 0 for a nonexistent key' do
|
7
7
|
@redises.llen(@key).should == 0
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
10
|
+
it 'returns the length of the list' do
|
11
11
|
5.times { @redises.lpush(@key, 'X') }
|
12
12
|
@redises.llen(@key).should == 5
|
13
13
|
end
|
14
14
|
|
15
|
-
it_should_behave_like
|
15
|
+
it_should_behave_like 'a list-only command'
|
16
16
|
end
|
data/spec/commands/lpop_spec.rb
CHANGED
@@ -3,32 +3,32 @@ require 'spec_helper'
|
|
3
3
|
describe '#lpop(key)' do
|
4
4
|
before { @key = 'mock-redis-test:65374' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns and removes the first element of a list' do
|
7
7
|
@redises.lpush(@key, 1)
|
8
8
|
@redises.lpush(@key, 2)
|
9
9
|
|
10
|
-
@redises.lpop(@key).should ==
|
10
|
+
@redises.lpop(@key).should == '2'
|
11
11
|
|
12
12
|
@redises.llen(@key).should == 1
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'returns nil if the list is empty' do
|
16
16
|
@redises.lpush(@key, 'foo')
|
17
17
|
@redises.lpop(@key)
|
18
18
|
|
19
19
|
@redises.lpop(@key).should be_nil
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'returns nil for nonexistent values' do
|
23
23
|
@redises.lpop(@key).should be_nil
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'removes empty lists' do
|
27
27
|
@redises.lpush(@key, 'foo')
|
28
28
|
@redises.lpop(@key)
|
29
29
|
|
30
30
|
@redises.get(@key).should be_nil
|
31
31
|
end
|
32
32
|
|
33
|
-
it_should_behave_like
|
33
|
+
it_should_behave_like 'a list-only command'
|
34
34
|
end
|
data/spec/commands/lpush_spec.rb
CHANGED
@@ -1,37 +1,43 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#lpush(key, value)' do
|
4
4
|
before { @key = 'mock-redis-test:57367' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns the new size of the list' do
|
7
7
|
@redises.lpush(@key, 'X').should == 1
|
8
8
|
@redises.lpush(@key, 'X').should == 2
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'creates a new list when run against a nonexistent key' do
|
12
12
|
@redises.lpush(@key, 'value')
|
13
13
|
@redises.llen(@key).should == 1
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
17
|
-
@redises.lpush(@key,
|
18
|
-
@redises.lpush(@key,
|
16
|
+
it 'prepends items to the list' do
|
17
|
+
@redises.lpush(@key, 'bert')
|
18
|
+
@redises.lpush(@key, 'ernie')
|
19
19
|
|
20
|
-
@redises.lindex(@key, 0).should ==
|
21
|
-
@redises.lindex(@key, 1).should ==
|
20
|
+
@redises.lindex(@key, 0).should == 'ernie'
|
21
|
+
@redises.lindex(@key, 1).should == 'bert'
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'stores values as strings' do
|
25
25
|
@redises.lpush(@key, 1)
|
26
|
-
@redises.lindex(@key, 0).should ==
|
26
|
+
@redises.lindex(@key, 0).should == '1'
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'supports a variable number of arguments' do
|
30
30
|
@redises.lpush(@key, [1, 2, 3]).should == 3
|
31
|
-
@redises.lindex(@key, 0).should ==
|
32
|
-
@redises.lindex(@key, 1).should ==
|
33
|
-
@redises.lindex(@key, 2).should ==
|
31
|
+
@redises.lindex(@key, 0).should == '3'
|
32
|
+
@redises.lindex(@key, 1).should == '2'
|
33
|
+
@redises.lindex(@key, 2).should == '1'
|
34
34
|
end
|
35
35
|
|
36
|
-
|
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'
|
37
43
|
end
|