mock_redis 0.17.3 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +6 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -2
- data/README.md +1 -1
- data/lib/mock_redis/database.rb +14 -16
- data/lib/mock_redis/hash_methods.rb +3 -2
- data/lib/mock_redis/list_methods.rb +2 -2
- data/lib/mock_redis/version.rb +1 -1
- data/spec/commands/hset_spec.rb +11 -1
- data/spec/commands/lpushx_spec.rb +5 -4
- data/spec/commands/rename_spec.rb +3 -5
- data/spec/commands/renamenx_spec.rb +2 -4
- data/spec/commands/rpushx_spec.rb +5 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d45157a6761c4ee6db463b692fc9576ea1635576702423d8482e4a108662a1bc
|
4
|
+
data.tar.gz: 1fd788a1b8d7260c68f964af5cad36d83d360ae86616d4b764c1a655b1df953d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb6a1a256bca8464aff700e90db426ce3e98b454c9bbdb56f44316dba0b8c10dd66afe7938b3f0fb3b22e61cee3c2f96675fc3f5ce1d2efcae24c09c9bd6ba76
|
7
|
+
data.tar.gz: 6720e42db8d2aafeae70dfeb79ad827b054b10143013510a2f3ac8b209438d70a05aafbf1039aae3f9b85194221cb80461c33700cf0215895ab6989999bcf605
|
data/.rubocop.yml
CHANGED
@@ -9,6 +9,9 @@ Lint/Void:
|
|
9
9
|
Metrics/AbcSize:
|
10
10
|
Enabled: false
|
11
11
|
|
12
|
+
Metrics/BlockLength:
|
13
|
+
Enabled: false
|
14
|
+
|
12
15
|
Metrics/CyclomaticComplexity:
|
13
16
|
Enabled: false
|
14
17
|
|
@@ -90,6 +93,9 @@ Style/SignalException:
|
|
90
93
|
Style/SingleLineBlockParams:
|
91
94
|
Enabled: false
|
92
95
|
|
96
|
+
Style/SymbolArray:
|
97
|
+
Enabled: false
|
98
|
+
|
93
99
|
Style/TrailingCommaInArguments:
|
94
100
|
Enabled: false
|
95
101
|
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# MockRedis Changelog
|
2
2
|
|
3
|
+
### 0.18.0
|
4
|
+
|
5
|
+
* Fix `hset` return value to return false when the field exists in the hash
|
6
|
+
* Fix message on exception raised from hincrbyfloat to match Redis 4
|
7
|
+
* Fix `lpushx`/`rpushx` to correctly accept an array as the value
|
8
|
+
* Fix rename to allow `rename(k1, k1)`
|
9
|
+
|
3
10
|
### 0.17.3
|
4
11
|
|
5
12
|
* Fix `zrange` behavior with negative stop argument
|
data/Gemfile
CHANGED
@@ -4,9 +4,9 @@ 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.39.0'
|
8
8
|
|
9
9
|
# Pin tool versions (which are executed by Overcommit) for Travis builds
|
10
|
-
gem 'rubocop', '0.
|
10
|
+
gem 'rubocop', '0.48.1'
|
11
11
|
|
12
12
|
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 4*. Older versions
|
13
13
|
of Redis may return different results or not support some commands.
|
14
14
|
|
15
15
|
## Getting Started
|
data/lib/mock_redis/database.rb
CHANGED
@@ -160,25 +160,26 @@ class MockRedis
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def rename(key, newkey)
|
163
|
-
|
163
|
+
unless data.include?(key)
|
164
164
|
raise Redis::CommandError, 'ERR no such key'
|
165
|
-
elsif key == newkey
|
166
|
-
raise Redis::CommandError, 'ERR source and destination objects are the same'
|
167
165
|
end
|
168
|
-
|
169
|
-
if
|
170
|
-
|
171
|
-
|
166
|
+
|
167
|
+
if key != newkey
|
168
|
+
data[newkey] = data.delete(key)
|
169
|
+
if has_expiration?(key)
|
170
|
+
set_expiration(newkey, expiration(key))
|
171
|
+
remove_expiration(key)
|
172
|
+
end
|
172
173
|
end
|
174
|
+
|
173
175
|
'OK'
|
174
176
|
end
|
175
177
|
|
176
178
|
def renamenx(key, newkey)
|
177
|
-
|
179
|
+
unless data.include?(key)
|
178
180
|
raise Redis::CommandError, 'ERR no such key'
|
179
|
-
elsif key == newkey
|
180
|
-
raise Redis::CommandError, 'ERR source and destination objects are the same'
|
181
181
|
end
|
182
|
+
|
182
183
|
if exists(newkey)
|
183
184
|
false
|
184
185
|
else
|
@@ -229,14 +230,11 @@ class MockRedis
|
|
229
230
|
end
|
230
231
|
end
|
231
232
|
|
232
|
-
def script(subcommand, *args)
|
233
|
-
end
|
233
|
+
def script(subcommand, *args); end
|
234
234
|
|
235
|
-
def evalsha(*args)
|
236
|
-
end
|
235
|
+
def evalsha(*args); end
|
237
236
|
|
238
|
-
def eval(*args)
|
239
|
-
end
|
237
|
+
def eval(*args); end
|
240
238
|
|
241
239
|
private
|
242
240
|
|
@@ -51,7 +51,7 @@ class MockRedis
|
|
51
51
|
with_hash_at(key) do |hash|
|
52
52
|
field = field.to_s
|
53
53
|
unless can_incr_float?(data[key][field])
|
54
|
-
raise Redis::CommandError, 'ERR hash value is not a
|
54
|
+
raise Redis::CommandError, 'ERR hash value is not a float'
|
55
55
|
end
|
56
56
|
|
57
57
|
unless looks_like_float?(increment.to_s)
|
@@ -126,8 +126,9 @@ class MockRedis
|
|
126
126
|
end
|
127
127
|
|
128
128
|
def hset(key, field, value)
|
129
|
+
field_exists = hexists(key, field)
|
129
130
|
with_hash_at(key) { |h| h[field.to_s] = value.to_s }
|
130
|
-
|
131
|
+
!field_exists
|
131
132
|
end
|
132
133
|
|
133
134
|
def hsetnx(key, field, value)
|
@@ -91,7 +91,7 @@ class MockRedis
|
|
91
91
|
|
92
92
|
def lpushx(key, value)
|
93
93
|
value = [value] unless value.is_a?(Array)
|
94
|
-
if value.
|
94
|
+
if value.empty?
|
95
95
|
raise Redis::CommandError, "ERR wrong number of arguments for 'lpushx' command"
|
96
96
|
end
|
97
97
|
assert_listy(key)
|
@@ -170,7 +170,7 @@ class MockRedis
|
|
170
170
|
|
171
171
|
def rpushx(key, value)
|
172
172
|
value = [value] unless value.is_a?(Array)
|
173
|
-
if value.
|
173
|
+
if value.empty?
|
174
174
|
raise Redis::CommandError, "ERR wrong number of arguments for 'rpushx' command"
|
175
175
|
end
|
176
176
|
assert_listy(key)
|
data/lib/mock_redis/version.rb
CHANGED
data/spec/commands/hset_spec.rb
CHANGED
@@ -5,10 +5,20 @@ describe '#hset(key, field)' do
|
|
5
5
|
@key = 'mock-redis-test:hset'
|
6
6
|
end
|
7
7
|
|
8
|
-
it 'returns true' do
|
8
|
+
it 'returns true if the key does not exist' do
|
9
9
|
@redises.hset(@key, 'k1', 'v1').should == true
|
10
10
|
end
|
11
11
|
|
12
|
+
it 'returns true if the key exists but the field does not' do
|
13
|
+
@redises.hset(@key, 'k1', 'v1')
|
14
|
+
@redises.hset(@key, 'k2', 'v2').should == true
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns false if the field already exists' do
|
18
|
+
@redises.hset(@key, 'k1', 'v1')
|
19
|
+
@redises.hset(@key, 'k1', 'v1').should == false
|
20
|
+
end
|
21
|
+
|
12
22
|
it 'creates a hash there is no such field' do
|
13
23
|
@redises.hset(@key, 'k1', 'v1')
|
14
24
|
@redises.hget(@key, 'k1').should == 'v1'
|
@@ -30,15 +30,16 @@ describe '#lpushx(key, value)' do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'raises an error if an empty array is given' do
|
33
|
+
@redises.lpush(@key, 'X')
|
33
34
|
lambda do
|
34
35
|
@redises.lpushx(@key, [])
|
35
36
|
end.should raise_error(Redis::CommandError)
|
36
37
|
end
|
37
38
|
|
38
|
-
it '
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
it 'stores multiple items if an array of more than one item is given' do
|
40
|
+
@redises.lpush(@key, 'X')
|
41
|
+
@redises.lpushx(@key, [1, 2]).should == 3
|
42
|
+
@redises.lrange(@key, 0, -1).should == %w[2 1 X]
|
42
43
|
end
|
43
44
|
|
44
45
|
it_should_behave_like 'a list-only command'
|
@@ -8,7 +8,7 @@ describe '#rename(key, newkey)' do
|
|
8
8
|
@redises.set(@key, 'oof')
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'responds with "OK"' do
|
12
12
|
@redises.rename(@key, @newkey).should == 'OK'
|
13
13
|
end
|
14
14
|
|
@@ -24,10 +24,8 @@ describe '#rename(key, newkey)' do
|
|
24
24
|
end.should raise_error(Redis::CommandError)
|
25
25
|
end
|
26
26
|
|
27
|
-
it '
|
28
|
-
|
29
|
-
@redises.rename(@key, @key)
|
30
|
-
end.should raise_error(Redis::CommandError)
|
27
|
+
it 'responds with "OK" when key == newkey' do
|
28
|
+
@redises.rename(@key, @key).should == 'OK'
|
31
29
|
end
|
32
30
|
|
33
31
|
it 'overwrites any existing value at newkey' do
|
@@ -29,10 +29,8 @@ describe '#renamenx(key, newkey)' do
|
|
29
29
|
end.should raise_error(Redis::CommandError)
|
30
30
|
end
|
31
31
|
|
32
|
-
it '
|
33
|
-
|
34
|
-
@redises.renamenx(@key, @key)
|
35
|
-
end.should raise_error(Redis::CommandError)
|
32
|
+
it 'returns false when key == newkey' do
|
33
|
+
@redises.renamenx(@key, @key).should == false
|
36
34
|
end
|
37
35
|
|
38
36
|
it 'leaves any existing value at newkey alone' do
|
@@ -30,15 +30,16 @@ describe '#rpushx(key, value)' do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'raises an error if an empty array is given' do
|
33
|
+
@redises.lpush(@key, 'X')
|
33
34
|
lambda do
|
34
35
|
@redises.rpushx(@key, [])
|
35
36
|
end.should raise_error(Redis::CommandError)
|
36
37
|
end
|
37
38
|
|
38
|
-
it '
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
it 'stores multiple items if an array of more than one item is given' do
|
40
|
+
@redises.lpush(@key, 'X')
|
41
|
+
@redises.rpushx(@key, [1, 2]).should == 3
|
42
|
+
@redises.lrange(@key, 0, -1).should == %w[X 1 2]
|
42
43
|
end
|
43
44
|
|
44
45
|
it_should_behave_like 'a list-only command'
|
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.18.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:
|
12
|
+
date: 2018-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -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.7.3
|
285
285
|
signing_key:
|
286
286
|
specification_version: 4
|
287
287
|
summary: Redis mock that just lives in memory; useful for testing.
|