mock_redis 0.3.0 → 0.4.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.
- data/.gitignore +1 -0
- data/CHANGELOG.md +6 -0
- data/lib/mock_redis.rb +1 -0
- data/lib/mock_redis/database.rb +1 -1
- data/lib/mock_redis/distributed.rb +6 -0
- data/lib/mock_redis/hash_methods.rb +15 -0
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset_methods.rb +1 -1
- data/mock_redis.gemspec +2 -2
- data/spec/commands/mapped_hmget_spec.rb +25 -0
- data/spec/commands/mapped_hmset_spec.rb +41 -0
- data/spec/commands/pipelined_spec.rb +11 -0
- data/spec/commands/select_spec.rb +2 -2
- data/spec/commands/ttl_spec.rb +1 -2
- data/spec/commands/zrange_spec.rb +4 -0
- data/spec/commands/zremrangebyrank_spec.rb +5 -0
- metadata +31 -17
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
### 0.4.0
|
2
|
+
* Support `mapped_hmset`/`mapped_hmget`
|
3
|
+
* Support `pipelined`
|
4
|
+
* Correctly handle out-of-range conditions for `zremrangebyrank` and `zrange`
|
5
|
+
* Fix off-by-one error in calculation of `ttl`
|
6
|
+
|
1
7
|
### 0.3.0
|
2
8
|
* Support hash operator (`[]`/`[]=`) as synonym of `get`/`set`
|
3
9
|
* Misc bugfixes
|
data/lib/mock_redis.rb
CHANGED
data/lib/mock_redis/database.rb
CHANGED
@@ -52,6 +52,11 @@ class MockRedis
|
|
52
52
|
fields.map{|f| hget(key, f)}
|
53
53
|
end
|
54
54
|
|
55
|
+
def mapped_hmget(key, *fields)
|
56
|
+
reply = hmget(key, *fields)
|
57
|
+
Hash[*fields.zip(reply).flatten]
|
58
|
+
end
|
59
|
+
|
55
60
|
def hmset(key, *kvpairs)
|
56
61
|
assert_has_args(kvpairs, 'hmset')
|
57
62
|
if kvpairs.length.odd?
|
@@ -64,6 +69,16 @@ class MockRedis
|
|
64
69
|
'OK'
|
65
70
|
end
|
66
71
|
|
72
|
+
def mapped_hmset(key, hash)
|
73
|
+
kvpairs = hash.to_a.flatten
|
74
|
+
assert_has_args(kvpairs, 'hmset')
|
75
|
+
if kvpairs.length.odd?
|
76
|
+
raise RuntimeError, "ERR wrong number of arguments for 'hmset' command"
|
77
|
+
end
|
78
|
+
|
79
|
+
hmset(key, *kvpairs)
|
80
|
+
end
|
81
|
+
|
67
82
|
def hset(key, field, value)
|
68
83
|
with_hash_at(key) {|h| h[field] = value.to_s}
|
69
84
|
true
|
data/lib/mock_redis/version.rb
CHANGED
data/mock_redis.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "mock_redis"
|
7
7
|
s.version = MockRedis::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = [
|
10
|
-
s.email = [
|
9
|
+
s.authors = ['Causes Engineering', 'Samuel Merritt']
|
10
|
+
s.email = ['eng@causes.com']
|
11
11
|
s.homepage = "https://github.com/causes/mock_redis"
|
12
12
|
s.summary = %q{Redis mock that just lives in memory; useful for testing.}
|
13
13
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#mapped_hmget(key, *fields)" do
|
4
|
+
before do
|
5
|
+
@key = "mock-redis-test:mapped_hmget"
|
6
|
+
@redises.hmset(@key, 'k1', 'v1', 'k2', 'v2')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns values stored at key" do
|
10
|
+
@redises.mapped_hmget(@key, 'k1', 'k2').should == {'k1' => 'v1', 'k2' => 'v2'}
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns nils for missing fields" do
|
14
|
+
@redises.mapped_hmget(@key, 'k1', 'mock-redis-test:nonesuch').
|
15
|
+
should == {'k1' => 'v1', 'mock-redis-test:nonesuch' => nil}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "raises an error if given no fields" do
|
19
|
+
lambda do
|
20
|
+
@redises.mapped_hmget(@key)
|
21
|
+
end.should raise_error(RuntimeError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it_should_behave_like "a hash-only command"
|
25
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#mapped_hmset(key, hash={})" do
|
4
|
+
before do
|
5
|
+
@key = "mock-redis-test:mapped_hmset"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns 'OK'" do
|
9
|
+
@redises.mapped_hmset(@key, {'k1'=>'v1', 'k2'=>'v2'}).should == 'OK'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets the values" do
|
13
|
+
@redises.mapped_hmset(@key, {'k1'=>'v1', 'k2'=>'v2'})
|
14
|
+
@redises.hmget(@key, 'k1', 'k2').should == %w[v1 v2]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "updates an existing hash" do
|
18
|
+
@redises.hmset(@key, 'foo', 'bar')
|
19
|
+
@redises.mapped_hmset(@key, {'bert' => 'ernie', 'diet' => 'coke'})
|
20
|
+
|
21
|
+
@redises.hmget(@key, 'foo', 'bert', 'diet').
|
22
|
+
should == %w[bar ernie coke]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "stores the values as strings" do
|
26
|
+
@redises.mapped_hmset(@key, {'one' => 1})
|
27
|
+
@redises.hget(@key, 'one').should == '1'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raises an error if given no hash" do
|
31
|
+
lambda do
|
32
|
+
@redises.mapped_hmset(@key)
|
33
|
+
end.should raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises an error if given a non-hash value" do
|
37
|
+
lambda do
|
38
|
+
@redises.mapped_hmset(@key, 1)
|
39
|
+
end.should raise_error(RuntimeError)
|
40
|
+
end
|
41
|
+
end
|
@@ -35,11 +35,11 @@ describe "#select(db)" do
|
|
35
35
|
|
36
36
|
@mock.select(0)
|
37
37
|
@mock.set(@key, 1)
|
38
|
-
@mock.expire(@key,
|
38
|
+
@mock.expire(@key, 100)
|
39
39
|
|
40
40
|
@mock.select(1)
|
41
41
|
@mock.set(@key, 2)
|
42
|
-
@mock.expire(@key,
|
42
|
+
@mock.expire(@key, 200)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "keeps expire times per-db" do
|
data/spec/commands/ttl_spec.rb
CHANGED
@@ -17,6 +17,10 @@ describe "#zrange(key, start, stop [, :with_scores => true])" do
|
|
17
17
|
@redises.zrange(@key, -2, -1).should == ['Jefferson', 'Madison']
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'returns empty list when start is too large' do
|
21
|
+
@redises.zrange(@key, 5, -1).should == []
|
22
|
+
end
|
23
|
+
|
20
24
|
it "returns the scores when :with_scores is specified" do
|
21
25
|
@redises.zrange(@key, 0, 1, :with_scores => true).
|
22
26
|
should == ["Washington", "1", "Adams", "2"]
|
@@ -18,5 +18,10 @@ describe "#zremrangebyrank(key, start, stop)" do
|
|
18
18
|
@redises.zrange(@key, 0, -1).should == %w[Washington Adams]
|
19
19
|
end
|
20
20
|
|
21
|
+
it "does nothing if start is greater than cardinality of set" do
|
22
|
+
@redises.zremrangebyrank(@key, 5, -1)
|
23
|
+
@redises.zrange(@key, 0, -1).should == %w[Washington Adams Jefferson Madison]
|
24
|
+
end
|
25
|
+
|
21
26
|
it_should_behave_like "a zset-only command"
|
22
27
|
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
|
10
|
+
segments_generated: true
|
11
|
+
version: 0.4.0
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
14
|
+
- Causes Engineering
|
13
15
|
- Samuel Merritt
|
14
16
|
autorequire:
|
15
17
|
bindir: bin
|
16
18
|
cert_chain: []
|
17
19
|
|
18
|
-
date:
|
20
|
+
date: 2012-03-04 00:00:00 -08:00
|
19
21
|
default_executable:
|
20
22
|
dependencies:
|
21
23
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
@@ -31,13 +31,14 @@ dependencies:
|
|
31
31
|
- 0
|
32
32
|
- 9
|
33
33
|
- 2
|
34
|
+
segments_generated: true
|
34
35
|
version: 0.9.2
|
36
|
+
requirement: *id001
|
37
|
+
name: rake
|
38
|
+
prerelease: false
|
35
39
|
type: :development
|
36
|
-
version_requirements: *id001
|
37
40
|
- !ruby/object:Gem::Dependency
|
38
|
-
|
39
|
-
prerelease: false
|
40
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
42
|
none: false
|
42
43
|
requirements:
|
43
44
|
- - ~>
|
@@ -47,13 +48,14 @@ dependencies:
|
|
47
48
|
- 2
|
48
49
|
- 2
|
49
50
|
- 1
|
51
|
+
segments_generated: true
|
50
52
|
version: 2.2.1
|
53
|
+
requirement: *id002
|
54
|
+
name: redis
|
55
|
+
prerelease: false
|
51
56
|
type: :development
|
52
|
-
version_requirements: *id002
|
53
57
|
- !ruby/object:Gem::Dependency
|
54
|
-
|
55
|
-
prerelease: false
|
56
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
57
59
|
none: false
|
58
60
|
requirements:
|
59
61
|
- - ~>
|
@@ -63,12 +65,15 @@ dependencies:
|
|
63
65
|
- 2
|
64
66
|
- 6
|
65
67
|
- 0
|
68
|
+
segments_generated: true
|
66
69
|
version: 2.6.0
|
70
|
+
requirement: *id003
|
71
|
+
name: rspec
|
72
|
+
prerelease: false
|
67
73
|
type: :development
|
68
|
-
version_requirements: *id003
|
69
74
|
description: Instantiate one with `redis = MockRedis.new` and treat it like you would a normal Redis object. It supports all the usual Redis operations.
|
70
75
|
email:
|
71
|
-
-
|
76
|
+
- eng@causes.com
|
72
77
|
executables: []
|
73
78
|
|
74
79
|
extensions: []
|
@@ -86,6 +91,7 @@ files:
|
|
86
91
|
- lib/mock_redis.rb
|
87
92
|
- lib/mock_redis/assertions.rb
|
88
93
|
- lib/mock_redis/database.rb
|
94
|
+
- lib/mock_redis/distributed.rb
|
89
95
|
- lib/mock_redis/exceptions.rb
|
90
96
|
- lib/mock_redis/expire_wrapper.rb
|
91
97
|
- lib/mock_redis/hash_methods.rb
|
@@ -150,12 +156,15 @@ files:
|
|
150
156
|
- spec/commands/lrem_spec.rb
|
151
157
|
- spec/commands/lset_spec.rb
|
152
158
|
- spec/commands/ltrim_spec.rb
|
159
|
+
- spec/commands/mapped_hmget_spec.rb
|
160
|
+
- spec/commands/mapped_hmset_spec.rb
|
153
161
|
- spec/commands/mget_spec.rb
|
154
162
|
- spec/commands/move_spec.rb
|
155
163
|
- spec/commands/mset_spec.rb
|
156
164
|
- spec/commands/msetnx_spec.rb
|
157
165
|
- spec/commands/persist_spec.rb
|
158
166
|
- spec/commands/ping_spec.rb
|
167
|
+
- spec/commands/pipelined_spec.rb
|
159
168
|
- spec/commands/quit_spec.rb
|
160
169
|
- spec/commands/randomkey_spec.rb
|
161
170
|
- spec/commands/rename_spec.rb
|
@@ -231,6 +240,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
240
|
hash: 3
|
232
241
|
segments:
|
233
242
|
- 0
|
243
|
+
segments_generated: true
|
234
244
|
version: "0"
|
235
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
246
|
none: false
|
@@ -240,6 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
240
250
|
hash: 3
|
241
251
|
segments:
|
242
252
|
- 0
|
253
|
+
segments_generated: true
|
243
254
|
version: "0"
|
244
255
|
requirements: []
|
245
256
|
|
@@ -299,12 +310,15 @@ test_files:
|
|
299
310
|
- spec/commands/lrem_spec.rb
|
300
311
|
- spec/commands/lset_spec.rb
|
301
312
|
- spec/commands/ltrim_spec.rb
|
313
|
+
- spec/commands/mapped_hmget_spec.rb
|
314
|
+
- spec/commands/mapped_hmset_spec.rb
|
302
315
|
- spec/commands/mget_spec.rb
|
303
316
|
- spec/commands/move_spec.rb
|
304
317
|
- spec/commands/mset_spec.rb
|
305
318
|
- spec/commands/msetnx_spec.rb
|
306
319
|
- spec/commands/persist_spec.rb
|
307
320
|
- spec/commands/ping_spec.rb
|
321
|
+
- spec/commands/pipelined_spec.rb
|
308
322
|
- spec/commands/quit_spec.rb
|
309
323
|
- spec/commands/randomkey_spec.rb
|
310
324
|
- spec/commands/rename_spec.rb
|