mock_redis 0.30.0 → 0.33.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/.github/workflows/tests.yml +18 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +2 -1
- data/README.md +1 -1
- data/lib/mock_redis/database.rb +3 -3
- data/lib/mock_redis/hash_methods.rb +3 -1
- data/lib/mock_redis/string_methods.rb +18 -2
- data/lib/mock_redis/version.rb +1 -1
- data/mock_redis.gemspec +1 -1
- data/spec/commands/del_spec.rb +1 -1
- data/spec/commands/expire_spec.rb +1 -1
- data/spec/commands/hmget_spec.rb +6 -0
- data/spec/commands/lpop_spec.rb +1 -0
- data/spec/commands/pexpire_spec.rb +1 -1
- data/spec/commands/ping_spec.rb +5 -1
- data/spec/commands/psetex_spec.rb +44 -0
- data/spec/commands/rpop_spec.rb +1 -0
- data/spec/commands/set_spec.rb +15 -0
- data/spec/spec_helper.rb +18 -9
- data/spec/support/shared_examples/does_not_cleanup_empty_strings.rb +1 -1
- data/spec/support/shared_examples/only_operates_on_lists.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 764d3b747c037b933788f2d4ef01e581ecb509aa8c3e445d12c27d199d2273fe
|
4
|
+
data.tar.gz: 9093a8b7601c57e746dd38d7708c52474df56247ea0910ca4d8d7bcecca9506e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7ef20dba317c18d0ab4de7d5d0a87107512cb2398c7d9c549a603a1980fbced844c7b98c547db32fb905a32ed68cdfa25ba9331b03a91512c8c1d1f6d45551a
|
7
|
+
data.tar.gz: 29570271c68cf37d7fd09c065cdad79e1ac64e9b1aa3bdb28dbf0d2080983cc758ad4632e13ad132d492dc823afef8dd7a7a9cec14dfbefb6a7e49a840c74c8c
|
data/.github/workflows/tests.yml
CHANGED
@@ -43,3 +43,21 @@ jobs:
|
|
43
43
|
|
44
44
|
- name: Run tests
|
45
45
|
run: bundle exec rspec
|
46
|
+
|
47
|
+
- name: Code coverage reporting
|
48
|
+
uses: coverallsapp/github-action@master
|
49
|
+
with:
|
50
|
+
github-token: ${{ secrets.github_token }}
|
51
|
+
flag-name: ruby${{ matrix.ruby-version }}-${{ matrix.redis-version }}
|
52
|
+
parallel: true
|
53
|
+
|
54
|
+
finish:
|
55
|
+
needs: rspec
|
56
|
+
runs-on: ubuntu-latest
|
57
|
+
|
58
|
+
steps:
|
59
|
+
- name: Finalize code coverage report
|
60
|
+
uses: coverallsapp/github-action@master
|
61
|
+
with:
|
62
|
+
github-token: ${{ secrets.github_token }}
|
63
|
+
parallel-finished: true
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# MockRedis Changelog
|
2
2
|
|
3
|
+
### 0.33.0
|
4
|
+
|
5
|
+
* Add support for `GET` argument to `SET` command
|
6
|
+
|
7
|
+
### 0.32.0
|
8
|
+
|
9
|
+
* Add support for `psetex`
|
10
|
+
|
11
|
+
### 0.31.0
|
12
|
+
|
13
|
+
* Allow `ping` to take argument
|
14
|
+
* Raise `CommandError` on `hmget` with empty list of fields
|
15
|
+
|
3
16
|
### 0.30.0
|
4
17
|
|
5
18
|
* Drop support for Ruby 2.4 and Ruby 2.5 since they are EOL
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# MockRedis
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/mock_redis)
|
4
|
-
|
4
|
+

|
5
5
|
[](https://coveralls.io/r/sds/mock_redis)
|
6
6
|
|
7
7
|
MockRedis provides the same interface as `redis-rb`, but it stores its
|
data/lib/mock_redis/database.rb
CHANGED
@@ -71,7 +71,7 @@ class MockRedis
|
|
71
71
|
|
72
72
|
def del(*keys)
|
73
73
|
keys = keys.flatten.map(&:to_s)
|
74
|
-
assert_has_args(keys, 'del')
|
74
|
+
# assert_has_args(keys, 'del') # no longer errors in redis > v4.5
|
75
75
|
|
76
76
|
keys.
|
77
77
|
find_all { |key| data[key] }.
|
@@ -178,8 +178,8 @@ class MockRedis
|
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
|
-
def ping
|
182
|
-
|
181
|
+
def ping(response = 'PONG')
|
182
|
+
response
|
183
183
|
end
|
184
184
|
|
185
185
|
def quit
|
@@ -206,8 +206,10 @@ class MockRedis
|
|
206
206
|
|
207
207
|
# Parameer list required to ensure the ArgumentError is returned correctly
|
208
208
|
# rubocop:disable Metrics/ParameterLists
|
209
|
-
def set(key, value, ex: nil, px: nil, nx: nil, xx: nil, keepttl: nil)
|
209
|
+
def set(key, value, ex: nil, px: nil, nx: nil, xx: nil, keepttl: nil, get: nil)
|
210
210
|
key = key.to_s
|
211
|
+
retval = self.get(key) if get
|
212
|
+
|
211
213
|
return_true = false
|
212
214
|
if nx
|
213
215
|
if exists?(key)
|
@@ -240,7 +242,11 @@ class MockRedis
|
|
240
242
|
pexpire(key, px)
|
241
243
|
end
|
242
244
|
|
243
|
-
|
245
|
+
if get
|
246
|
+
retval
|
247
|
+
else
|
248
|
+
return_true ? true : 'OK'
|
249
|
+
end
|
244
250
|
end
|
245
251
|
# rubocop:enable Metrics/ParameterLists
|
246
252
|
|
@@ -328,6 +334,16 @@ class MockRedis
|
|
328
334
|
end
|
329
335
|
end
|
330
336
|
|
337
|
+
def psetex(key, milliseconds, value)
|
338
|
+
if milliseconds <= 0
|
339
|
+
raise Redis::CommandError, 'ERR invalid expire time in psetex'
|
340
|
+
else
|
341
|
+
set(key, value)
|
342
|
+
pexpire(key, milliseconds)
|
343
|
+
'OK'
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
331
347
|
def setnx(key, value)
|
332
348
|
if exists?(key)
|
333
349
|
false
|
data/lib/mock_redis/version.rb
CHANGED
data/mock_redis.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
|
26
26
|
s.add_runtime_dependency 'ruby2_keywords'
|
27
27
|
|
28
|
-
s.add_development_dependency 'redis', '~> 4.
|
28
|
+
s.add_development_dependency 'redis', '~> 4.5.0'
|
29
29
|
s.add_development_dependency 'rspec', '~> 3.0'
|
30
30
|
s.add_development_dependency 'rspec-its', '~> 1.0'
|
31
31
|
s.add_development_dependency 'timecop', '~> 0.9.1'
|
data/spec/commands/del_spec.rb
CHANGED
@@ -40,7 +40,7 @@ describe '#del(key [, key, ...])' do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'raises an error if an empty array is given' do
|
43
|
-
expect { @redises.del [] }.
|
43
|
+
expect { @redises.del [] }.not_to raise_error Redis::CommandError
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'removes a stream key' do
|
data/spec/commands/hmget_spec.rb
CHANGED
@@ -36,5 +36,11 @@ describe '#hmget(key, field [, field, ...])' do
|
|
36
36
|
end.should raise_error(Redis::CommandError)
|
37
37
|
end
|
38
38
|
|
39
|
+
it 'raises an error if given an empty list of fields' do
|
40
|
+
lambda do
|
41
|
+
@redises.hmget(@key, [])
|
42
|
+
end.should raise_error(Redis::CommandError)
|
43
|
+
end
|
44
|
+
|
39
45
|
it_should_behave_like 'a hash-only command'
|
40
46
|
end
|
data/spec/commands/lpop_spec.rb
CHANGED
data/spec/commands/ping_spec.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#psetex(key, miliseconds, value)' do
|
4
|
+
before { @key = 'mock-redis-test:setex' }
|
5
|
+
|
6
|
+
it "responds with 'OK'" do
|
7
|
+
@redises.psetex(@key, 10, 'value').should == 'OK'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'sets the value' do
|
11
|
+
@redises.psetex(@key, 10_000, 'value')
|
12
|
+
@redises.get(@key).should == 'value'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'sets the expiration time' do
|
16
|
+
@redises.psetex(@key, 10_000, 'value')
|
17
|
+
|
18
|
+
# no guarantee these are the same
|
19
|
+
@redises.real.ttl(@key).should > 0
|
20
|
+
@redises.mock.ttl(@key).should > 0
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'converts time correctly' do
|
24
|
+
@redises.psetex(@key, 10_000_000, 'value')
|
25
|
+
|
26
|
+
@redises.mock.ttl(@key).should > 9_000
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when expiration time is zero' do
|
30
|
+
it 'raises Redis::CommandError' do
|
31
|
+
expect do
|
32
|
+
@redises.psetex(@key, 0, 'value')
|
33
|
+
end.to raise_error(Redis::CommandError, 'ERR invalid expire time in psetex')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when expiration time is negative' do
|
38
|
+
it 'raises Redis::CommandError' do
|
39
|
+
expect do
|
40
|
+
@redises.psetex(@key, -2, 'value')
|
41
|
+
end.to raise_error(Redis::CommandError, 'ERR invalid expire time in psetex')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/commands/rpop_spec.rb
CHANGED
data/spec/commands/set_spec.rb
CHANGED
@@ -33,6 +33,21 @@ describe '#set(key, value)' do
|
|
33
33
|
@redises.set(key, 1, xx: true).should == true
|
34
34
|
end
|
35
35
|
|
36
|
+
it 'accepts GET on a string' do
|
37
|
+
@redises.set(key, '1').should == 'OK'
|
38
|
+
@redises.set(key, '2', get: true).should == '1'
|
39
|
+
@redises.set(key, '3', get: true).should == '2'
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when set key is not a String' do
|
43
|
+
it 'should error with Redis::CommandError' do
|
44
|
+
@redises.lpush(key, '1').should == 1
|
45
|
+
expect do
|
46
|
+
@redises.set(key, '2', get: true)
|
47
|
+
end.to raise_error(Redis::CommandError)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
36
51
|
it 'sets the ttl to -1' do
|
37
52
|
@redises.set(key, 1)
|
38
53
|
expect(@redises.ttl(key)).to eq(-1)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter 'spec/'
|
4
|
+
|
5
|
+
if ENV['CI']
|
6
|
+
require 'simplecov-lcov'
|
7
|
+
|
8
|
+
SimpleCov::Formatter::LcovFormatter.config do |c|
|
9
|
+
c.report_with_single_file = true
|
10
|
+
c.single_report_path = 'coverage/lcov.info'
|
11
|
+
end
|
12
|
+
|
13
|
+
formatter SimpleCov::Formatter::LcovFormatter
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
11
17
|
require 'rspec/its'
|
@@ -56,7 +62,10 @@ RSpec.configure do |config|
|
|
56
62
|
# databases mentioned in our tests
|
57
63
|
[1, 0].each do |db|
|
58
64
|
@redises.send_without_checking(:select, db)
|
59
|
-
@redises.send_without_checking(:keys, 'mock-redis-test:*')
|
65
|
+
keys = @redises.send_without_checking(:keys, 'mock-redis-test:*')
|
66
|
+
next unless keys.is_a?(Enumerable)
|
67
|
+
|
68
|
+
keys.each do |key|
|
60
69
|
@redises.send_without_checking(:del, key)
|
61
70
|
end
|
62
71
|
end
|
@@ -8,7 +8,7 @@ shared_examples_for 'does not remove empty strings on error' do
|
|
8
8
|
@redises.set(key, '')
|
9
9
|
lambda do
|
10
10
|
@redises.send(method, *args)
|
11
|
-
end.should raise_error(RuntimeError)
|
11
|
+
end.should raise_error(defined?(default_error) ? default_error : RuntimeError)
|
12
12
|
@redises.get(key).should == ''
|
13
13
|
end
|
14
14
|
end
|
@@ -8,7 +8,7 @@ shared_examples_for 'a list-only command' do
|
|
8
8
|
@redises.set(key, 1)
|
9
9
|
lambda do
|
10
10
|
@redises.send(method, *args)
|
11
|
-
end.should raise_error(RuntimeError)
|
11
|
+
end.should raise_error(defined?(default_error) ? default_error : RuntimeError)
|
12
12
|
end
|
13
13
|
|
14
14
|
it_should_behave_like 'does not remove empty strings on error'
|
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.33.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: 2022-
|
12
|
+
date: 2022-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby2_keywords
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 4.
|
34
|
+
version: 4.5.0
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 4.
|
41
|
+
version: 4.5.0
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rspec
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- spec/commands/pexpireat_spec.rb
|
212
212
|
- spec/commands/ping_spec.rb
|
213
213
|
- spec/commands/pipelined_spec.rb
|
214
|
+
- spec/commands/psetex_spec.rb
|
214
215
|
- spec/commands/pttl_spec.rb
|
215
216
|
- spec/commands/quit_spec.rb
|
216
217
|
- spec/commands/randomkey_spec.rb
|
@@ -397,6 +398,7 @@ test_files:
|
|
397
398
|
- spec/commands/pexpireat_spec.rb
|
398
399
|
- spec/commands/ping_spec.rb
|
399
400
|
- spec/commands/pipelined_spec.rb
|
401
|
+
- spec/commands/psetex_spec.rb
|
400
402
|
- spec/commands/pttl_spec.rb
|
401
403
|
- spec/commands/quit_spec.rb
|
402
404
|
- spec/commands/randomkey_spec.rb
|