mock_redis 0.6.6 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/mock_redis/list_methods.rb +1 -1
- data/lib/mock_redis/string_methods.rb +12 -0
- data/lib/mock_redis/version.rb +1 -1
- data/spec/commands/mapped_mget_spec.rb +22 -0
- data/spec/commands/mapped_mset_spec.rb +19 -0
- data/spec/commands/mapped_msetnx_spec.rb +26 -0
- data/spec/commands/rpoplpush_spec.rb +5 -0
- metadata +8 -2
data/CHANGELOG.md
CHANGED
@@ -99,6 +99,10 @@ class MockRedis
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
def mapped_mget(*keys)
|
103
|
+
Hash[keys.zip(mget(*keys))]
|
104
|
+
end
|
105
|
+
|
102
106
|
def mset(*kvpairs)
|
103
107
|
assert_has_args(kvpairs, 'mset')
|
104
108
|
if kvpairs.length.odd?
|
@@ -112,6 +116,10 @@ class MockRedis
|
|
112
116
|
"OK"
|
113
117
|
end
|
114
118
|
|
119
|
+
def mapped_mset(hash)
|
120
|
+
mset(*hash.to_a.flatten)
|
121
|
+
end
|
122
|
+
|
115
123
|
def msetnx(*kvpairs)
|
116
124
|
assert_has_args(kvpairs, 'msetnx')
|
117
125
|
|
@@ -123,6 +131,10 @@ class MockRedis
|
|
123
131
|
end
|
124
132
|
end
|
125
133
|
|
134
|
+
def mapped_msetnx(hash)
|
135
|
+
msetnx(*hash.to_a.flatten)
|
136
|
+
end
|
137
|
+
|
126
138
|
def set(key, value)
|
127
139
|
data[key] = value.to_s
|
128
140
|
'OK'
|
data/lib/mock_redis/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#mapped_mget(*keys)' do
|
4
|
+
before do
|
5
|
+
@key1 = 'mock-redis-test:a'
|
6
|
+
@key2 = 'mock-redis-test:b'
|
7
|
+
@key3 = 'mock-redis-test:c'
|
8
|
+
|
9
|
+
@redises.set(@key1, '1')
|
10
|
+
@redises.set(@key2, '2')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns a hash' do
|
14
|
+
@redises.mapped_mget(@key1, @key2, @key3).should eq({@key1 => '1',
|
15
|
+
@key2 => '2',
|
16
|
+
@key3 => nil})
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns a hash even when no matches' do
|
20
|
+
@redises.mapped_mget('qwer').should eq({'qwer' => nil})
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#mapped_mset(hash)' do
|
4
|
+
before do
|
5
|
+
@key1 = 'mock-redis-test:a'
|
6
|
+
@key2 = 'mock-redis-test:b'
|
7
|
+
@key3 = 'mock-redis-test:c'
|
8
|
+
|
9
|
+
@redises.set(@key1, '1')
|
10
|
+
@redises.set(@key2, '2')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'sets the values properly' do
|
14
|
+
@redises.mapped_mset({@key1 => 'one', @key3 => 'three'}).should eq('OK')
|
15
|
+
@redises.get(@key1).should eq('one')
|
16
|
+
@redises.get(@key2).should eq('2') # left alone
|
17
|
+
@redises.get(@key3).should eq('three')
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#mapped_msetnx(hash)' do
|
4
|
+
before do
|
5
|
+
@key1 = 'mock-redis-test:a'
|
6
|
+
@key2 = 'mock-redis-test:b'
|
7
|
+
@key3 = 'mock-redis-test:c'
|
8
|
+
|
9
|
+
@redises.set(@key1, '1')
|
10
|
+
@redises.set(@key2, '2')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'sets properly when none collide' do
|
14
|
+
@redises.mapped_msetnx(@key3 => 'three').should eq(true)
|
15
|
+
@redises.get(@key1).should eq('1') # existed; untouched
|
16
|
+
@redises.get(@key2).should eq('2') # existed; untouched
|
17
|
+
@redises.get(@key3).should eq('three')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'does not set any when any collide' do
|
21
|
+
@redises.mapped_msetnx(@key1 => 'one', @key3 => 'three').should eq(false)
|
22
|
+
@redises.get(@key1).should eq('1') # existed; untouched
|
23
|
+
@redises.get(@key2).should eq('2') # existed; untouched
|
24
|
+
@redises.get(@key3).should be_nil
|
25
|
+
end
|
26
|
+
end
|
@@ -16,6 +16,11 @@ describe '#rpoplpush(source, destination)' do
|
|
16
16
|
@redises.rpoplpush(@list1, @list2).should == "b"
|
17
17
|
end
|
18
18
|
|
19
|
+
it "returns false and doesn't append if source empty" do
|
20
|
+
@redises.rpoplpush('empty', @list1).should be_nil
|
21
|
+
@redises.lrange(@list1, 0, -1).should == %w[a b]
|
22
|
+
end
|
23
|
+
|
19
24
|
it "takes the last element of destination and prepends it to source" do
|
20
25
|
@redises.rpoplpush(@list1, @list2)
|
21
26
|
|
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.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-04-
|
13
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -153,6 +153,9 @@ files:
|
|
153
153
|
- spec/commands/ltrim_spec.rb
|
154
154
|
- spec/commands/mapped_hmget_spec.rb
|
155
155
|
- spec/commands/mapped_hmset_spec.rb
|
156
|
+
- spec/commands/mapped_mget_spec.rb
|
157
|
+
- spec/commands/mapped_mset_spec.rb
|
158
|
+
- spec/commands/mapped_msetnx_spec.rb
|
156
159
|
- spec/commands/mget_spec.rb
|
157
160
|
- spec/commands/move_spec.rb
|
158
161
|
- spec/commands/mset_spec.rb
|
@@ -304,6 +307,9 @@ test_files:
|
|
304
307
|
- spec/commands/ltrim_spec.rb
|
305
308
|
- spec/commands/mapped_hmget_spec.rb
|
306
309
|
- spec/commands/mapped_hmset_spec.rb
|
310
|
+
- spec/commands/mapped_mget_spec.rb
|
311
|
+
- spec/commands/mapped_mset_spec.rb
|
312
|
+
- spec/commands/mapped_msetnx_spec.rb
|
307
313
|
- spec/commands/mget_spec.rb
|
308
314
|
- spec/commands/move_spec.rb
|
309
315
|
- spec/commands/mset_spec.rb
|