mock_redis 0.32.0 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9f945150c69e6ff81838d4e029f1620ade56e9da6c3cb2ed0550cd61060335a
4
- data.tar.gz: fbd58f70dbf78b770a6d3e04351771a1d94a7cac87afbff95213c92bceb16eaa
3
+ metadata.gz: 764d3b747c037b933788f2d4ef01e581ecb509aa8c3e445d12c27d199d2273fe
4
+ data.tar.gz: 9093a8b7601c57e746dd38d7708c52474df56247ea0910ca4d8d7bcecca9506e
5
5
  SHA512:
6
- metadata.gz: 9320958fc6e3360f26317dfcb47747bf8d39d626d54c0297cece31b9521fc4ad991acdccf885428d05f8b82765cfec12a37af4de33473f4106c7e3eb4e9c2b69
7
- data.tar.gz: 05c04acff0f82500f114a868ed40aef95fc115e367ed94008075ddd90de5550dd939ca12215ffb3c88021a6aeff18cd3f9ff51dfabcc3f14244b40465d6184f0
6
+ metadata.gz: c7ef20dba317c18d0ab4de7d5d0a87107512cb2398c7d9c549a603a1980fbced844c7b98c547db32fb905a32ed68cdfa25ba9331b03a91512c8c1d1f6d45551a
7
+ data.tar.gz: 29570271c68cf37d7fd09c065cdad79e1ac64e9b1aa3bdb28dbf0d2080983cc758ad4632e13ad132d492dc823afef8dd7a7a9cec14dfbefb6a7e49a840c74c8c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # MockRedis Changelog
2
2
 
3
+ ### 0.33.0
4
+
5
+ * Add support for `GET` argument to `SET` command
6
+
3
7
  ### 0.32.0
4
8
 
5
9
  * Add support for `psetex`
@@ -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] }.
@@ -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
- return_true ? true : 'OK'
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
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  class MockRedis
5
- VERSION = '0.32.0'
5
+ VERSION = '0.33.0'
6
6
  end
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.2.0'
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'
@@ -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 [] }.to raise_error Redis::CommandError
43
+ expect { @redises.del [] }.not_to raise_error Redis::CommandError
44
44
  end
45
45
 
46
46
  it 'removes a stream key' do
@@ -30,5 +30,6 @@ describe '#lpop(key)' do
30
30
  @redises.get(@key).should be_nil
31
31
  end
32
32
 
33
+ let(:default_error) { RedisMultiplexer::MismatchedResponse }
33
34
  it_should_behave_like 'a list-only command'
34
35
  end
@@ -30,5 +30,6 @@ describe '#rpop(key)' do
30
30
  @redises.get(@key).should be_nil
31
31
  end
32
32
 
33
+ let(:default_error) { RedisMultiplexer::MismatchedResponse }
33
34
  it_should_behave_like 'a list-only command'
34
35
  end
@@ -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
@@ -62,7 +62,10 @@ RSpec.configure do |config|
62
62
  # databases mentioned in our tests
63
63
  [1, 0].each do |db|
64
64
  @redises.send_without_checking(:select, db)
65
- @redises.send_without_checking(:keys, 'mock-redis-test:*').each do |key|
65
+ keys = @redises.send_without_checking(:keys, 'mock-redis-test:*')
66
+ next unless keys.is_a?(Enumerable)
67
+
68
+ keys.each do |key|
66
69
  @redises.send_without_checking(:del, key)
67
70
  end
68
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.32.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-06-12 00:00:00.000000000 Z
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.2.0
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.2.0
41
+ version: 4.5.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement