mock_redis 0.16.1 → 0.17.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/.rubocop.yml +7 -0
- data/.travis.yml +7 -3
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -2
- data/README.md +3 -4
- data/lib/mock_redis.rb +5 -1
- data/lib/mock_redis/database.rb +2 -1
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset_methods.rb +81 -18
- data/mock_redis.gemspec +1 -1
- data/spec/commands/del_spec.rb +2 -1
- data/spec/commands/zadd_spec.rb +76 -0
- data/spec/commands/zrem_spec.rb +6 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb438752840e4549b0797ba546fe482c36bbfed7
|
4
|
+
data.tar.gz: af6544eeeabb9e54989b39aebf64bad53e2a4ac0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e548a84b1df2535ddde32358e88801383560e3cedb65e9892e07c4f1812b291e37d3e255cd5777463fa96ad11fa9c47c047b520d77fb101e3e430a5703159a69
|
7
|
+
data.tar.gz: e3c469733b2de7d7793ea892b651cc3b9d0005f97c73e8b71894d4d6e10a4e95ae12de0faf97bfc0110d60ea7352abd40272ac5cba8df0bbc05984646819afe7
|
data/.rubocop.yml
CHANGED
@@ -51,9 +51,16 @@ Style/IfUnlessModifier:
|
|
51
51
|
Style/Lambda:
|
52
52
|
Enabled: false
|
53
53
|
|
54
|
+
# TODO: Address these at some point
|
55
|
+
Style/MethodMissing:
|
56
|
+
Enabled: false
|
57
|
+
|
54
58
|
Style/MultilineBlockChain:
|
55
59
|
Enabled: false
|
56
60
|
|
61
|
+
Style/NumericPredicate:
|
62
|
+
Enabled: false
|
63
|
+
|
57
64
|
# Prefer curly braces except for %i/%w/%W, since those return arrays.
|
58
65
|
Style/PercentLiteralDelimiters:
|
59
66
|
PreferredDelimiters:
|
data/.travis.yml
CHANGED
@@ -4,22 +4,26 @@ sudo: false
|
|
4
4
|
|
5
5
|
cache: bundler
|
6
6
|
|
7
|
+
addons:
|
8
|
+
apt:
|
9
|
+
packages:
|
10
|
+
- redis-server
|
11
|
+
|
7
12
|
services:
|
8
13
|
- redis-server
|
9
14
|
|
10
15
|
rvm:
|
11
|
-
- 1.9.3
|
12
16
|
- 2.0
|
13
17
|
- 2.1
|
14
18
|
- 2.2
|
15
|
-
- 2.3.
|
16
|
-
- jruby-19mode
|
19
|
+
- 2.3.1
|
17
20
|
|
18
21
|
before_script:
|
19
22
|
- git config --local user.email "travis@travis.ci"
|
20
23
|
- git config --local user.name "Travis CI"
|
21
24
|
|
22
25
|
script:
|
26
|
+
- redis-cli --version
|
23
27
|
- bundle exec rspec
|
24
28
|
- bundle exec overcommit --sign
|
25
29
|
- bundle exec overcommit --run
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# MockRedis Changelog
|
2
2
|
|
3
|
+
### 0.17.0
|
4
|
+
|
5
|
+
* Upgrade minimum `redis` gem version to 3.3.0+
|
6
|
+
* Add support for XX, NX and INCR parameters of `ZADD`
|
7
|
+
* Drop support for Ruby 1.9.3/JRuby 1.7.x
|
8
|
+
* Fix ZREM to raise error when argument is an empty array
|
9
|
+
|
3
10
|
### 0.16.1
|
4
11
|
|
5
12
|
* Relax `rake` gem dependency to allow 11.x.x versions
|
data/Gemfile
CHANGED
@@ -4,10 +4,10 @@ source 'http://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
# Run all pre-commit hooks via Overcommit during CI runs
|
7
|
-
gem 'overcommit', '0.
|
7
|
+
gem 'overcommit', '0.35.0'
|
8
8
|
|
9
9
|
# Pin tool versions (which are executed by Overcommit) for Travis builds
|
10
|
-
gem 'rubocop', '0.
|
10
|
+
gem 'rubocop', '0.42.0'
|
11
11
|
gem 'travis', '~> 1.7'
|
12
12
|
|
13
13
|
gem 'coveralls', require: false
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ MockRedis provides the same interface as `redis-rb`, but it stores its
|
|
9
9
|
data in memory instead of talking to a Redis server. It is intended
|
10
10
|
for use in tests.
|
11
11
|
|
12
|
-
The current implementation is tested against *Redis
|
12
|
+
The current implementation is tested against *Redis 3*. Older versions
|
13
13
|
of Redis may return different results or not support some commands.
|
14
14
|
|
15
15
|
## Getting Started
|
@@ -93,9 +93,8 @@ please submit a pull request with your (tested!) implementation.
|
|
93
93
|
|
94
94
|
## Compatibility
|
95
95
|
|
96
|
-
As of version `0.8.2`, Ruby
|
97
|
-
older versions of Ruby, use `0.8.1` or older.
|
98
|
-
supported.
|
96
|
+
As of version `0.8.2`, Ruby 2.0.0 and above are supported. For
|
97
|
+
older versions of Ruby, use `0.8.1` or older.
|
99
98
|
|
100
99
|
## Running the Tests
|
101
100
|
|
data/lib/mock_redis.rb
CHANGED
data/lib/mock_redis/database.rb
CHANGED
data/lib/mock_redis/version.rb
CHANGED
@@ -8,27 +8,84 @@ class MockRedis
|
|
8
8
|
include UtilityMethods
|
9
9
|
|
10
10
|
def zadd(key, *args)
|
11
|
-
|
12
|
-
|
13
|
-
assert_has_args(args, 'zadd')
|
11
|
+
zadd_options = {}
|
12
|
+
zadd_options = args.pop if args.last.is_a?(Hash)
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
if zadd_options && zadd_options.include?(:nx) && zadd_options.include?(:xx)
|
15
|
+
raise Redis::CommandError, 'ERR XX and NX options at the same time are not compatible'
|
16
|
+
end
|
17
|
+
|
18
|
+
if args.size == 1 && args[0].is_a?(Array)
|
19
|
+
zadd_multiple_members(key, args.first, zadd_options)
|
20
20
|
elsif args.size == 2
|
21
21
|
score, member = args
|
22
|
-
|
23
|
-
retval = !zscore(key, member)
|
24
|
-
with_zset_at(key) { |z| z.add(score, member.to_s) }
|
22
|
+
zadd_one_member(key, score, member, zadd_options)
|
25
23
|
else
|
26
24
|
raise Redis::CommandError, 'ERR wrong number of arguments'
|
27
25
|
end
|
26
|
+
end
|
28
27
|
|
29
|
-
|
28
|
+
def zadd_one_member(key, score, member, zadd_options = {})
|
29
|
+
assert_scorey(score) unless score =~ /(\+|\-)inf/
|
30
|
+
|
31
|
+
with_zset_at(key) do |zset|
|
32
|
+
if zadd_options[:incr]
|
33
|
+
if zadd_options[:xx]
|
34
|
+
member_present = zset.include?(member)
|
35
|
+
return member_present ? zincrby(key, score, member) : nil
|
36
|
+
end
|
37
|
+
|
38
|
+
if zadd_options[:nx]
|
39
|
+
member_present = zset.include?(member)
|
40
|
+
return member_present ? nil : zincrby(key, score, member)
|
41
|
+
end
|
42
|
+
|
43
|
+
zincrby(key, score, member)
|
44
|
+
elsif zadd_options[:xx]
|
45
|
+
zset.add(score, member.to_s) if zset.include?(member)
|
46
|
+
false
|
47
|
+
elsif zadd_options[:nx]
|
48
|
+
!zset.include?(member) && !!zset.add(score, member.to_s)
|
49
|
+
else
|
50
|
+
retval = !zscore(key, member)
|
51
|
+
zset.add(score, member.to_s)
|
52
|
+
retval
|
53
|
+
end
|
54
|
+
end
|
30
55
|
end
|
31
56
|
|
57
|
+
private :zadd_one_member
|
58
|
+
|
59
|
+
def zadd_multiple_members(key, args, zadd_options = {})
|
60
|
+
assert_has_args(args, 'zadd')
|
61
|
+
|
62
|
+
args = args.each_slice(2).to_a unless args.first.is_a?(Array)
|
63
|
+
with_zset_at(key) do |zset|
|
64
|
+
if zadd_options[:incr]
|
65
|
+
raise Redis::CommandError, 'ERR INCR option supports a single increment-element pair'
|
66
|
+
elsif zadd_options[:xx]
|
67
|
+
args.each { |score, member| zset.include?(member) && zset.add(score, member.to_s) }
|
68
|
+
0
|
69
|
+
elsif zadd_options[:nx]
|
70
|
+
args.reduce(0) do |retval, (score, member)|
|
71
|
+
unless zset.include?(member)
|
72
|
+
zset.add(score, member.to_s)
|
73
|
+
retval += 1
|
74
|
+
end
|
75
|
+
retval
|
76
|
+
end
|
77
|
+
else
|
78
|
+
args.reduce(0) do |retval, (score, member)|
|
79
|
+
retval += 1 unless zset.include?(member)
|
80
|
+
zset.add(score, member.to_s)
|
81
|
+
retval
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private :zadd_multiple_members
|
88
|
+
|
32
89
|
def zcard(key)
|
33
90
|
with_zset_at(key, &:size)
|
34
91
|
end
|
@@ -83,9 +140,13 @@ class MockRedis
|
|
83
140
|
retval = with_zset_at(key) { |z| !!z.delete?(args.first.to_s) }
|
84
141
|
else
|
85
142
|
args = args.first
|
86
|
-
|
87
|
-
|
88
|
-
|
143
|
+
if args.empty?
|
144
|
+
raise Redis::CommandError, "ERR wrong number of arguments for 'zrem' command"
|
145
|
+
else
|
146
|
+
retval = args.map { |member| !!zscore(key, member.to_s) }.count(true)
|
147
|
+
with_zset_at(key) do |z|
|
148
|
+
args.each { |member| z.delete?(member) }
|
149
|
+
end
|
89
150
|
end
|
90
151
|
end
|
91
152
|
|
@@ -119,8 +180,10 @@ class MockRedis
|
|
119
180
|
to_response(
|
120
181
|
apply_limit(
|
121
182
|
zset.in_range(min, max).reverse,
|
122
|
-
options[:limit]
|
123
|
-
|
183
|
+
options[:limit]
|
184
|
+
),
|
185
|
+
options
|
186
|
+
)
|
124
187
|
end
|
125
188
|
end
|
126
189
|
|
@@ -233,7 +296,7 @@ class MockRedis
|
|
233
296
|
def assert_zsety(key)
|
234
297
|
unless zsety?(key)
|
235
298
|
raise Redis::CommandError,
|
236
|
-
|
299
|
+
'WRONGTYPE Operation against a key holding the wrong kind of value'
|
237
300
|
end
|
238
301
|
end
|
239
302
|
|
data/mock_redis.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.require_paths = ['lib']
|
23
23
|
|
24
24
|
s.add_development_dependency 'rake', '>= 10', '< 12'
|
25
|
-
s.add_development_dependency 'redis', '~> 3.
|
25
|
+
s.add_development_dependency 'redis', '~> 3.3.0'
|
26
26
|
s.add_development_dependency 'rspec', '~> 3.0'
|
27
27
|
s.add_development_dependency 'rspec-its', '~> 1.0'
|
28
28
|
end
|
data/spec/commands/del_spec.rb
CHANGED
data/spec/commands/zadd_spec.rb
CHANGED
@@ -30,6 +30,82 @@ describe '#zadd(key, score, member)' do
|
|
30
30
|
@redises.zscore(@key, 'foo').should == 2.0
|
31
31
|
end
|
32
32
|
|
33
|
+
it 'with XX option command do nothing if element not exist' do
|
34
|
+
@redises.zadd(@key, 1, 'foo')
|
35
|
+
@redises.zadd(@key, 2, 'bar', xx: true)
|
36
|
+
@redises.zrange(@key, 0, -1).should_not include 'bar'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'with XX option command update index on exist element' do
|
40
|
+
@redises.zadd(@key, 1, 'foo')
|
41
|
+
@redises.zadd(@key, 2, 'foo', xx: true)
|
42
|
+
@redises.zscore(@key, 'foo').should == 2.0
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'with XX option and multiple elements command update index on exist element' do
|
46
|
+
@redises.zadd(@key, 1, 'foo')
|
47
|
+
added_count = @redises.zadd(@key, [[2, 'foo'], [2, 'bar']], xx: true)
|
48
|
+
added_count.should == 0
|
49
|
+
|
50
|
+
@redises.zscore(@key, 'foo').should == 2.0
|
51
|
+
@redises.zrange(@key, 0, -1).should_not include 'bar'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "with NX option don't update current element" do
|
55
|
+
@redises.zadd(@key, 1, 'foo')
|
56
|
+
@redises.zadd(@key, 2, 'foo', nx: true)
|
57
|
+
@redises.zscore(@key, 'foo').should == 1.0
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'with NX option create new element' do
|
61
|
+
@redises.zadd(@key, 1, 'foo')
|
62
|
+
@redises.zadd(@key, 2, 'bar', nx: true)
|
63
|
+
@redises.zrange(@key, 0, -1).should include 'bar'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'with NX option and multiple elements command only create element' do
|
67
|
+
@redises.zadd(@key, 1, 'foo')
|
68
|
+
added_count = @redises.zadd(@key, [[2, 'foo'], [2, 'bar']], nx: true)
|
69
|
+
added_count.should == 1
|
70
|
+
@redises.zscore(@key, 'bar').should == 2.0
|
71
|
+
@redises.zrange(@key, 0, -1).should eq %w[foo bar]
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'XX and NX options in same time raise error' do
|
75
|
+
lambda do
|
76
|
+
@redises.zadd(@key, 1, 'foo', nx: true, xx: true)
|
77
|
+
end.should raise_error(Redis::CommandError)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'with INCR is act like zincrby' do
|
81
|
+
@redises.zadd(@key, 10, 'bert', incr: true).should == 10.0
|
82
|
+
@redises.zadd(@key, 3, 'bert', incr: true).should == 13.0
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'with INCR and XX not create element' do
|
86
|
+
@redises.zadd(@key, 10, 'bert', xx: true, incr: true).should be_nil
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'with INCR and XX increase score for exist element' do
|
90
|
+
@redises.zadd(@key, 2, 'bert')
|
91
|
+
@redises.zadd(@key, 10, 'bert', xx: true, incr: true).should == 12.0
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'with INCR and NX create element with score' do
|
95
|
+
@redises.zadd(@key, 11, 'bert', nx: true, incr: true).should == 11.0
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'with INCR and NX not update element' do
|
99
|
+
@redises.zadd(@key, 1, 'bert')
|
100
|
+
@redises.zadd(@key, 10, 'bert', nx: true, incr: true).should be_nil
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'with INCR with variable number of arguments raise error' do
|
104
|
+
lambda do
|
105
|
+
@redises.zadd(@key, [[1, 'one'], [2, 'two']], incr: true)
|
106
|
+
end.should raise_error(Redis::CommandError)
|
107
|
+
end
|
108
|
+
|
33
109
|
it 'supports a variable number of arguments' do
|
34
110
|
@redises.zadd(@key, [[1, 'one'], [2, 'two']])
|
35
111
|
@redises.zadd(@key, [[3, 'three']])
|
data/spec/commands/zrem_spec.rb
CHANGED
@@ -33,5 +33,11 @@ describe '#zrem(key, member)' do
|
|
33
33
|
@redises.zrange(@key, 0, -1).should be_empty
|
34
34
|
end
|
35
35
|
|
36
|
+
it 'raises an error if member is an empty array' do
|
37
|
+
lambda do
|
38
|
+
@redises.zrem(@key, [])
|
39
|
+
end.should raise_error(Redis::CommandError)
|
40
|
+
end
|
41
|
+
|
36
42
|
it_should_behave_like 'a zset-only command'
|
37
43
|
end
|
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.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brigade Engineering
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -37,14 +37,14 @@ dependencies:
|
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.
|
40
|
+
version: 3.3.0
|
41
41
|
type: :development
|
42
42
|
prerelease: false
|
43
43
|
version_requirements: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.
|
47
|
+
version: 3.3.0
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -281,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
281
|
version: '0'
|
282
282
|
requirements: []
|
283
283
|
rubyforge_project:
|
284
|
-
rubygems_version: 2.
|
284
|
+
rubygems_version: 2.5.1
|
285
285
|
signing_key:
|
286
286
|
specification_version: 4
|
287
287
|
summary: Redis mock that just lives in memory; useful for testing.
|