mock_redis 0.29.0 → 0.32.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 +63 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +2 -1
- data/README.md +3 -3
- data/lib/mock_redis/database.rb +15 -8
- data/lib/mock_redis/hash_methods.rb +3 -1
- data/lib/mock_redis/stream.rb +9 -9
- data/lib/mock_redis/string_methods.rb +10 -0
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis.rb +3 -1
- data/spec/commands/expire_spec.rb +1 -1
- data/spec/commands/hmget_spec.rb +6 -0
- data/spec/commands/hset_spec.rb +1 -1
- data/spec/commands/pexpire_spec.rb +1 -1
- data/spec/commands/ping_spec.rb +5 -1
- data/spec/commands/psetex_spec.rb +44 -0
- data/spec/commands/xadd_spec.rb +1 -1
- data/spec/mock_redis_spec.rb +1 -1
- data/spec/spec_helper.rb +14 -8
- metadata +10 -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: b9f945150c69e6ff81838d4e029f1620ade56e9da6c3cb2ed0550cd61060335a
|
4
|
+
data.tar.gz: fbd58f70dbf78b770a6d3e04351771a1d94a7cac87afbff95213c92bceb16eaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9320958fc6e3360f26317dfcb47747bf8d39d626d54c0297cece31b9521fc4ad991acdccf885428d05f8b82765cfec12a37af4de33473f4106c7e3eb4e9c2b69
|
7
|
+
data.tar.gz: 05c04acff0f82500f114a868ed40aef95fc115e367ed94008075ddd90de5550dd939ca12215ffb3c88021a6aeff18cd3f9ff51dfabcc3f14244b40465d6184f0
|
@@ -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,63 @@
|
|
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
|
46
|
+
|
47
|
+
- name: Code coverage reporting
|
48
|
+
uses: coverallsapp/github-action@master
|
49
|
+
with:
|
50
|
+
github-token: ${{ secrets.github_token }}
|
51
|
+
flag-name: ruby${{ matrix.ruby-version }}-${{ matrix.redis-version }}
|
52
|
+
parallel: true
|
53
|
+
|
54
|
+
finish:
|
55
|
+
needs: rspec
|
56
|
+
runs-on: ubuntu-latest
|
57
|
+
|
58
|
+
steps:
|
59
|
+
- name: Finalize code coverage report
|
60
|
+
uses: coverallsapp/github-action@master
|
61
|
+
with:
|
62
|
+
github-token: ${{ secrets.github_token }}
|
63
|
+
parallel-finished: true
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# MockRedis Changelog
|
2
2
|
|
3
|
+
### 0.32.0
|
4
|
+
|
5
|
+
* Add support for `psetex`
|
6
|
+
|
7
|
+
### 0.31.0
|
8
|
+
|
9
|
+
* Allow `ping` to take argument
|
10
|
+
* Raise `CommandError` on `hmget` with empty list of fields
|
11
|
+
|
12
|
+
### 0.30.0
|
13
|
+
|
14
|
+
* Drop support for Ruby 2.4 and Ruby 2.5 since they are EOL
|
15
|
+
* Fix `expire` to to raise error on invalid integer
|
16
|
+
|
3
17
|
### 0.29.0
|
4
18
|
|
5
19
|
* Add support for `logger` option ([#211](https://github.com/sds/mock_redis/pull/211))
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# MockRedis
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/mock_redis.svg)](http://badge.fury.io/rb/mock_redis)
|
4
|
-
|
4
|
+
![Build Status](https://github.com/sds/mock_redis/actions/workflows/tests.yml/badge.svg)
|
5
5
|
[![Coverage Status](https://coveralls.io/repos/sds/mock_redis/badge.svg)](https://coveralls.io/r/sds/mock_redis)
|
6
6
|
|
7
7
|
MockRedis provides the same interface as `redis-rb`, but it stores its
|
@@ -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)
|
@@ -178,8 +178,8 @@ class MockRedis
|
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
|
-
def ping
|
182
|
-
|
181
|
+
def ping(response = 'PONG')
|
182
|
+
response
|
183
183
|
end
|
184
184
|
|
185
185
|
def quit
|
@@ -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
|
@@ -328,6 +328,16 @@ class MockRedis
|
|
328
328
|
end
|
329
329
|
end
|
330
330
|
|
331
|
+
def psetex(key, milliseconds, value)
|
332
|
+
if milliseconds <= 0
|
333
|
+
raise Redis::CommandError, 'ERR invalid expire time in psetex'
|
334
|
+
else
|
335
|
+
set(key, value)
|
336
|
+
pexpire(key, milliseconds)
|
337
|
+
'OK'
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
331
341
|
def setnx(key, value)
|
332
342
|
if exists?(key)
|
333
343
|
false
|
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/hmget_spec.rb
CHANGED
@@ -36,5 +36,11 @@ describe '#hmget(key, field [, field, ...])' do
|
|
36
36
|
end.should raise_error(Redis::CommandError)
|
37
37
|
end
|
38
38
|
|
39
|
+
it 'raises an error if given an empty list of fields' do
|
40
|
+
lambda do
|
41
|
+
@redises.hmget(@key, [])
|
42
|
+
end.should raise_error(Redis::CommandError)
|
43
|
+
end
|
44
|
+
|
39
45
|
it_should_behave_like 'a hash-only command'
|
40
46
|
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/ping_spec.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#psetex(key, miliseconds, value)' do
|
4
|
+
before { @key = 'mock-redis-test:setex' }
|
5
|
+
|
6
|
+
it "responds with 'OK'" do
|
7
|
+
@redises.psetex(@key, 10, 'value').should == 'OK'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'sets the value' do
|
11
|
+
@redises.psetex(@key, 10_000, 'value')
|
12
|
+
@redises.get(@key).should == 'value'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'sets the expiration time' do
|
16
|
+
@redises.psetex(@key, 10_000, 'value')
|
17
|
+
|
18
|
+
# no guarantee these are the same
|
19
|
+
@redises.real.ttl(@key).should > 0
|
20
|
+
@redises.mock.ttl(@key).should > 0
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'converts time correctly' do
|
24
|
+
@redises.psetex(@key, 10_000_000, 'value')
|
25
|
+
|
26
|
+
@redises.mock.ttl(@key).should > 9_000
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when expiration time is zero' do
|
30
|
+
it 'raises Redis::CommandError' do
|
31
|
+
expect do
|
32
|
+
@redises.psetex(@key, 0, 'value')
|
33
|
+
end.to raise_error(Redis::CommandError, 'ERR invalid expire time in psetex')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when expiration time is negative' do
|
38
|
+
it 'raises Redis::CommandError' do
|
39
|
+
expect do
|
40
|
+
@redises.psetex(@key, -2, 'value')
|
41
|
+
end.to raise_error(Redis::CommandError, 'ERR invalid expire time in psetex')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter 'spec/'
|
4
|
+
|
5
|
+
if ENV['CI']
|
6
|
+
require 'simplecov-lcov'
|
7
|
+
|
8
|
+
SimpleCov::Formatter::LcovFormatter.config do |c|
|
9
|
+
c.report_with_single_file = true
|
10
|
+
c.single_report_path = 'coverage/lcov.info'
|
11
|
+
end
|
12
|
+
|
13
|
+
formatter SimpleCov::Formatter::LcovFormatter
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
11
17
|
require 'rspec/its'
|
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.32.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-06-12 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
|
@@ -210,6 +211,7 @@ files:
|
|
210
211
|
- spec/commands/pexpireat_spec.rb
|
211
212
|
- spec/commands/ping_spec.rb
|
212
213
|
- spec/commands/pipelined_spec.rb
|
214
|
+
- spec/commands/psetex_spec.rb
|
213
215
|
- spec/commands/pttl_spec.rb
|
214
216
|
- spec/commands/quit_spec.rb
|
215
217
|
- spec/commands/randomkey_spec.rb
|
@@ -295,7 +297,7 @@ homepage: https://github.com/sds/mock_redis
|
|
295
297
|
licenses:
|
296
298
|
- MIT
|
297
299
|
metadata: {}
|
298
|
-
post_install_message:
|
300
|
+
post_install_message:
|
299
301
|
rdoc_options: []
|
300
302
|
require_paths:
|
301
303
|
- lib
|
@@ -310,8 +312,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
310
312
|
- !ruby/object:Gem::Version
|
311
313
|
version: '0'
|
312
314
|
requirements: []
|
313
|
-
rubygems_version: 3.1.
|
314
|
-
signing_key:
|
315
|
+
rubygems_version: 3.1.6
|
316
|
+
signing_key:
|
315
317
|
specification_version: 4
|
316
318
|
summary: Redis mock that just lives in memory; useful for testing.
|
317
319
|
test_files:
|
@@ -396,6 +398,7 @@ test_files:
|
|
396
398
|
- spec/commands/pexpireat_spec.rb
|
397
399
|
- spec/commands/ping_spec.rb
|
398
400
|
- spec/commands/pipelined_spec.rb
|
401
|
+
- spec/commands/psetex_spec.rb
|
399
402
|
- spec/commands/pttl_spec.rb
|
400
403
|
- spec/commands/quit_spec.rb
|
401
404
|
- spec/commands/randomkey_spec.rb
|
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
|