mock_redis 0.29.0 → 0.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +31 -0
- data/.github/workflows/tests.yml +45 -0
- data/CHANGELOG.md +5 -0
- data/README.md +2 -2
- data/lib/mock_redis/database.rb +13 -6
- data/lib/mock_redis/stream.rb +9 -9
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis.rb +3 -1
- data/spec/commands/hset_spec.rb +1 -1
- data/spec/commands/xadd_spec.rb +1 -1
- data/spec/mock_redis_spec.rb +1 -1
- metadata +8 -7
- data/.travis.yml +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15bcc9fb58837462df30acd61176547493ce217061459f2c73e134f8ce15c5ab
|
4
|
+
data.tar.gz: 46df9da818b1b4cdf817a2d8700d6321c182934379974aaa21393bd588b6ab04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7322c682d6b702f98afcfd42aac3fe7c6676d63e064d977ddbbfdbaf0f40bca96cd88636e7fd43384dc00455e4421f56555342aabe5707af28ea084587060db9
|
7
|
+
data.tar.gz: 36fa3abf3f2eef55e305a79ea6010edf90ba561e89b10466942f4f8f587c82cb400d97dae0cd330ff8bb73a494cff5171a8b3ab09485cdf76ae0804e9d1af0bb
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: Lint
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches: [main]
|
5
|
+
pull_request:
|
6
|
+
branches: [main]
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
overcommit:
|
10
|
+
timeout-minutes: 10
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: ruby/setup-ruby@v1.97.0
|
18
|
+
with:
|
19
|
+
ruby-version: 2.7
|
20
|
+
|
21
|
+
- name: Install dependencies
|
22
|
+
run: bundle install
|
23
|
+
|
24
|
+
- name: Prepare environment
|
25
|
+
run: |
|
26
|
+
git config --local user.email "gh-actions@example.com"
|
27
|
+
git config --local user.name "GitHub Actions"
|
28
|
+
bundle exec overcommit --sign
|
29
|
+
|
30
|
+
- name: Run pre-commit checks
|
31
|
+
run: bundle exec overcommit --run
|
@@ -0,0 +1,45 @@
|
|
1
|
+
name: Tests
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches: [main]
|
5
|
+
pull_request:
|
6
|
+
branches: [main]
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
rspec:
|
10
|
+
timeout-minutes: 10
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby-version:
|
16
|
+
- '2.6'
|
17
|
+
- '2.7'
|
18
|
+
- '3.0'
|
19
|
+
redis-version:
|
20
|
+
- '6.2'
|
21
|
+
|
22
|
+
services:
|
23
|
+
redis:
|
24
|
+
image: redis:${{ matrix.redis-version }}-alpine
|
25
|
+
options: >-
|
26
|
+
--health-cmd "redis-cli ping"
|
27
|
+
--health-interval 10s
|
28
|
+
--health-timeout 5s
|
29
|
+
--health-retries 5
|
30
|
+
ports:
|
31
|
+
- 6379:6379
|
32
|
+
|
33
|
+
steps:
|
34
|
+
- uses: actions/checkout@v2
|
35
|
+
|
36
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
37
|
+
uses: ruby/setup-ruby@v1.97.0
|
38
|
+
with:
|
39
|
+
ruby-version: ${{ matrix.ruby-version }}
|
40
|
+
|
41
|
+
- name: Install dependencies
|
42
|
+
run: bundle install
|
43
|
+
|
44
|
+
- name: Run tests
|
45
|
+
run: bundle exec rspec
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# MockRedis Changelog
|
2
2
|
|
3
|
+
### 0.30.0
|
4
|
+
|
5
|
+
* Drop support for Ruby 2.4 and Ruby 2.5 since they are EOL
|
6
|
+
* Fix `expire` to to raise error on invalid integer
|
7
|
+
|
3
8
|
### 0.29.0
|
4
9
|
|
5
10
|
* Add support for `logger` option ([#211](https://github.com/sds/mock_redis/pull/211))
|
data/README.md
CHANGED
@@ -10,9 +10,9 @@ for use in tests.
|
|
10
10
|
|
11
11
|
## Requirements
|
12
12
|
|
13
|
-
|
13
|
+
Ruby 2.6+
|
14
14
|
|
15
|
-
The current implementation is tested against
|
15
|
+
The current implementation is tested against Redis 6.2. Older versions may work, but can also return different results or not support some commands.
|
16
16
|
|
17
17
|
## Getting Started
|
18
18
|
|
data/lib/mock_redis/database.rb
CHANGED
@@ -86,27 +86,27 @@ class MockRedis
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def expire(key, seconds)
|
89
|
+
assert_valid_integer(seconds)
|
90
|
+
|
89
91
|
pexpire(key, seconds.to_i * 1000)
|
90
92
|
end
|
91
93
|
|
92
94
|
def pexpire(key, ms)
|
95
|
+
assert_valid_integer(ms)
|
96
|
+
|
93
97
|
now, miliseconds = @base.now
|
94
98
|
now_ms = (now * 1000) + miliseconds
|
95
99
|
pexpireat(key, now_ms + ms.to_i)
|
96
100
|
end
|
97
101
|
|
98
102
|
def expireat(key, timestamp)
|
99
|
-
|
100
|
-
raise Redis::CommandError, 'ERR value is not an integer or out of range'
|
101
|
-
end
|
103
|
+
assert_valid_integer(timestamp)
|
102
104
|
|
103
105
|
pexpireat(key, timestamp.to_i * 1000)
|
104
106
|
end
|
105
107
|
|
106
108
|
def pexpireat(key, timestamp_ms)
|
107
|
-
|
108
|
-
raise Redis::CommandError, 'ERR value is not an integer or out of range'
|
109
|
-
end
|
109
|
+
assert_valid_integer(timestamp_ms)
|
110
110
|
|
111
111
|
if exists?(key)
|
112
112
|
timestamp = Rational(timestamp_ms.to_i, 1000)
|
@@ -280,6 +280,13 @@ class MockRedis
|
|
280
280
|
|
281
281
|
private
|
282
282
|
|
283
|
+
def assert_valid_integer(integer)
|
284
|
+
unless looks_like_integer?(integer.to_s)
|
285
|
+
raise Redis::CommandError, 'ERR value is not an integer or out of range'
|
286
|
+
end
|
287
|
+
integer
|
288
|
+
end
|
289
|
+
|
283
290
|
def assert_valid_timeout(timeout)
|
284
291
|
if !looks_like_integer?(timeout.to_s)
|
285
292
|
raise Redis::CommandError, 'ERR timeout is not an integer or out of range'
|
data/lib/mock_redis/stream.rb
CHANGED
@@ -49,15 +49,15 @@ class MockRedis
|
|
49
49
|
opts = options opts_in, ['count']
|
50
50
|
start_id = MockRedis::Stream::Id.new(start)
|
51
51
|
finish_id = MockRedis::Stream::Id.new(finish, sequence: Float::INFINITY)
|
52
|
-
if start_id.exclusive
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
52
|
+
items = if start_id.exclusive
|
53
|
+
members
|
54
|
+
.select { |m| (start_id < m[0]) && (finish_id >= m[0]) }
|
55
|
+
.map { |m| [m[0].to_s, m[1]] }
|
56
|
+
else
|
57
|
+
members
|
58
|
+
.select { |m| (start_id <= m[0]) && (finish_id >= m[0]) }
|
59
|
+
.map { |m| [m[0].to_s, m[1]] }
|
60
|
+
end
|
61
61
|
items.reverse! if reversed
|
62
62
|
return items.first(opts['count'].to_i) if opts.key?('count')
|
63
63
|
items
|
data/lib/mock_redis/version.rb
CHANGED
data/lib/mock_redis.rb
CHANGED
@@ -167,7 +167,9 @@ class MockRedis
|
|
167
167
|
t1 = Time.now
|
168
168
|
yield
|
169
169
|
ensure
|
170
|
-
|
170
|
+
if t1
|
171
|
+
logger.debug(format('[MockRedis] call_time=%<time>0.2f ms', time: ((Time.now - t1) * 1000)))
|
172
|
+
end
|
171
173
|
end
|
172
174
|
end
|
173
175
|
end
|
data/spec/commands/hset_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe '#hset(key, field)' do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'stores fields sent in a hash' do
|
38
|
-
@redises.hset(@key, {'k1' => 'v1', 'k2' => 'v2'}).should == 2
|
38
|
+
@redises.hset(@key, { 'k1' => 'v1', 'k2' => 'v2' }).should == 2
|
39
39
|
end
|
40
40
|
|
41
41
|
it_should_behave_like 'a hash-only command'
|
data/spec/commands/xadd_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe '#xadd("mystream", { f1: "v1", f2: "v2" }, id: "0-0", maxlen: 1000, app
|
|
15
15
|
it 'returns an id based on the timestamp' do
|
16
16
|
t = Time.now.to_i
|
17
17
|
id = @redises.xadd(@key, { key: 'value' })
|
18
|
-
expect(
|
18
|
+
expect(id).to match(/#{t}\d{3}-0/)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'adds data with symbols' do
|
data/spec/mock_redis_spec.rb
CHANGED
@@ -87,7 +87,7 @@ describe MockRedis do
|
|
87
87
|
logger = double('Logger', debug?: true, debug: nil)
|
88
88
|
mock_redis = MockRedis.new(logger: logger)
|
89
89
|
expect(logger).to receive(:debug).with(/command=HMGET args="hash" "key1" "key2"/)
|
90
|
-
mock_redis.hmget(
|
90
|
+
mock_redis.hmget('hash', 'key1', 'key2')
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.30.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane da Silva
|
8
8
|
- Samuel Merritt
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-02-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby2_keywords
|
@@ -89,6 +89,8 @@ executables: []
|
|
89
89
|
extensions: []
|
90
90
|
extra_rdoc_files: []
|
91
91
|
files:
|
92
|
+
- ".github/workflows/lint.yml"
|
93
|
+
- ".github/workflows/tests.yml"
|
92
94
|
- ".gitignore"
|
93
95
|
- ".mailmap"
|
94
96
|
- ".overcommit.yml"
|
@@ -96,7 +98,6 @@ files:
|
|
96
98
|
- ".rubocop.yml"
|
97
99
|
- ".rubocop_todo.yml"
|
98
100
|
- ".simplecov"
|
99
|
-
- ".travis.yml"
|
100
101
|
- CHANGELOG.md
|
101
102
|
- Gemfile
|
102
103
|
- LICENSE.md
|
@@ -295,7 +296,7 @@ homepage: https://github.com/sds/mock_redis
|
|
295
296
|
licenses:
|
296
297
|
- MIT
|
297
298
|
metadata: {}
|
298
|
-
post_install_message:
|
299
|
+
post_install_message:
|
299
300
|
rdoc_options: []
|
300
301
|
require_paths:
|
301
302
|
- lib
|
@@ -310,8 +311,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
310
311
|
- !ruby/object:Gem::Version
|
311
312
|
version: '0'
|
312
313
|
requirements: []
|
313
|
-
rubygems_version: 3.1.
|
314
|
-
signing_key:
|
314
|
+
rubygems_version: 3.1.6
|
315
|
+
signing_key:
|
315
316
|
specification_version: 4
|
316
317
|
summary: Redis mock that just lives in memory; useful for testing.
|
317
318
|
test_files:
|
data/.travis.yml
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
cache: bundler
|
4
|
-
|
5
|
-
addons:
|
6
|
-
apt:
|
7
|
-
packages:
|
8
|
-
- redis-server
|
9
|
-
|
10
|
-
services:
|
11
|
-
- redis-server
|
12
|
-
|
13
|
-
before_install:
|
14
|
-
- sudo sed -e 's/^bind.*/bind 127.0.0.1/' /etc/redis/redis.conf > redis.conf
|
15
|
-
- sudo mv redis.conf /etc/redis
|
16
|
-
- sudo service redis-server start
|
17
|
-
- echo PING | nc localhost 6379
|
18
|
-
|
19
|
-
rvm:
|
20
|
-
- 2.4
|
21
|
-
- 2.5
|
22
|
-
- 2.6
|
23
|
-
- 2.7
|
24
|
-
|
25
|
-
before_script:
|
26
|
-
- git config --local user.email "travis@travis.ci"
|
27
|
-
- git config --local user.name "Travis CI"
|
28
|
-
|
29
|
-
script:
|
30
|
-
- redis-cli --version
|
31
|
-
- bundle exec rspec
|
32
|
-
- bundle exec overcommit --sign
|
33
|
-
- bundle exec overcommit --run
|