mock_redis 0.14.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -11,12 +11,12 @@ describe '#mapped_mget(*keys)' do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'returns a hash' do
|
14
|
-
@redises.mapped_mget(@key1, @key2, @key3).should eq(
|
15
|
-
|
16
|
-
|
14
|
+
@redises.mapped_mget(@key1, @key2, @key3).should eq(@key1 => '1',
|
15
|
+
@key2 => '2',
|
16
|
+
@key3 => nil)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'returns a hash even when no matches' do
|
20
|
-
@redises.mapped_mget('qwer').should eq(
|
20
|
+
@redises.mapped_mget('qwer').should eq('qwer' => nil)
|
21
21
|
end
|
22
22
|
end
|
@@ -11,7 +11,7 @@ describe '#mapped_mset(hash)' do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'sets the values properly' do
|
14
|
-
@redises.mapped_mset(
|
14
|
+
@redises.mapped_mset(@key1 => 'one', @key3 => 'three').should eq('OK')
|
15
15
|
@redises.get(@key1).should eq('one')
|
16
16
|
@redises.get(@key2).should eq('2') # left alone
|
17
17
|
@redises.get(@key3).should eq('three')
|
data/spec/commands/mget_spec.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#mget(key [, key, ...])' do
|
4
4
|
before do
|
5
|
-
@key1 =
|
6
|
-
@key2 =
|
5
|
+
@key1 = 'mock-redis-test:mget1'
|
6
|
+
@key2 = 'mock-redis-test:mget2'
|
7
7
|
|
8
8
|
@redises.set(@key1, 1)
|
9
9
|
@redises.set(@key2, 2)
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'returns an array of values' do
|
13
13
|
@redises.mget(@key1, @key2).should == %w[1 2]
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'returns nil for missing keys' do
|
17
17
|
@redises.mget(@key1, 'mock-redis-test:not-found', @key2).
|
18
|
-
should == [
|
18
|
+
should == ['1', nil, '2']
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
list =
|
21
|
+
it 'returns nil for non-string keys' do
|
22
|
+
list = 'mock-redis-test:mget-list'
|
23
23
|
|
24
24
|
@redises.lpush(list, 'bork bork bork')
|
25
25
|
|
26
|
-
@redises.mget(@key1, @key2, list).should == [
|
26
|
+
@redises.mget(@key1, @key2, list).should == ['1', '2', nil]
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'raises an error if you pass it 0 arguments' do
|
30
30
|
lambda do
|
31
|
-
@redises.mget
|
31
|
+
@redises.mget
|
32
32
|
end.should raise_error(RuntimeError)
|
33
33
|
end
|
34
34
|
end
|
data/spec/commands/move_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe '#move(key, db)' do
|
|
8
8
|
@key = 'mock-redis-test:move'
|
9
9
|
end
|
10
10
|
|
11
|
-
context
|
11
|
+
context 'when key exists in destdb' do
|
12
12
|
before do
|
13
13
|
@redises.set(@key, 'srcvalue')
|
14
14
|
@redises.select(@destdb)
|
@@ -16,81 +16,81 @@ describe '#move(key, db)' do
|
|
16
16
|
@redises.select(@srcdb)
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'returns false' do
|
20
20
|
@redises.move(@key, @destdb).should == false
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
23
|
+
it 'leaves destdb/key alone' do
|
24
24
|
@redises.select(@destdb)
|
25
|
-
@redises.get(@key).should ==
|
25
|
+
@redises.get(@key).should == 'destvalue'
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
29
|
-
@redises.get(@key).should ==
|
28
|
+
it 'leaves srcdb/key alone' do
|
29
|
+
@redises.get(@key).should == 'srcvalue'
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
context
|
33
|
+
context 'when key does not exist in srcdb' do
|
34
34
|
before do
|
35
35
|
@redises.select(@destdb)
|
36
36
|
@redises.set(@key, 'destvalue')
|
37
37
|
@redises.select(@srcdb)
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'returns false' do
|
41
41
|
@redises.move(@key, @destdb).should == false
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
44
|
+
it 'leaves destdb/key alone' do
|
45
45
|
@redises.select(@destdb)
|
46
|
-
@redises.get(@key).should ==
|
46
|
+
@redises.get(@key).should == 'destvalue'
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
context
|
50
|
+
context 'when key exists in the currently-selected DB and not in db' do
|
51
51
|
before do
|
52
52
|
@redises.set(@key, 'value')
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
55
|
+
it 'returns true' do
|
56
56
|
@redises.move(@key, @destdb).should == true
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
context
|
60
|
+
context 'on a string' do
|
61
61
|
before do
|
62
62
|
@redises.set(@key, 'value')
|
63
63
|
@redises.move(@key, @destdb)
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
66
|
+
it 'removes key from srcdb' do
|
67
67
|
@redises.exists(@key).should == false
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
70
|
+
it 'copies key to destdb' do
|
71
71
|
@redises.select(@destdb)
|
72
72
|
@redises.get(@key).should == 'value'
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
context
|
76
|
+
context 'on a list' do
|
77
77
|
before do
|
78
78
|
@redises.rpush(@key, 'bert')
|
79
79
|
@redises.rpush(@key, 'ernie')
|
80
80
|
@redises.move(@key, @destdb)
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
83
|
+
it 'removes key from srcdb' do
|
84
84
|
@redises.exists(@key).should == false
|
85
85
|
end
|
86
86
|
|
87
|
-
it
|
87
|
+
it 'copies key to destdb' do
|
88
88
|
@redises.select(@destdb)
|
89
89
|
@redises.lrange(@key, 0, -1).should == %w[bert ernie]
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
context
|
93
|
+
context 'on a hash' do
|
94
94
|
before do
|
95
95
|
@redises.hset(@key, 'a', 1)
|
96
96
|
@redises.hset(@key, 'b', 2)
|
@@ -98,17 +98,17 @@ describe '#move(key, db)' do
|
|
98
98
|
@redises.move(@key, @destdb)
|
99
99
|
end
|
100
100
|
|
101
|
-
it
|
101
|
+
it 'removes key from srcdb' do
|
102
102
|
@redises.exists(@key).should == false
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
105
|
+
it 'copies key to destdb' do
|
106
106
|
@redises.select(@destdb)
|
107
|
-
@redises.hgetall(@key).should == {'a' =>
|
107
|
+
@redises.hgetall(@key).should == { 'a' => '1', 'b' => '2' }
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
context
|
111
|
+
context 'on a set' do
|
112
112
|
before do
|
113
113
|
@redises.sadd(@key, 'beer')
|
114
114
|
@redises.sadd(@key, 'wine')
|
@@ -116,17 +116,17 @@ describe '#move(key, db)' do
|
|
116
116
|
@redises.move(@key, @destdb)
|
117
117
|
end
|
118
118
|
|
119
|
-
it
|
119
|
+
it 'removes key from srcdb' do
|
120
120
|
@redises.exists(@key).should == false
|
121
121
|
end
|
122
122
|
|
123
|
-
it
|
123
|
+
it 'copies key to destdb' do
|
124
124
|
@redises.select(@destdb)
|
125
125
|
@redises.smembers(@key).should == %w[wine beer]
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
context
|
129
|
+
context 'on a zset' do
|
130
130
|
before do
|
131
131
|
@redises.zadd(@key, 1, 'beer')
|
132
132
|
@redises.zadd(@key, 2, 'wine')
|
@@ -134,14 +134,14 @@ describe '#move(key, db)' do
|
|
134
134
|
@redises.move(@key, @destdb)
|
135
135
|
end
|
136
136
|
|
137
|
-
it
|
137
|
+
it 'removes key from srcdb' do
|
138
138
|
@redises.exists(@key).should == false
|
139
139
|
end
|
140
140
|
|
141
|
-
it
|
141
|
+
it 'copies key to destdb' do
|
142
142
|
@redises.select(@destdb)
|
143
143
|
@redises.zrange(@key, 0, -1, :with_scores => true).should ==
|
144
|
-
[[
|
144
|
+
[['beer', 1.0], ['wine', 2.0]]
|
145
145
|
end
|
146
146
|
end
|
147
147
|
end
|
data/spec/commands/mset_spec.rb
CHANGED
@@ -10,20 +10,20 @@ describe '#mset(key, value [, key, value, ...])' do
|
|
10
10
|
@redises.mset(@key1, 1).should == 'OK'
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'sets the values' do
|
14
14
|
@redises.mset(@key1, 'value1', @key2, 'value2')
|
15
15
|
@redises.mget(@key1, @key2).should == %w[value1 value2]
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'raises an error if given an odd number of arguments' do
|
19
19
|
lambda do
|
20
20
|
@redises.mset(@key1, 'value1', @key2)
|
21
21
|
end.should raise_error(RuntimeError)
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'raises an error if given 0 arguments' do
|
25
25
|
lambda do
|
26
|
-
@redises.mset
|
26
|
+
@redises.mset
|
27
27
|
end.should raise_error(RuntimeError)
|
28
28
|
end
|
29
29
|
end
|
@@ -6,35 +6,35 @@ describe '#msetnx(key, value [, key, value, ...])' do
|
|
6
6
|
@key2 = 'mock-redis-test:msetnx2'
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'responds with 1 if any keys were set' do
|
10
10
|
@redises.msetnx(@key1, 1).should == true
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'sets the values' do
|
14
14
|
@redises.msetnx(@key1, 'value1', @key2, 'value2')
|
15
15
|
@redises.mget(@key1, @key2).should == %w[value1 value2]
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
@redises.set(@key1,
|
18
|
+
it 'does nothing if any value is already set' do
|
19
|
+
@redises.set(@key1, 'old1')
|
20
20
|
@redises.msetnx(@key1, 'value1', @key2, 'value2')
|
21
|
-
@redises.mget(@key1, @key2).should == [
|
21
|
+
@redises.mget(@key1, @key2).should == ['old1', nil]
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
@redises.set(@key1,
|
24
|
+
it 'responds with 0 if any value is already set' do
|
25
|
+
@redises.set(@key1, 'old1')
|
26
26
|
@redises.msetnx(@key1, 'value1', @key2, 'value2').should == false
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'raises an error if given an odd number of arguments' do
|
30
30
|
lambda do
|
31
31
|
@redises.msetnx(@key1, 'value1', @key2)
|
32
32
|
end.should raise_error(RuntimeError)
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'raises an error if given 0 arguments' do
|
36
36
|
lambda do
|
37
|
-
@redises.msetnx
|
37
|
+
@redises.msetnx
|
38
38
|
end.should raise_error(RuntimeError)
|
39
39
|
end
|
40
40
|
end
|
@@ -1,31 +1,31 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#persist(key)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:persist'
|
6
6
|
@redises.set(@key, 'spork')
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
10
|
-
@redises.expire(@key,
|
9
|
+
it 'returns true for a key with a timeout' do
|
10
|
+
@redises.expire(@key, 10_000)
|
11
11
|
@redises.persist(@key).should == true
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'returns false for a key with no timeout' do
|
15
15
|
@redises.persist(@key).should == false
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'returns false for a key that does not exist' do
|
19
19
|
@redises.persist('mock-redis-test:nonesuch').should == false
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
@redises.expire(@key,
|
22
|
+
it 'removes the timeout' do
|
23
|
+
@redises.expire(@key, 10_000)
|
24
24
|
@redises.persist(@key)
|
25
25
|
@redises.persist(@key).should == false
|
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,12 +38,11 @@ describe "#persist(key)" do
|
|
38
38
|
Time.stub(:now).and_return(@now)
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it 'makes keys stay around' do
|
42
42
|
@mock.expire(@key, 5)
|
43
43
|
@mock.persist(@key)
|
44
44
|
Time.stub(:now).and_return(@now + 5)
|
45
45
|
@mock.get(@key).should_not be_nil
|
46
46
|
end
|
47
|
-
|
48
47
|
end
|
49
48
|
end
|
@@ -1,35 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#pexpire(key, ms)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:pexpire'
|
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.pexpire(@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.pexpire('mock-redis-test:nonesuch', 1).should == false
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'removes a key immediately when ms==0' do
|
18
18
|
@redises.pexpire(@key, 0)
|
19
19
|
@redises.get(@key).should be_nil
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'raises an error if ms is bogus' do
|
23
23
|
lambda do
|
24
24
|
@redises.pexpireat(@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.pexpire(@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 "#pexpire(key, ms)" 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.pexpire(@key, 5)
|
47
47
|
Time.stub(:now).and_return(@now + Rational(6, 1000))
|
48
48
|
@mock.get(@key).should be_nil
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it 'updates an existing pexpire time' do
|
52
52
|
@mock.pexpire(@key, 5)
|
53
53
|
@mock.pexpire(@key, 6)
|
54
54
|
|
@@ -56,10 +56,10 @@ describe "#pexpire(key, ms)" do
|
|
56
56
|
@mock.get(@key).should_not be_nil
|
57
57
|
end
|
58
58
|
|
59
|
-
context
|
59
|
+
context 'expirations on a deleted key' do
|
60
60
|
before { @mock.del(@key) }
|
61
61
|
|
62
|
-
it
|
62
|
+
it 'cleans up the expiration once the key is gone (string)' do
|
63
63
|
@mock.set(@key, 'string')
|
64
64
|
@mock.pexpire(@key, 2)
|
65
65
|
@mock.del(@key)
|
@@ -70,7 +70,7 @@ describe "#pexpire(key, ms)" do
|
|
70
70
|
@mock.get(@key).should_not be_nil
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
73
|
+
it 'cleans up the expiration once the key is gone (list)' do
|
74
74
|
@mock.rpush(@key, 'coconuts')
|
75
75
|
@mock.pexpire(@key, 2)
|
76
76
|
@mock.rpop(@key)
|
@@ -82,6 +82,5 @@ describe "#pexpire(key, ms)" do
|
|
82
82
|
@mock.lindex(@key, 0).should_not be_nil
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
86
85
|
end
|
87
86
|
end
|