mock_redis 0.11.0 → 0.12.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/.overcommit.yml +3 -0
- data/CHANGELOG.md +7 -0
- data/lib/mock_redis/database.rb +3 -1
- data/lib/mock_redis/string_methods.rb +27 -0
- data/lib/mock_redis/version.rb +2 -1
- data/mock_redis.gemspec +4 -5
- data/spec/commands/bitcount_spec.rb +25 -0
- data/spec/commands/blpop_spec.rb +1 -1
- data/spec/commands/brpop_spec.rb +1 -1
- data/spec/commands/brpoplpush_spec.rb +0 -6
- data/spec/commands/del_spec.rb +4 -0
- data/spec/commands/expire_spec.rb +7 -7
- data/spec/commands/expireat_spec.rb +2 -2
- data/spec/commands/persist_spec.rb +2 -2
- data/spec/commands/pexpire_spec.rb +5 -5
- data/spec/commands/pexpireat_spec.rb +2 -2
- data/spec/commands/pttl_spec.rb +1 -1
- data/spec/commands/select_spec.rb +1 -1
- data/spec/commands/set_spec.rb +3 -3
- data/spec/commands/ttl_spec.rb +1 -1
- data/spec/transactions_spec.rb +2 -3
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 516b9db310fcc1afb4836e614d64d2e6eaf182be
|
4
|
+
data.tar.gz: 346ab1f34936cd9b19387912c34c694d27ef1ff9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c4e3966c3ad7feba84548c6591aa55bbf7c1fe3d01d8051da4b1be41749fe23afb02475ba176bd7fad4d3ed761be2bbdbf511151c80c74ed9e1b3b133b7b7a6
|
7
|
+
data.tar.gz: df2c5def2bd41aba2671033ee2064dfbf31a5dabaf21ba5ba9a578200623648ef7d3a8c1b92e64a0d63b35af2bc00dd30c856afb6b4b07704b428a44324ba1d2
|
data/.overcommit.yml
ADDED
data/CHANGELOG.md
CHANGED
data/lib/mock_redis/database.rb
CHANGED
@@ -208,6 +208,33 @@ class MockRedis
|
|
208
208
|
retval
|
209
209
|
end
|
210
210
|
|
211
|
+
def bitcount(key, start = 0, stop = -1)
|
212
|
+
assert_stringy(key)
|
213
|
+
|
214
|
+
str = data[key] || ""
|
215
|
+
count = 0
|
216
|
+
m1 = 0x5555555555555555
|
217
|
+
m2 = 0x3333333333333333
|
218
|
+
m4 = 0x0f0f0f0f0f0f0f0f
|
219
|
+
m8 = 0x00ff00ff00ff00ff
|
220
|
+
m16 = 0x0000ffff0000ffff
|
221
|
+
m32 = 0x00000000ffffffff
|
222
|
+
|
223
|
+
str.bytes.to_a[start..stop].each do |byte|
|
224
|
+
# Naive Hamming weight
|
225
|
+
c = byte
|
226
|
+
c = (c & m1) + ((c >> 1) & m1)
|
227
|
+
c = (c & m2) + ((c >> 2) & m2)
|
228
|
+
c = (c & m4) + ((c >> 4) & m4)
|
229
|
+
c = (c & m8) + ((c >> 8) & m8)
|
230
|
+
c = (c & m16) + ((c >> 16) & m16)
|
231
|
+
c = (c & m32) + ((c >> 32) & m32)
|
232
|
+
count += c
|
233
|
+
end
|
234
|
+
|
235
|
+
count
|
236
|
+
end
|
237
|
+
|
211
238
|
def setex(key, seconds, value)
|
212
239
|
set(key, value)
|
213
240
|
expire(key, seconds)
|
data/lib/mock_redis/version.rb
CHANGED
data/mock_redis.gemspec
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
$:.push File.expand_path('../lib', __FILE__)
|
1
|
+
$LOAD_PATH << File.expand_path('../lib', __FILE__)
|
3
2
|
require 'mock_redis/version'
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
@@ -19,10 +18,10 @@ Gem::Specification.new do |s|
|
|
19
18
|
|
20
19
|
s.files = `git ls-files`.split("\n")
|
21
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
23
22
|
s.require_paths = ['lib']
|
24
23
|
|
25
|
-
s.add_development_dependency 'rake', '~> 0
|
24
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
26
25
|
s.add_development_dependency 'redis', '~> 3.0.0'
|
27
|
-
s.add_development_dependency 'rspec', '~> 2.
|
26
|
+
s.add_development_dependency 'rspec', '~> 2.14.0'
|
28
27
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#bitcount(key [, start, end ])" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:bitcount'
|
6
|
+
@redises.set(@key, "foobar")
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'gets the number of set bits from the key' do
|
10
|
+
@redises.bitcount(@key).should == 26
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'gets the number of set bits from the key in an interval' do
|
14
|
+
@redises.bitcount(@key, 0, 1000).should == 26
|
15
|
+
@redises.bitcount(@key, 0, 0).should == 4
|
16
|
+
@redises.bitcount(@key, 1, 1).should == 6
|
17
|
+
@redises.bitcount(@key, 1, -2).should == 18
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'treats nonexistent keys as empty strings' do
|
21
|
+
@redises.bitcount('mock-redis-test:not-found').should == 0
|
22
|
+
end
|
23
|
+
|
24
|
+
it_should_behave_like "a string-only command"
|
25
|
+
end
|
data/spec/commands/blpop_spec.rb
CHANGED
@@ -30,7 +30,7 @@ describe '#blpop(key [, key, ...,], timeout)' do
|
|
30
30
|
it "allows subsecond timeouts" do
|
31
31
|
lambda do
|
32
32
|
@redises.blpop(@list1, @list2, 0.5)
|
33
|
-
end.should_not raise_error
|
33
|
+
end.should_not raise_error
|
34
34
|
end
|
35
35
|
|
36
36
|
it "raises an error on negative timeout" do
|
data/spec/commands/brpop_spec.rb
CHANGED
@@ -29,7 +29,7 @@ describe '#brpop(key [, key, ...,], timeout)' do
|
|
29
29
|
it "allows subsecond timeouts" do
|
30
30
|
lambda do
|
31
31
|
@redises.brpop(@list1, @list2, 0.5)
|
32
|
-
end.should_not raise_error
|
32
|
+
end.should_not raise_error
|
33
33
|
end
|
34
34
|
|
35
35
|
it "raises an error on negative timeout" do
|
@@ -24,12 +24,6 @@ describe '#brpoplpush(source, destination, timeout)' do
|
|
24
24
|
@redises.brpoplpush(@list1, @list2, 0).should == "B"
|
25
25
|
end
|
26
26
|
|
27
|
-
it "allows subsecond timeout" do
|
28
|
-
lambda do
|
29
|
-
@redises.brpoplpush(@list1, @list2, 0.5)
|
30
|
-
end.should_not raise_error(Redis::CommandError)
|
31
|
-
end
|
32
|
-
|
33
27
|
it "raises an error on negative timeout" do
|
34
28
|
lambda do
|
35
29
|
@redises.brpoplpush(@list1, @list2, -1)
|
data/spec/commands/del_spec.rb
CHANGED
@@ -27,4 +27,8 @@ describe '#del(key [, key, ...])' do
|
|
27
27
|
@redises.get('mock-redis-test:1').should be_nil
|
28
28
|
@redises.get('mock-redis-test:2').should be_nil
|
29
29
|
end
|
30
|
+
|
31
|
+
it "raises an error if an empty array is given" do
|
32
|
+
expect { @redises.del [] }.to raise_error Redis::CommandError
|
33
|
+
end
|
30
34
|
end
|
@@ -39,12 +39,12 @@ describe "#expire(key, seconds)" do
|
|
39
39
|
|
40
40
|
before do
|
41
41
|
@now = Time.now
|
42
|
-
Time.stub
|
42
|
+
Time.stub(:now).and_return(@now)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "removes keys after enough time has passed" do
|
46
46
|
@mock.expire(@key, 5)
|
47
|
-
Time.stub
|
47
|
+
Time.stub(:now).and_return(@now + 5)
|
48
48
|
@mock.get(@key).should be_nil
|
49
49
|
end
|
50
50
|
|
@@ -52,15 +52,15 @@ describe "#expire(key, seconds)" do
|
|
52
52
|
@mock.expire(@key, 5)
|
53
53
|
@mock.expire(@key, 6)
|
54
54
|
|
55
|
-
Time.stub
|
55
|
+
Time.stub(:now).and_return(@now + 5)
|
56
56
|
@mock.get(@key).should_not be_nil
|
57
57
|
end
|
58
58
|
|
59
59
|
it "has millisecond precision" do
|
60
60
|
@now = Time.at(@now.to_i + 0.5)
|
61
|
-
Time.stub
|
61
|
+
Time.stub(:now).and_return(@now)
|
62
62
|
@mock.expire(@key, 5)
|
63
|
-
Time.stub
|
63
|
+
Time.stub(:now).and_return(@now + 4.9)
|
64
64
|
@mock.get(@key).should_not be_nil
|
65
65
|
end
|
66
66
|
|
@@ -73,7 +73,7 @@ describe "#expire(key, seconds)" do
|
|
73
73
|
@mock.del(@key)
|
74
74
|
@mock.set(@key, 'string')
|
75
75
|
|
76
|
-
Time.stub
|
76
|
+
Time.stub(:now).and_return(@now + 2)
|
77
77
|
|
78
78
|
@mock.get(@key).should_not be_nil
|
79
79
|
end
|
@@ -85,7 +85,7 @@ describe "#expire(key, seconds)" do
|
|
85
85
|
|
86
86
|
@mock.rpush(@key, 'coconuts')
|
87
87
|
|
88
|
-
Time.stub
|
88
|
+
Time.stub(:now).and_return(@now + 2)
|
89
89
|
|
90
90
|
@mock.lindex(@key, 0).should_not be_nil
|
91
91
|
end
|
@@ -35,12 +35,12 @@ describe "#expireat(key, timestamp)" do
|
|
35
35
|
|
36
36
|
before do
|
37
37
|
@now = Time.now
|
38
|
-
Time.stub
|
38
|
+
Time.stub(:now).and_return(@now)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "removes keys after enough time has passed" do
|
42
42
|
@mock.expireat(@key, @now.to_i + 5)
|
43
|
-
Time.stub
|
43
|
+
Time.stub(:now).and_return(@now + 5)
|
44
44
|
@mock.get(@key).should be_nil
|
45
45
|
end
|
46
46
|
|
@@ -35,13 +35,13 @@ describe "#persist(key)" do
|
|
35
35
|
|
36
36
|
before do
|
37
37
|
@now = Time.now
|
38
|
-
Time.stub
|
38
|
+
Time.stub(:now).and_return(@now)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "makes keys stay around" do
|
42
42
|
@mock.expire(@key, 5)
|
43
43
|
@mock.persist(@key)
|
44
|
-
Time.stub
|
44
|
+
Time.stub(:now).and_return(@now + 5)
|
45
45
|
@mock.get(@key).should_not be_nil
|
46
46
|
end
|
47
47
|
|
@@ -39,12 +39,12 @@ describe "#pexpire(key, ms)" do
|
|
39
39
|
|
40
40
|
before do
|
41
41
|
@now = Time.now.round
|
42
|
-
Time.stub
|
42
|
+
Time.stub(:now).and_return(@now)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "removes keys after enough time has passed" do
|
46
46
|
@mock.pexpire(@key, 5)
|
47
|
-
Time.stub
|
47
|
+
Time.stub(:now).and_return(@now + Rational(6, 1000))
|
48
48
|
@mock.get(@key).should be_nil
|
49
49
|
end
|
50
50
|
|
@@ -52,7 +52,7 @@ describe "#pexpire(key, ms)" do
|
|
52
52
|
@mock.pexpire(@key, 5)
|
53
53
|
@mock.pexpire(@key, 6)
|
54
54
|
|
55
|
-
Time.stub
|
55
|
+
Time.stub(:now).and_return(@now + Rational(5, 1000))
|
56
56
|
@mock.get(@key).should_not be_nil
|
57
57
|
end
|
58
58
|
|
@@ -65,7 +65,7 @@ describe "#pexpire(key, ms)" do
|
|
65
65
|
@mock.del(@key)
|
66
66
|
@mock.set(@key, 'string')
|
67
67
|
|
68
|
-
Time.stub
|
68
|
+
Time.stub(:now).and_return(@now + 0.003)
|
69
69
|
|
70
70
|
@mock.get(@key).should_not be_nil
|
71
71
|
end
|
@@ -77,7 +77,7 @@ describe "#pexpire(key, ms)" do
|
|
77
77
|
|
78
78
|
@mock.rpush(@key, 'coconuts')
|
79
79
|
|
80
|
-
Time.stub
|
80
|
+
Time.stub(:now).and_return(@now + 0.003)
|
81
81
|
|
82
82
|
@mock.lindex(@key, 0).should_not be_nil
|
83
83
|
end
|
@@ -36,12 +36,12 @@ describe "#pexpireat(key, timestamp_ms)" do
|
|
36
36
|
|
37
37
|
before do
|
38
38
|
@now = Time.now
|
39
|
-
Time.stub
|
39
|
+
Time.stub(:now).and_return(@now)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "removes keys after enough time has passed" do
|
43
43
|
@mock.pexpireat(@key, (@now.to_f * 1000).to_i + 5)
|
44
|
-
Time.stub
|
44
|
+
Time.stub(:now).and_return(@now + 0.006)
|
45
45
|
@mock.get(@key).should be_nil
|
46
46
|
end
|
47
47
|
end
|
data/spec/commands/pttl_spec.rb
CHANGED
data/spec/commands/set_spec.rb
CHANGED
@@ -40,14 +40,14 @@ describe '#set(key, value)' do
|
|
40
40
|
|
41
41
|
before do
|
42
42
|
@now = Time.now
|
43
|
-
Time.stub
|
43
|
+
Time.stub(:now).and_return(@now)
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'accepts EX seconds' do
|
47
47
|
key = 'mock-redis-test'
|
48
48
|
@mock.set(key, 1, ex: 1).should == 'OK'
|
49
49
|
@mock.get(key).should_not be_nil
|
50
|
-
Time.stub
|
50
|
+
Time.stub(:now).and_return(@now + 2)
|
51
51
|
@mock.get(key).should be_nil
|
52
52
|
end
|
53
53
|
|
@@ -55,7 +55,7 @@ describe '#set(key, value)' do
|
|
55
55
|
key = 'mock-redis-test'
|
56
56
|
@mock.set(key, 1, px: 1000).should == 'OK'
|
57
57
|
@mock.get(key).should_not be_nil
|
58
|
-
Time.stub
|
58
|
+
Time.stub(:now).and_return(@now + 2)
|
59
59
|
@mock.get(key).should be_nil
|
60
60
|
end
|
61
61
|
end
|
data/spec/commands/ttl_spec.rb
CHANGED
data/spec/transactions_spec.rb
CHANGED
@@ -28,10 +28,9 @@ describe 'transactions (multi/exec/discard)' do
|
|
28
28
|
lambda do
|
29
29
|
@redises.mock.multi do |r|
|
30
30
|
# do stuff that succeed
|
31
|
-
|
31
|
+
r.set(nil, 'string')
|
32
32
|
end
|
33
|
-
end.should_not raise_error
|
34
|
-
|
33
|
+
end.should_not raise_error
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
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.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Causes Engineering
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ~>
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0
|
20
|
+
version: '10.0'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0
|
27
|
+
version: '10.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: redis
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - ~>
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 2.
|
48
|
+
version: 2.14.0
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 2.
|
55
|
+
version: 2.14.0
|
56
56
|
description: Instantiate one with `redis = MockRedis.new` and treat it like you would
|
57
57
|
a normal Redis object. It supports all the usual Redis operations.
|
58
58
|
email:
|
@@ -63,6 +63,7 @@ extra_rdoc_files: []
|
|
63
63
|
files:
|
64
64
|
- .gitignore
|
65
65
|
- .mailmap
|
66
|
+
- .overcommit.yml
|
66
67
|
- .rspec
|
67
68
|
- .travis.yml
|
68
69
|
- CHANGELOG.md
|
@@ -97,6 +98,7 @@ files:
|
|
97
98
|
- spec/commands/auth_spec.rb
|
98
99
|
- spec/commands/bgrewriteaof_spec.rb
|
99
100
|
- spec/commands/bgsave_spec.rb
|
101
|
+
- spec/commands/bitcount_spec.rb
|
100
102
|
- spec/commands/blpop_spec.rb
|
101
103
|
- spec/commands/brpop_spec.rb
|
102
104
|
- spec/commands/brpoplpush_spec.rb
|
@@ -256,6 +258,7 @@ test_files:
|
|
256
258
|
- spec/commands/auth_spec.rb
|
257
259
|
- spec/commands/bgrewriteaof_spec.rb
|
258
260
|
- spec/commands/bgsave_spec.rb
|
261
|
+
- spec/commands/bitcount_spec.rb
|
259
262
|
- spec/commands/blpop_spec.rb
|
260
263
|
- spec/commands/brpop_spec.rb
|
261
264
|
- spec/commands/brpoplpush_spec.rb
|