mock_redis 0.20.0 → 0.21.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 +8 -0
- data/lib/mock_redis.rb +3 -1
- data/lib/mock_redis/database.rb +14 -6
- data/lib/mock_redis/hash_methods.rb +4 -8
- data/lib/mock_redis/set_methods.rb +1 -0
- data/lib/mock_redis/string_methods.rb +12 -5
- data/lib/mock_redis/version.rb +1 -1
- data/spec/client_spec.rb +12 -0
- data/spec/commands/hdel_spec.rb +16 -0
- data/spec/commands/set_spec.rb +6 -0
- data/spec/commands/srem_spec.rb +5 -0
- data/spec/mock_redis_spec.rb +4 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4443d90955b31a149afd0c66972a06993bf9b01f6bd826276c2d60edb49b3141
|
4
|
+
data.tar.gz: 2d096c0b7438b81720adcd50ecb36a8fa19df7a05c822ed4beee6d06d459f1b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdcb30c9756e77fcc4f857f0bdaa01d73faa28b8ea7cc37aa669c0f5cf2e2967d3e216a32ff50c7c78f6945b313f8525073060daf9f980187d566202f3dbcda2
|
7
|
+
data.tar.gz: 17502b628f1a5a62fa2046b529ef0178d8b84453d3a8b83441e3f2eef72282d45a79e60bee34e9a871ea553deb08c1c286b915d4b2c6ffe52fab3e6e32a6cc56
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# MockRedis Changelog
|
2
2
|
|
3
|
+
### 0.21.0
|
4
|
+
|
5
|
+
* Fix behavior of `time` to return array of two integers ([#161](https://github.com/sds/mock_redis/pull/161))
|
6
|
+
* Add support for `close` and `disconnect!` ([#163](https://github.com/sds/mock_redis/pull/163))
|
7
|
+
* Fix `set` to properly handle (and ignore) other options ([#164](https://github.com/sds/mock_redis/pull/163))
|
8
|
+
* Fix `srem` to allow array of integers as argument ([#166](https://github.com/sds/mock_redis/pull/166))
|
9
|
+
* Fix `hdel` to allow array as argument ([#168](https://github.com/sds/mock_redis/pull/168))
|
10
|
+
|
3
11
|
### 0.20.0
|
4
12
|
|
5
13
|
* Add support for `count` parameter of `spop`
|
data/lib/mock_redis.rb
CHANGED
data/lib/mock_redis/database.rb
CHANGED
@@ -56,6 +56,8 @@ class MockRedis
|
|
56
56
|
def disconnect
|
57
57
|
nil
|
58
58
|
end
|
59
|
+
alias close disconnect
|
60
|
+
alias disconnect! close
|
59
61
|
|
60
62
|
def connected?
|
61
63
|
true
|
@@ -86,7 +88,8 @@ class MockRedis
|
|
86
88
|
end
|
87
89
|
|
88
90
|
def pexpire(key, ms)
|
89
|
-
|
91
|
+
now, miliseconds = @base.now
|
92
|
+
now_ms = (now * 1000) + miliseconds
|
90
93
|
pexpireat(key, now_ms + ms.to_i)
|
91
94
|
end
|
92
95
|
|
@@ -140,7 +143,7 @@ class MockRedis
|
|
140
143
|
end
|
141
144
|
|
142
145
|
def lastsave
|
143
|
-
@base.now.
|
146
|
+
@base.now.first
|
144
147
|
end
|
145
148
|
|
146
149
|
def persist(key)
|
@@ -201,17 +204,21 @@ class MockRedis
|
|
201
204
|
if !exists(key)
|
202
205
|
-2
|
203
206
|
elsif has_expiration?(key)
|
204
|
-
|
207
|
+
now, = @base.now
|
208
|
+
expiration(key).to_i - now
|
205
209
|
else
|
206
210
|
-1
|
207
211
|
end
|
208
212
|
end
|
209
213
|
|
210
214
|
def pttl(key)
|
215
|
+
now, miliseconds = @base.now
|
216
|
+
now_ms = now * 1000 + miliseconds
|
217
|
+
|
211
218
|
if !exists(key)
|
212
219
|
-2
|
213
220
|
elsif has_expiration?(key)
|
214
|
-
(expiration(key).to_r * 1000).to_i -
|
221
|
+
(expiration(key).to_r * 1000).to_i - now_ms
|
215
222
|
else
|
216
223
|
-1
|
217
224
|
end
|
@@ -321,10 +328,11 @@ class MockRedis
|
|
321
328
|
# This method isn't private, but it also isn't a Redis command, so
|
322
329
|
# it doesn't belong up above with all the Redis commands.
|
323
330
|
def expire_keys
|
324
|
-
now = @base.now
|
331
|
+
now, miliseconds = @base.now
|
332
|
+
now_ms = now * 1_000 + miliseconds
|
325
333
|
|
326
334
|
to_delete = expire_times.take_while do |(time, _key)|
|
327
|
-
(time.to_r * 1_000).to_i <=
|
335
|
+
(time.to_r * 1_000).to_i <= now_ms
|
328
336
|
end
|
329
337
|
|
330
338
|
to_delete.each do |(_time, key)|
|
@@ -8,14 +8,10 @@ class MockRedis
|
|
8
8
|
|
9
9
|
def hdel(key, *fields)
|
10
10
|
with_hash_at(key) do |hash|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
orig_size - hash.size
|
16
|
-
else
|
17
|
-
hash.delete(fields[0].to_s) ? 1 : 0
|
18
|
-
end
|
11
|
+
orig_size = hash.size
|
12
|
+
fields = Array(fields).flatten.map(&:to_s)
|
13
|
+
hash.delete_if { |k, _v| fields.include?(k) }
|
14
|
+
orig_size - hash.size
|
19
15
|
end
|
20
16
|
end
|
21
17
|
|
@@ -220,15 +220,22 @@ class MockRedis
|
|
220
220
|
end
|
221
221
|
data[key] = value.to_s
|
222
222
|
|
223
|
-
|
224
|
-
|
225
|
-
if expire_option
|
226
|
-
type, duration = expire_option
|
223
|
+
duration = options.delete(:ex)
|
224
|
+
if duration
|
227
225
|
if duration == 0
|
228
226
|
raise Redis::CommandError, 'ERR invalid expire time in set'
|
229
227
|
end
|
230
|
-
expire(key,
|
228
|
+
expire(key, duration)
|
231
229
|
end
|
230
|
+
|
231
|
+
duration = options.delete(:px)
|
232
|
+
if duration
|
233
|
+
if duration == 0
|
234
|
+
raise Redis::CommandError, 'ERR invalid expire time in set'
|
235
|
+
end
|
236
|
+
expire(key, duration / 1000.0)
|
237
|
+
end
|
238
|
+
|
232
239
|
return_true ? true : 'OK'
|
233
240
|
end
|
234
241
|
|
data/lib/mock_redis/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -14,4 +14,16 @@ describe 'client' do
|
|
14
14
|
redis.connect.should == redis
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
context '#disconnect!' do
|
19
|
+
it 'responds to disconnect!' do
|
20
|
+
expect(MockRedis.new).to respond_to(:disconnect!)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context '#close' do
|
25
|
+
it 'responds to close' do
|
26
|
+
expect(MockRedis.new).to respond_to(:close)
|
27
|
+
end
|
28
|
+
end
|
17
29
|
end
|
data/spec/commands/hdel_spec.rb
CHANGED
@@ -50,5 +50,21 @@ describe '#hdel(key, field)' do
|
|
50
50
|
@redises.hget(@key, field).should be_nil
|
51
51
|
end
|
52
52
|
|
53
|
+
it 'supports a variable number of fields as array' do
|
54
|
+
@redises.hdel(@key, %w[k1 k2]).should == 2
|
55
|
+
|
56
|
+
@redises.hget(@key, 'k1').should be_nil
|
57
|
+
@redises.hget(@key, 'k2').should be_nil
|
58
|
+
@redises.get(@key).should be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'supports a list of fields in various way' do
|
62
|
+
@redises.hdel(@key, ['k1'], 'k2').should == 2
|
63
|
+
|
64
|
+
@redises.hget(@key, 'k1').should be_nil
|
65
|
+
@redises.hget(@key, 'k2').should be_nil
|
66
|
+
@redises.get(@key).should be_nil
|
67
|
+
end
|
68
|
+
|
53
69
|
it_should_behave_like 'a hash-only command'
|
54
70
|
end
|
data/spec/commands/set_spec.rb
CHANGED
@@ -33,6 +33,12 @@ describe '#set(key, value)' do
|
|
33
33
|
@redises.set(key, 1, xx: true).should == true
|
34
34
|
end
|
35
35
|
|
36
|
+
it 'ignores other options' do
|
37
|
+
key = 'mock-redis-test'
|
38
|
+
@redises.del(key)
|
39
|
+
@redises.set(key, 1, logger: :something).should == 'OK'
|
40
|
+
end
|
41
|
+
|
36
42
|
context '[mock only]' do
|
37
43
|
before(:all) do
|
38
44
|
@mock = @redises.mock
|
data/spec/commands/srem_spec.rb
CHANGED
@@ -36,5 +36,10 @@ describe '#srem(key, member)' do
|
|
36
36
|
@redises.get(@key).should be_nil
|
37
37
|
end
|
38
38
|
|
39
|
+
it 'allow passing an array of integers as argument' do
|
40
|
+
@redises.sadd(@key, %w[1 2])
|
41
|
+
@redises.srem(@key, [1, 2]).should == 2
|
42
|
+
end
|
43
|
+
|
39
44
|
it_should_behave_like 'a set-only command'
|
40
45
|
end
|
data/spec/mock_redis_spec.rb
CHANGED
@@ -49,23 +49,21 @@ describe MockRedis do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
describe '.now' do
|
52
|
-
let(:
|
53
|
-
let(:time_stub) { double 'Time', :now => now }
|
52
|
+
let(:time_stub) { double 'Time', :now => Time.new(2019, 1, 2, 3, 4, 6, '+00:00') }
|
54
53
|
let(:options) { { :time_class => time_stub } }
|
55
54
|
|
56
55
|
subject { MockRedis.new(options) }
|
57
56
|
|
58
|
-
its(:now) { should ==
|
57
|
+
its(:now) { should == [1_546_398_246, 0] }
|
59
58
|
end
|
60
59
|
|
61
60
|
describe '.time' do
|
62
|
-
let(:
|
63
|
-
let(:time_stub) { double 'Time', :now => now }
|
61
|
+
let(:time_stub) { double 'Time', :now => Time.new(2019, 1, 2, 3, 4, 6, '+00:00') }
|
64
62
|
let(:options) { { :time_class => time_stub } }
|
65
63
|
|
66
64
|
subject { MockRedis.new(options) }
|
67
65
|
|
68
|
-
its(:time) { should ==
|
66
|
+
its(:time) { should == [1_546_398_246, 0] }
|
69
67
|
end
|
70
68
|
|
71
69
|
describe '.expireat' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane da Silva
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|