mock_redis 0.26.0 → 0.27.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/.travis.yml +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +2 -0
- data/lib/mock_redis.rb +1 -1
- data/lib/mock_redis/connection_method.rb +13 -0
- data/lib/mock_redis/database.rb +2 -0
- data/lib/mock_redis/expire_wrapper.rb +1 -1
- data/lib/mock_redis/geospatial_methods.rb +1 -1
- data/lib/mock_redis/multi_db_wrapper.rb +1 -1
- data/lib/mock_redis/pipelined_wrapper.rb +1 -1
- data/lib/mock_redis/stream.rb +1 -4
- data/lib/mock_redis/string_methods.rb +14 -15
- data/lib/mock_redis/transaction_wrapper.rb +1 -1
- data/lib/mock_redis/version.rb +1 -1
- data/spec/commands/connection_spec.rb +15 -0
- data/spec/commands/del_spec.rb +3 -1
- data/spec/commands/set_spec.rb +52 -6
- data/spec/commands/xadd_spec.rb +5 -5
- data/spec/commands/xlen_spec.rb +3 -1
- data/spec/spec_helper.rb +1 -2
- data/spec/support/redis_multiplexer.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b491b0b8e260ee631a3633b35154946ef5822a3310d6bc51ce977febe8559b8a
|
4
|
+
data.tar.gz: 795a9ec1aa340ee6b0733b3a539a0ff355dc5e71287f59ca03f2ae64ef9e770e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea3fd9aabe7c3afac9c358dbe97a2ffb78277a1d0dab830d6b9983404a1a9f3b2b47f97022441b62884ce01fb6557b1b5a8ca334378bc18ba6c0863b577a947a
|
7
|
+
data.tar.gz: 4a487e49858bed2684e8695affe470801de0a6247c1a7281c1f1f3a6913f59ebe38fffee8fa0a41142d20d65cb8339cbb4dd4c2d03ddc2ed5d538760f59fc959
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# MockRedis Changelog
|
2
2
|
|
3
|
+
### 0.27.0
|
4
|
+
|
5
|
+
* Fix handling of keyword arguments on Ruby 3 ([#199](https://github.com/sds/mock_redis/pull/199))
|
6
|
+
* Allow passing string `offset` to `setbit` ([#200](https://github.com/sds/mock_redis/pull/200))
|
7
|
+
* Add `connection` method ([#201](https://github.com/sds/mock_redis/pull/201))
|
8
|
+
|
3
9
|
### 0.26.0
|
4
10
|
|
5
11
|
* Add block and count support to `xread` ([#194](https://github.com/sds/mock_redis/pull/194))
|
data/Gemfile
CHANGED
data/lib/mock_redis.rb
CHANGED
data/lib/mock_redis/database.rb
CHANGED
@@ -11,6 +11,7 @@ require 'mock_redis/info_method'
|
|
11
11
|
require 'mock_redis/utility_methods'
|
12
12
|
require 'mock_redis/geospatial_methods'
|
13
13
|
require 'mock_redis/stream_methods'
|
14
|
+
require 'mock_redis/connection_method'
|
14
15
|
|
15
16
|
class MockRedis
|
16
17
|
class Database
|
@@ -24,6 +25,7 @@ class MockRedis
|
|
24
25
|
include UtilityMethods
|
25
26
|
include GeospatialMethods
|
26
27
|
include StreamMethods
|
28
|
+
include ConnectionMethod
|
27
29
|
|
28
30
|
attr_reader :data, :expire_times
|
29
31
|
|
@@ -18,7 +18,7 @@ class MockRedis
|
|
18
18
|
@pipelined_futures = @pipelined_futures.clone
|
19
19
|
end
|
20
20
|
|
21
|
-
def method_missing(method, *args, &block)
|
21
|
+
ruby2_keywords def method_missing(method, *args, &block)
|
22
22
|
if in_pipeline?
|
23
23
|
future = MockRedis::Future.new([method, *args], block)
|
24
24
|
@pipelined_futures << future
|
data/lib/mock_redis/stream.rb
CHANGED
@@ -25,10 +25,7 @@ class MockRedis
|
|
25
25
|
@last_id = MockRedis::Stream::Id.new(id, min: @last_id)
|
26
26
|
if @last_id.to_s == '0-0'
|
27
27
|
raise Redis::CommandError,
|
28
|
-
|
29
|
-
'the target stream top item'
|
30
|
-
# TOOD: Redis version 6.0.4, w redis 4.2.1 generates the following error message:
|
31
|
-
# 'ERR The ID specified in XADD must be greater than 0-0'
|
28
|
+
'ERR The ID specified in XADD must be greater than 0-0'
|
32
29
|
end
|
33
30
|
members.add [@last_id, Hash[values.map { |k, v| [k.to_s, v.to_s] }]]
|
34
31
|
@last_id.to_s
|
@@ -201,18 +201,19 @@ class MockRedis
|
|
201
201
|
msetnx(*hash.to_a.flatten)
|
202
202
|
end
|
203
203
|
|
204
|
-
|
204
|
+
# Parameer list required to ensure the ArgumentError is returned correctly
|
205
|
+
# rubocop:disable Metrics/ParameterLists
|
206
|
+
def set(key, value, ex: nil, px: nil, nx: nil, xx: nil, keepttl: nil)
|
205
207
|
key = key.to_s
|
206
208
|
return_true = false
|
207
|
-
|
208
|
-
if options.delete(:nx)
|
209
|
+
if nx
|
209
210
|
if exists?(key)
|
210
211
|
return false
|
211
212
|
else
|
212
213
|
return_true = true
|
213
214
|
end
|
214
215
|
end
|
215
|
-
if
|
216
|
+
if xx
|
216
217
|
if exists?(key)
|
217
218
|
return_true = true
|
218
219
|
else
|
@@ -221,27 +222,24 @@ class MockRedis
|
|
221
222
|
end
|
222
223
|
data[key] = value.to_s
|
223
224
|
|
224
|
-
|
225
|
-
if
|
226
|
-
if
|
225
|
+
remove_expiration(key) unless keepttl
|
226
|
+
if ex
|
227
|
+
if ex == 0
|
227
228
|
raise Redis::CommandError, 'ERR invalid expire time in set'
|
228
229
|
end
|
229
|
-
expire(key,
|
230
|
+
expire(key, ex)
|
230
231
|
end
|
231
232
|
|
232
|
-
|
233
|
-
|
234
|
-
if duration == 0
|
233
|
+
if px
|
234
|
+
if px == 0
|
235
235
|
raise Redis::CommandError, 'ERR invalid expire time in set'
|
236
236
|
end
|
237
|
-
pexpire(key,
|
238
|
-
end
|
239
|
-
unless options.empty?
|
240
|
-
raise ArgumentError, "unknown keyword: #{options.keys[0]}"
|
237
|
+
pexpire(key, px)
|
241
238
|
end
|
242
239
|
|
243
240
|
return_true ? true : 'OK'
|
244
241
|
end
|
242
|
+
# rubocop:enable Metrics/ParameterLists
|
245
243
|
|
246
244
|
def setbit(key, offset, value)
|
247
245
|
assert_stringy(key, 'ERR bit is not an integer or out of range')
|
@@ -249,6 +247,7 @@ class MockRedis
|
|
249
247
|
|
250
248
|
str = data[key] || ''
|
251
249
|
|
250
|
+
offset = offset.to_i
|
252
251
|
offset_of_byte = offset / 8
|
253
252
|
offset_within_byte = offset % 8
|
254
253
|
|
@@ -15,7 +15,7 @@ class MockRedis
|
|
15
15
|
@multi_block_given = false
|
16
16
|
end
|
17
17
|
|
18
|
-
def method_missing(method, *args, &block)
|
18
|
+
ruby2_keywords def method_missing(method, *args, &block)
|
19
19
|
if in_multi?
|
20
20
|
future = MockRedis::Future.new([method, *args], block)
|
21
21
|
@transaction_futures << future
|
data/lib/mock_redis/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#connection' do
|
4
|
+
let(:redis) { @redises.mock }
|
5
|
+
|
6
|
+
it 'returns the correct values' do
|
7
|
+
redis.connection.should == {
|
8
|
+
:host => '127.0.0.1',
|
9
|
+
:port => 6379,
|
10
|
+
:db => 0,
|
11
|
+
:id => 'redis://127.0.0.1:6379/0',
|
12
|
+
:location => '127.0.0.1:6379'
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
data/spec/commands/del_spec.rb
CHANGED
@@ -6,7 +6,9 @@ describe '#del(key [, key, ...])' do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
before :each do
|
9
|
-
|
9
|
+
# TODO: Redis appears to be returning a timestamp a few seconds in the future
|
10
|
+
# so we're ignoring the last 5 digits (time in milliseconds)
|
11
|
+
@redises._gsub(/\d{5}-\d/, '...-.')
|
10
12
|
end
|
11
13
|
|
12
14
|
it 'returns the number of keys deleted' do
|
data/spec/commands/set_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe '#set(key, value)' do
|
4
|
+
let(:key) { 'mock-redis-test' }
|
5
|
+
|
4
6
|
it "responds with 'OK'" do
|
5
7
|
@redises.set('mock-redis-test', 1).should == 'OK'
|
6
8
|
end
|
@@ -19,26 +21,72 @@ describe '#set(key, value)' do
|
|
19
21
|
end
|
20
22
|
|
21
23
|
it 'accepts NX' do
|
22
|
-
key = 'mock-redis-test'
|
23
24
|
@redises.del(key)
|
24
25
|
@redises.set(key, 1, nx: true).should == true
|
25
26
|
@redises.set(key, 1, nx: true).should == false
|
26
27
|
end
|
27
28
|
|
28
29
|
it 'accepts XX' do
|
29
|
-
key = 'mock-redis-test'
|
30
30
|
@redises.del(key)
|
31
31
|
@redises.set(key, 1, xx: true).should == false
|
32
32
|
@redises.set(key, 1).should == 'OK'
|
33
33
|
@redises.set(key, 1, xx: true).should == true
|
34
34
|
end
|
35
35
|
|
36
|
+
it 'sets the ttl to -1' do
|
37
|
+
@redises.set(key, 1)
|
38
|
+
expect(@redises.ttl(key)).to eq(-1)
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with an expiry time' do
|
42
|
+
before :each do
|
43
|
+
Timecop.freeze
|
44
|
+
@redises.set(key, 1, ex: 90)
|
45
|
+
end
|
46
|
+
|
47
|
+
after :each do
|
48
|
+
@redises.del(key)
|
49
|
+
Timecop.return
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'has the TTL set' do
|
53
|
+
expect(@redises.ttl(key)).to eq 90
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'resets the TTL without keepttl' do
|
57
|
+
expect do
|
58
|
+
@redises.set(key, 2)
|
59
|
+
end.to change { @redises.ttl(key) }.from(90).to(-1)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'does not change the TTL with keepttl: true' do
|
63
|
+
expect do
|
64
|
+
@redises.set(key, 2, keepttl: true)
|
65
|
+
end.not_to change { @redises.ttl(key) }.from(90)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'accepts KEEPTTL' do
|
70
|
+
expect(@redises.set(key, 1, keepttl: true)).to eq 'OK'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does not set TTL without ex' do
|
74
|
+
@redises.set(key, 1)
|
75
|
+
expect(@redises.ttl(key)).to eq(-1)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'sets the TTL' do
|
79
|
+
Timecop.freeze do
|
80
|
+
@redises.set(key, 1, ex: 90)
|
81
|
+
expect(@redises.ttl(key)).to eq 90
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
36
85
|
it 'raises on unknown options' do
|
37
|
-
key = 'mock-redis-test'
|
38
86
|
@redises.del(key)
|
39
87
|
expect do
|
40
88
|
@redises.set(key, 1, logger: :something)
|
41
|
-
end.to raise_error(ArgumentError,
|
89
|
+
end.to raise_error(ArgumentError, /unknown keyword/)
|
42
90
|
end
|
43
91
|
|
44
92
|
context '[mock only]' do
|
@@ -52,7 +100,6 @@ describe '#set(key, value)' do
|
|
52
100
|
end
|
53
101
|
|
54
102
|
it 'accepts EX seconds' do
|
55
|
-
key = 'mock-redis-test'
|
56
103
|
@mock.set(key, 1, ex: 1).should == 'OK'
|
57
104
|
@mock.get(key).should_not be_nil
|
58
105
|
Time.stub(:now).and_return(@now + 2)
|
@@ -60,7 +107,6 @@ describe '#set(key, value)' do
|
|
60
107
|
end
|
61
108
|
|
62
109
|
it 'accepts PX milliseconds' do
|
63
|
-
key = 'mock-redis-test'
|
64
110
|
@mock.set(key, 1, px: 500).should == 'OK'
|
65
111
|
@mock.get(key).should_not be_nil
|
66
112
|
Time.stub(:now).and_return(@now + 300 / 1000.to_f)
|
data/spec/commands/xadd_spec.rb
CHANGED
@@ -7,11 +7,14 @@ describe '#xadd("mystream", { f1: "v1", f2: "v2" }, id: "0-0", maxlen: 1000, app
|
|
7
7
|
end
|
8
8
|
|
9
9
|
before :each do
|
10
|
-
|
10
|
+
# TODO: Redis appears to be returning a timestamp a few seconds in the future
|
11
|
+
# so we're ignoring the last 5 digits (time in milliseconds)
|
12
|
+
@redises._gsub(/\d{5}-\d/, '....-.')
|
11
13
|
end
|
12
14
|
|
13
15
|
it 'returns an id based on the timestamp' do
|
14
16
|
t = Time.now.to_i
|
17
|
+
id = @redises.xadd(@key, key: 'value')
|
15
18
|
expect(@redises.xadd(@key, key: 'value')).to match(/#{t}\d{3}-0/)
|
16
19
|
end
|
17
20
|
|
@@ -52,10 +55,7 @@ describe '#xadd("mystream", { f1: "v1", f2: "v2" }, id: "0-0", maxlen: 1000, app
|
|
52
55
|
expect { @redises.xadd('mock-redis-test:unknown-stream', { key: 'value' }, id: '0') }
|
53
56
|
.to raise_error(
|
54
57
|
Redis::CommandError,
|
55
|
-
'ERR The ID specified in XADD
|
56
|
-
'stream top item'
|
57
|
-
# TOOD: Redis version 6.0.4, w redis 4.2.1 generates the following error message:
|
58
|
-
# 'ERR The ID specified in XADD must be greater than 0-0'
|
58
|
+
'ERR The ID specified in XADD must be greater than 0-0'
|
59
59
|
)
|
60
60
|
end
|
61
61
|
|
data/spec/commands/xlen_spec.rb
CHANGED
@@ -7,7 +7,9 @@ describe '#xlen(key)' do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
before :each do
|
10
|
-
|
10
|
+
# TODO: Redis appears to be returning a timestamp a few seconds in the future
|
11
|
+
# so we're ignoring the last 5 digits (time in milliseconds)
|
12
|
+
@redises._gsub(/\d{5}-\d/, '...-.')
|
11
13
|
end
|
12
14
|
|
13
15
|
it 'returns the number of items in the stream' do
|
data/spec/spec_helper.rb
CHANGED
@@ -11,6 +11,7 @@ end
|
|
11
11
|
require 'rspec/its'
|
12
12
|
require 'redis'
|
13
13
|
$LOAD_PATH.unshift(File.expand_path(File.join(__FILE__, '..', '..', 'lib')))
|
14
|
+
require 'ruby2_keywords'
|
14
15
|
require 'mock_redis'
|
15
16
|
require 'timecop'
|
16
17
|
|
@@ -40,8 +41,6 @@ end
|
|
40
41
|
RSpec.configure do |config|
|
41
42
|
config.expect_with :rspec do |c|
|
42
43
|
c.syntax = [:expect, :should]
|
43
|
-
# Allow for a large output so we can debug error messages
|
44
|
-
c.max_formatted_output_length = 1_000_000
|
45
44
|
end
|
46
45
|
|
47
46
|
config.mock_with :rspec do |c|
|
@@ -23,7 +23,7 @@ class RedisMultiplexer < BlankSlate
|
|
23
23
|
@gsub_from = @gsub_to = ''
|
24
24
|
end
|
25
25
|
|
26
|
-
def method_missing(method, *args, &blk)
|
26
|
+
ruby2_keywords def method_missing(method, *args, &blk)
|
27
27
|
# If we're in a Redis command that accepts a block, and we execute more
|
28
28
|
# redis commands, ONLY execute them on the Redis implementation that the
|
29
29
|
# block came from.
|
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.27.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane da Silva
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- Rakefile
|
91
91
|
- lib/mock_redis.rb
|
92
92
|
- lib/mock_redis/assertions.rb
|
93
|
+
- lib/mock_redis/connection_method.rb
|
93
94
|
- lib/mock_redis/database.rb
|
94
95
|
- lib/mock_redis/exceptions.rb
|
95
96
|
- lib/mock_redis/expire_wrapper.rb
|
@@ -126,6 +127,7 @@ files:
|
|
126
127
|
- spec/commands/brpop_spec.rb
|
127
128
|
- spec/commands/brpoplpush_spec.rb
|
128
129
|
- spec/commands/connected_spec.rb
|
130
|
+
- spec/commands/connection_spec.rb
|
129
131
|
- spec/commands/dbsize_spec.rb
|
130
132
|
- spec/commands/decr_spec.rb
|
131
133
|
- spec/commands/decrby_spec.rb
|
@@ -294,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
294
296
|
- !ruby/object:Gem::Version
|
295
297
|
version: '0'
|
296
298
|
requirements: []
|
297
|
-
rubygems_version: 3.1.
|
299
|
+
rubygems_version: 3.1.4
|
298
300
|
signing_key:
|
299
301
|
specification_version: 4
|
300
302
|
summary: Redis mock that just lives in memory; useful for testing.
|
@@ -311,6 +313,7 @@ test_files:
|
|
311
313
|
- spec/commands/brpop_spec.rb
|
312
314
|
- spec/commands/brpoplpush_spec.rb
|
313
315
|
- spec/commands/connected_spec.rb
|
316
|
+
- spec/commands/connection_spec.rb
|
314
317
|
- spec/commands/dbsize_spec.rb
|
315
318
|
- spec/commands/decr_spec.rb
|
316
319
|
- spec/commands/decrby_spec.rb
|