mock_redis 0.14.1 → 0.15.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/.gitignore +1 -0
- data/.overcommit.yml +1 -1
- data/.rubocop.yml +91 -0
- data/.simplecov +4 -0
- data/.travis.yml +14 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -2
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/lib/mock_redis.rb +25 -26
- data/lib/mock_redis/assertions.rb +0 -1
- data/lib/mock_redis/database.rb +35 -28
- data/lib/mock_redis/expire_wrapper.rb +1 -1
- data/lib/mock_redis/future.rb +1 -1
- data/lib/mock_redis/hash_methods.rb +18 -17
- data/lib/mock_redis/indifferent_hash.rb +4 -0
- data/lib/mock_redis/info_method.rb +109 -108
- data/lib/mock_redis/list_methods.rb +17 -16
- data/lib/mock_redis/multi_db_wrapper.rb +5 -4
- data/lib/mock_redis/pipelined_wrapper.rb +3 -3
- data/lib/mock_redis/set_methods.rb +10 -9
- data/lib/mock_redis/sort_method.rb +11 -12
- data/lib/mock_redis/string_methods.rb +26 -29
- data/lib/mock_redis/transaction_wrapper.rb +7 -8
- data/lib/mock_redis/utility_methods.rb +9 -12
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +22 -23
- data/lib/mock_redis/zset_methods.rb +25 -25
- data/spec/cloning_spec.rb +17 -18
- data/spec/commands/append_spec.rb +4 -4
- data/spec/commands/auth_spec.rb +1 -1
- data/spec/commands/bgrewriteaof_spec.rb +2 -2
- data/spec/commands/bgsave_spec.rb +2 -2
- data/spec/commands/bitcount_spec.rb +3 -3
- data/spec/commands/blpop_spec.rb +10 -10
- data/spec/commands/brpop_spec.rb +10 -10
- data/spec/commands/brpoplpush_spec.rb +9 -9
- data/spec/commands/connected_spec.rb +2 -2
- data/spec/commands/dbsize_spec.rb +3 -3
- data/spec/commands/decr_spec.rb +7 -7
- data/spec/commands/decrby_spec.rb +7 -7
- data/spec/commands/del_spec.rb +4 -4
- data/spec/commands/disconnect_spec.rb +2 -2
- data/spec/commands/echo_spec.rb +4 -4
- data/spec/commands/exists_spec.rb +3 -3
- data/spec/commands/expire_spec.rb +13 -13
- data/spec/commands/expireat_spec.rb +6 -7
- data/spec/commands/flushall_spec.rb +5 -5
- data/spec/commands/flushdb_spec.rb +5 -5
- data/spec/commands/future_spec.rb +2 -2
- data/spec/commands/get_spec.rb +7 -7
- data/spec/commands/getbit_spec.rb +6 -6
- data/spec/commands/getrange_spec.rb +9 -9
- data/spec/commands/getset_spec.rb +7 -7
- data/spec/commands/hash_operator_spec.rb +5 -5
- data/spec/commands/hdel_spec.rb +12 -12
- data/spec/commands/hexists_spec.rb +7 -7
- data/spec/commands/hget_spec.rb +7 -7
- data/spec/commands/hgetall_spec.rb +6 -6
- data/spec/commands/hincrby_spec.rb +14 -14
- data/spec/commands/hincrbyfloat_spec.rb +14 -14
- data/spec/commands/hkeys_spec.rb +5 -5
- data/spec/commands/hlen_spec.rb +5 -5
- data/spec/commands/hmget_spec.rb +8 -8
- data/spec/commands/hmset_spec.rb +10 -10
- data/spec/commands/hset_spec.rb +11 -11
- data/spec/commands/hsetnx_spec.rb +14 -14
- data/spec/commands/hvals_spec.rb +5 -5
- data/spec/commands/incr_spec.rb +7 -7
- data/spec/commands/incrby_spec.rb +11 -11
- data/spec/commands/incrbyfloat_spec.rb +11 -11
- data/spec/commands/info_spec.rb +30 -30
- data/spec/commands/keys_spec.rb +42 -43
- data/spec/commands/lastsave_spec.rb +2 -2
- data/spec/commands/lindex_spec.rb +15 -15
- data/spec/commands/linsert_spec.rb +13 -13
- data/spec/commands/llen_spec.rb +4 -4
- data/spec/commands/lpop_spec.rb +6 -6
- data/spec/commands/lpush_spec.rb +16 -16
- data/spec/commands/lpushx_spec.rb +13 -13
- data/spec/commands/lrange_spec.rb +12 -12
- data/spec/commands/lrem_spec.rb +15 -15
- data/spec/commands/lset_spec.rb +12 -12
- data/spec/commands/ltrim_spec.rb +9 -9
- data/spec/commands/mapped_hmget_spec.rb +8 -8
- data/spec/commands/mapped_hmset_spec.rb +12 -12
- data/spec/commands/mapped_mget_spec.rb +4 -4
- data/spec/commands/mapped_mset_spec.rb +1 -1
- data/spec/commands/mget_spec.rb +11 -11
- data/spec/commands/move_spec.rb +29 -29
- data/spec/commands/mset_spec.rb +4 -4
- data/spec/commands/msetnx_spec.rb +10 -10
- data/spec/commands/persist_spec.rb +9 -10
- data/spec/commands/pexpire_spec.rb +12 -13
- data/spec/commands/pexpireat_spec.rb +6 -6
- data/spec/commands/ping_spec.rb +1 -1
- data/spec/commands/pipelined_spec.rb +5 -5
- data/spec/commands/pttl_spec.rb +5 -5
- data/spec/commands/randomkey_spec.rb +3 -3
- data/spec/commands/rename_spec.rb +9 -9
- data/spec/commands/renamenx_spec.rb +10 -10
- data/spec/commands/rpop_spec.rb +6 -6
- data/spec/commands/rpoplpush_spec.rb +7 -7
- data/spec/commands/rpush_spec.rb +16 -16
- data/spec/commands/rpushx_spec.rb +13 -13
- data/spec/commands/sadd_spec.rb +8 -9
- data/spec/commands/scan_spec.rb +6 -7
- data/spec/commands/scard_spec.rb +3 -3
- data/spec/commands/sdiff_spec.rb +10 -10
- data/spec/commands/sdiffstore_spec.rb +10 -10
- data/spec/commands/select_spec.rb +7 -7
- data/spec/commands/setbit_spec.rb +13 -13
- data/spec/commands/setex_spec.rb +4 -4
- data/spec/commands/setnx_spec.rb +4 -4
- data/spec/commands/setrange_spec.rb +12 -12
- data/spec/commands/sinter_spec.rb +8 -10
- data/spec/commands/sinterstore_spec.rb +9 -9
- data/spec/commands/sismember_spec.rb +5 -5
- data/spec/commands/smembers_spec.rb +5 -5
- data/spec/commands/smove_spec.rb +7 -7
- data/spec/commands/sort_list_spec.rb +3 -3
- data/spec/commands/sort_set_spec.rb +3 -3
- data/spec/commands/sort_zset_spec.rb +3 -3
- data/spec/commands/spop_spec.rb +4 -4
- data/spec/commands/srandmember_spec.rb +8 -8
- data/spec/commands/srem_spec.rb +9 -9
- data/spec/commands/strlen_spec.rb +4 -4
- data/spec/commands/sunion_spec.rb +7 -9
- data/spec/commands/sunionstore_spec.rb +9 -9
- data/spec/commands/ttl_spec.rb +5 -5
- data/spec/commands/type_spec.rb +1 -1
- data/spec/commands/zadd_spec.rb +10 -10
- data/spec/commands/zcard_spec.rb +4 -4
- data/spec/commands/zcount_spec.rb +14 -14
- data/spec/commands/zincrby_spec.rb +6 -6
- data/spec/commands/zinterstore_spec.rb +17 -17
- data/spec/commands/zrange_spec.rb +12 -12
- data/spec/commands/zrangebyscore_spec.rb +26 -26
- data/spec/commands/zrank_spec.rb +4 -4
- data/spec/commands/zrem_spec.rb +9 -9
- data/spec/commands/zremrangebyrank_spec.rb +5 -5
- data/spec/commands/zremrangebyscore_spec.rb +9 -7
- data/spec/commands/zrevrange_spec.rb +10 -10
- data/spec/commands/zrevrangebyscore_spec.rb +14 -14
- data/spec/commands/zrevrank_spec.rb +4 -4
- data/spec/commands/zscore_spec.rb +5 -5
- data/spec/commands/zunionstore_spec.rb +18 -18
- data/spec/mock_redis_spec.rb +11 -1
- data/spec/spec_helper.rb +13 -4
- data/spec/support/redis_multiplexer.rb +39 -31
- data/spec/support/shared_examples/only_operates_on_hashes.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_lists.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_sets.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_strings.rb +3 -3
- data/spec/support/shared_examples/only_operates_on_zsets.rb +12 -12
- data/spec/support/shared_examples/sorts_enumerables.rb +12 -12
- data/spec/transactions_spec.rb +18 -18
- metadata +5 -3
data/spec/commands/blpop_spec.rb
CHANGED
@@ -11,46 +11,46 @@ describe '#blpop(key [, key, ...,], timeout)' do
|
|
11
11
|
@redises.rpush(@list2, 'eleven')
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'returns [first-nonempty-list, popped-value]' do
|
15
15
|
@redises.blpop(@list1, @list2).should == [@list1, 'one']
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'pops that value off the list' do
|
19
19
|
@redises.blpop(@list1, @list2)
|
20
20
|
@redises.blpop(@list1, @list2)
|
21
21
|
|
22
22
|
@redises.blpop(@list1, @list2).should == [@list2, 'ten']
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it 'ignores empty keys' do
|
26
26
|
@redises.blpop('mock-redis-test:not-here', @list1).should ==
|
27
27
|
[@list1, 'one']
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it 'raises an error on subsecond timeouts' do
|
31
31
|
lambda do
|
32
32
|
@redises.blpop(@list1, @list2, :timeout => 0.5)
|
33
33
|
end.should raise_error(Redis::CommandError)
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it 'raises an error on negative timeout' do
|
37
37
|
lambda do
|
38
38
|
@redises.blpop(@list1, @list2, :timeout => -1)
|
39
39
|
end.should raise_error(Redis::CommandError)
|
40
40
|
end
|
41
41
|
|
42
|
-
it_should_behave_like
|
42
|
+
it_should_behave_like 'a list-only command'
|
43
43
|
|
44
|
-
context
|
45
|
-
it
|
44
|
+
context '[mock only]' do
|
45
|
+
it 'ignores positive timeouts and returns nil' do
|
46
46
|
@redises.mock.blpop('mock-redis-test:not-here', :timeout => 1).should be_nil
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it 'ignores positive legacy timeouts and returns nil' do
|
50
50
|
@redises.mock.blpop('mock-redis-test:not-here', 1).should be_nil
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it 'raises WouldBlock on zero timeout (no blocking in the mock)' do
|
54
54
|
lambda do
|
55
55
|
@redises.mock.blpop('mock-redis-test:not-here', :timeout => 0)
|
56
56
|
end.should raise_error(MockRedis::WouldBlock)
|
data/spec/commands/brpop_spec.rb
CHANGED
@@ -11,45 +11,45 @@ describe '#brpop(key [, key, ...,], timeout)' do
|
|
11
11
|
@redises.rpush(@list2, 'ten')
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'returns [first-nonempty-list, popped-value]' do
|
15
15
|
@redises.brpop(@list1, @list2).should == [@list1, 'two']
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'pops that value off the list' do
|
19
19
|
@redises.brpop(@list1, @list2)
|
20
20
|
@redises.brpop(@list1, @list2)
|
21
21
|
@redises.brpop(@list1, @list2).should == [@list2, 'ten']
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'ignores empty keys' do
|
25
25
|
@redises.brpop('mock-redis-test:not-here', @list1).should ==
|
26
26
|
[@list1, 'two']
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'raises an error on subsecond timeouts' do
|
30
30
|
lambda do
|
31
31
|
@redises.brpop(@list1, @list2, :timeout => 0.5)
|
32
32
|
end.should raise_error(Redis::CommandError)
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'raises an error on negative timeout' do
|
36
36
|
lambda do
|
37
37
|
@redises.brpop(@list1, @list2, :timeout => -1)
|
38
38
|
end.should raise_error(Redis::CommandError)
|
39
39
|
end
|
40
40
|
|
41
|
-
it_should_behave_like
|
41
|
+
it_should_behave_like 'a list-only command'
|
42
42
|
|
43
|
-
context
|
44
|
-
it
|
43
|
+
context '[mock only]' do
|
44
|
+
it 'ignores positive timeouts and returns nil' do
|
45
45
|
@redises.mock.brpop('mock-redis-test:not-here', :timeout => 1).should be_nil
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it 'ignores positive legacy timeouts and returns nil' do
|
49
49
|
@redises.mock.brpop('mock-redis-test:not-here', 1).should be_nil
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
52
|
+
it 'raises WouldBlock on zero timeout (no blocking in the mock)' do
|
53
53
|
lambda do
|
54
54
|
@redises.mock.brpop('mock-redis-test:not-here', :timeout => 0)
|
55
55
|
end.should raise_error(MockRedis::WouldBlock)
|
@@ -14,36 +14,36 @@ describe '#brpoplpush(source, destination, timeout)' do
|
|
14
14
|
@redises.rpush(@list2, 'beta')
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'takes the last element of source and prepends it to destination' do
|
18
18
|
@redises.brpoplpush(@list1, @list2)
|
19
19
|
@redises.lrange(@list1, 0, -1).should == %w[A]
|
20
20
|
@redises.lrange(@list2, 0, -1).should == %w[B alpha beta]
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
@redises.brpoplpush(@list1, @list2).should ==
|
23
|
+
it 'returns the moved element' do
|
24
|
+
@redises.brpoplpush(@list1, @list2).should == 'B'
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'raises an error on negative timeout' do
|
28
28
|
lambda do
|
29
29
|
@redises.brpoplpush(@list1, @list2, :timeout => -1)
|
30
30
|
end.should raise_error(Redis::CommandError)
|
31
31
|
end
|
32
32
|
|
33
|
-
it_should_behave_like
|
33
|
+
it_should_behave_like 'a list-only command'
|
34
34
|
|
35
|
-
context
|
36
|
-
it
|
35
|
+
context '[mock only]' do
|
36
|
+
it 'ignores positive timeouts and returns nil' do
|
37
37
|
@redises.mock.brpoplpush('mock-redis-test:not-here', @list1, :timeout => 1).
|
38
38
|
should be_nil
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it 'ignores positive legacy timeouts and returns nil' do
|
42
42
|
@redises.mock.brpoplpush('mock-redis-test:not-here', @list1, 1).
|
43
43
|
should be_nil
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
46
|
+
it 'raises WouldBlock on zero timeout (no blocking in the mock)' do
|
47
47
|
lambda do
|
48
48
|
@redises.mock.brpoplpush('mock-redis-test:not-here', @list1, :timeout => 0)
|
49
49
|
end.should raise_error(MockRedis::WouldBlock)
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#dbsize [mock only]' do
|
4
4
|
# mock only since we can't guarantee that the real Redis is empty
|
5
5
|
before { @mock = @redises.mock }
|
6
6
|
|
7
|
-
it
|
7
|
+
it 'returns 0 for an empty DB' do
|
8
8
|
@mock.dbsize.should == 0
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'returns the number of keys in the DB' do
|
12
12
|
@mock.set('foo', 1)
|
13
13
|
@mock.lpush('bar', 2)
|
14
14
|
@mock.hset('baz', 3, 4)
|
data/spec/commands/decr_spec.rb
CHANGED
@@ -3,32 +3,32 @@ require 'spec_helper'
|
|
3
3
|
describe '#decr(key)' do
|
4
4
|
before { @key = 'mock-redis-test:46895' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns the value after the decrement' do
|
7
7
|
@redises.set(@key, 2)
|
8
8
|
@redises.decr(@key).should == 1
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'treats a missing key like 0' do
|
12
12
|
@redises.decr(@key).should == -1
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'decrements negative numbers' do
|
16
16
|
@redises.set(@key, -10)
|
17
17
|
@redises.decr(@key).should == -11
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'works multiple times' do
|
21
21
|
@redises.decr(@key).should == -1
|
22
22
|
@redises.decr(@key).should == -2
|
23
23
|
@redises.decr(@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, 'minus one')
|
28
28
|
lambda do
|
29
29
|
@redises.decr(@key)
|
30
30
|
end.should raise_error(RuntimeError)
|
31
31
|
end
|
32
32
|
|
33
|
-
it_should_behave_like
|
33
|
+
it_should_behave_like 'a string-only command'
|
34
34
|
end
|
@@ -3,32 +3,32 @@ require 'spec_helper'
|
|
3
3
|
describe '#decrby(key, decrement)' do
|
4
4
|
before { @key = 'mock-redis-test:43650' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns the value after the decrement' do
|
7
7
|
@redises.set(@key, 4)
|
8
8
|
@redises.decrby(@key, 2).should == 2
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'treats a missing key like 0' do
|
12
12
|
@redises.decrby(@key, 2).should == -2
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'decrements negative numbers' do
|
16
16
|
@redises.set(@key, -10)
|
17
17
|
@redises.decrby(@key, 2).should == -12
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'works multiple times' do
|
21
21
|
@redises.decrby(@key, 2).should == -2
|
22
22
|
@redises.decrby(@key, 2).should == -4
|
23
23
|
@redises.decrby(@key, 2).should == -6
|
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.decrby(@key, 1)
|
30
30
|
end.should raise_error(RuntimeError)
|
31
31
|
end
|
32
32
|
|
33
|
-
it_should_behave_like
|
33
|
+
it_should_behave_like 'a string-only command'
|
34
34
|
end
|
data/spec/commands/del_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe '#del(key [, key, ...])' do
|
4
|
-
it
|
4
|
+
it 'returns the number of keys deleted' do
|
5
5
|
@redises.set('mock-redis-test:1', 1)
|
6
6
|
@redises.set('mock-redis-test:2', 1)
|
7
7
|
|
@@ -11,14 +11,14 @@ describe '#del(key [, key, ...])' do
|
|
11
11
|
'mock-redis-test:other').should == 2
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'actually removes the key' do
|
15
15
|
@redises.set('mock-redis-test:1', 1)
|
16
16
|
@redises.del('mock-redis-test:1')
|
17
17
|
|
18
18
|
@redises.get('mock-redis-test:1').should be_nil
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it 'accepts an array of keys' do
|
22
22
|
@redises.set('mock-redis-test:1', 1)
|
23
23
|
@redises.set('mock-redis-test:2', 2)
|
24
24
|
|
@@ -28,7 +28,7 @@ describe '#del(key [, key, ...])' do
|
|
28
28
|
@redises.get('mock-redis-test:2').should be_nil
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'raises an error if an empty array is given' do
|
32
32
|
expect { @redises.del [] }.to raise_error Redis::CommandError
|
33
33
|
end
|
34
34
|
end
|
data/spec/commands/echo_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
it
|
3
|
+
describe '#echo(str)' do
|
4
|
+
it 'returns its argument' do
|
5
5
|
@redises.echo('foo').should == 'foo'
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
9
|
-
@redises.echo(1).should ==
|
8
|
+
it 'stringifies its argument' do
|
9
|
+
@redises.echo(1).should == '1'
|
10
10
|
end
|
11
11
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#exists(key)' do
|
4
4
|
before { @key = 'mock-redis-test:45794' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns false for keys that do not exist' do
|
7
7
|
@redises.exists(@key).should == false
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
10
|
+
it 'returns true for keys that do exist' do
|
11
11
|
@redises.set(@key, 1)
|
12
12
|
@redises.exists(@key).should == true
|
13
13
|
end
|
@@ -1,35 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#expire(key, seconds)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:expire'
|
6
6
|
@redises.set(@key, 'spork')
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'returns true for a key that exists' do
|
10
10
|
@redises.expire(@key, 1).should == true
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'returns false for a key that does not exist' do
|
14
14
|
@redises.expire('mock-redis-test:nonesuch', 1).should == false
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'removes a key immediately when seconds==0' do
|
18
18
|
@redises.expire(@key, 0)
|
19
19
|
@redises.get(@key).should be_nil
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'raises an error if seconds is bogus' do
|
23
23
|
lambda do
|
24
24
|
@redises.expireat(@key, 'a couple minutes or so')
|
25
25
|
end.should raise_error(RuntimeError)
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it 'stringifies key' do
|
29
29
|
@redises.expire(@key.to_sym, 9).should == true
|
30
30
|
end
|
31
31
|
|
32
|
-
context
|
32
|
+
context '[mock only]' do
|
33
33
|
# These are mock-only since we can't actually manipulate time in
|
34
34
|
# the real Redis.
|
35
35
|
|
@@ -42,13 +42,13 @@ describe "#expire(key, seconds)" do
|
|
42
42
|
Time.stub(:now).and_return(@now)
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it 'removes keys after enough time has passed' do
|
46
46
|
@mock.expire(@key, 5)
|
47
47
|
Time.stub(:now).and_return(@now + 5)
|
48
48
|
@mock.get(@key).should be_nil
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it 'updates an existing expire time' do
|
52
52
|
@mock.expire(@key, 5)
|
53
53
|
@mock.expire(@key, 6)
|
54
54
|
|
@@ -56,7 +56,7 @@ describe "#expire(key, seconds)" do
|
|
56
56
|
@mock.get(@key).should_not be_nil
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
59
|
+
it 'has millisecond precision' do
|
60
60
|
@now = Time.at(@now.to_i + 0.5)
|
61
61
|
Time.stub(:now).and_return(@now)
|
62
62
|
@mock.expire(@key, 5)
|
@@ -64,10 +64,10 @@ describe "#expire(key, seconds)" do
|
|
64
64
|
@mock.get(@key).should_not be_nil
|
65
65
|
end
|
66
66
|
|
67
|
-
context
|
67
|
+
context 'expirations on a deleted key' do
|
68
68
|
before { @mock.del(@key) }
|
69
69
|
|
70
|
-
it
|
70
|
+
it 'cleans up the expiration once the key is gone (string)' do
|
71
71
|
@mock.set(@key, 'string')
|
72
72
|
@mock.expire(@key, 2)
|
73
73
|
@mock.del(@key)
|
@@ -78,7 +78,7 @@ describe "#expire(key, seconds)" do
|
|
78
78
|
@mock.get(@key).should_not be_nil
|
79
79
|
end
|
80
80
|
|
81
|
-
it
|
81
|
+
it 'cleans up the expiration once the key is gone (list)' do
|
82
82
|
@mock.rpush(@key, 'coconuts')
|
83
83
|
@mock.expire(@key, 2)
|
84
84
|
@mock.rpop(@key)
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#expireat(key, timestamp)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:expireat'
|
6
6
|
@redises.set(@key, 'spork')
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'returns true for a key that exists' do
|
10
10
|
@redises.expireat(@key, Time.now.to_i + 1).should == true
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'returns false for a key that does not exist' do
|
14
14
|
@redises.expireat('mock-redis-test:nonesuch', Time.now.to_i + 1).should == false
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'removes a key immediately when timestamp is now' do
|
18
18
|
@redises.expireat(@key, Time.now.to_i)
|
19
19
|
@redises.get(@key).should be_nil
|
20
20
|
end
|
@@ -25,7 +25,7 @@ describe "#expireat(key, timestamp)" do
|
|
25
25
|
end.should raise_error(RuntimeError)
|
26
26
|
end
|
27
27
|
|
28
|
-
context
|
28
|
+
context '[mock only]' do
|
29
29
|
# These are mock-only since we can't actually manipulate time in
|
30
30
|
# the real Redis.
|
31
31
|
|
@@ -38,11 +38,10 @@ describe "#expireat(key, timestamp)" do
|
|
38
38
|
Time.stub(:now).and_return(@now)
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it 'removes keys after enough time has passed' do
|
42
42
|
@mock.expireat(@key, @now.to_i + 5)
|
43
43
|
Time.stub(:now).and_return(@now + 5)
|
44
44
|
@mock.get(@key).should be_nil
|
45
45
|
end
|
46
|
-
|
47
46
|
end
|
48
47
|
end
|