mock_redis 0.26.0 → 0.28.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c087a47dd536c50c70b1238484a41a46669ca210b53063efd87fc863c83aaa67
4
- data.tar.gz: 41927d6f1904768faaa5f9bbeff4fa803f7dc1045aa76da8f885594326eab326
3
+ metadata.gz: 9dc2b4dd866fe426a0ee5b767bc46668c1ccb515f0b927feeac129b47f28a4a6
4
+ data.tar.gz: cccf8ea1f98f9376afadcc57738eef1578bd07166b08bb5a11eb6c3410412f23
5
5
  SHA512:
6
- metadata.gz: efe4f6cb8a7c3326e8ad06c1753a651dc41323ca1fb4a7f23a1ac080feb09a4192f5d140ddeb437ce7268c0325e9e8bc4270f6d68facc88696d9586b9342d388
7
- data.tar.gz: 7392d8b37355b3c22dd7c51745df2f67497dfb88f2534a5cf5df606e07b6fe47cc7969e4e005da85b4a4e382ef8b7801e220f948db71313330079781a973ff75
6
+ metadata.gz: f8827a5223d959f27d33223904f0cdf705dfa280da700733ea83cb581ddc89ca3e427af39ec247ea05ebb79ecb9fe58ba3e8f2f1b7fd62204aacc65025f010cf
7
+ data.tar.gz: e1e3115c5577f1e22249f3c6b9fb3b82ac1be4b8a4967824cbea5f56ce35efec15154d1f9871de5ba3abc337cbe6d38c9d93787150c8e3262ba30b395bcb58b4
data/.travis.yml CHANGED
@@ -20,6 +20,7 @@ rvm:
20
20
  - 2.4
21
21
  - 2.5
22
22
  - 2.6
23
+ - 2.7
23
24
 
24
25
  before_script:
25
26
  - git config --local user.email "travis@travis.ci"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # MockRedis Changelog
2
2
 
3
+ ### 0.28.0
4
+
5
+ * Fix `hmset` exception ([#206](https://github.com/sds/mock_redis/pull/206))
6
+ * Fix `hmset` to accept hashes in addition to key/value pairs ([#208](https://github.com/sds/mock_redis/pull/208))
7
+ * Fix stream ID regex to support `(` ([#209](https://github.com/sds/mock_redis/pull/209))
8
+ * Allow `mget` to accept a block ([#210](https://github.com/sds/mock_redis/pull/210))
9
+
10
+ ### 0.27.3
11
+
12
+ * Ensure `ruby2_keywords` dependency is `require`d at runtime
13
+
14
+ ### 0.27.2
15
+
16
+ * Switch `ruby2_keywords` gem from development dependency to runtime dependency
17
+
18
+ ### 0.27.1
19
+
20
+ * Fix missing `ruby2_keywords` gem
21
+ * Allow passing string `offset` to `getbit` ([#203](https://github.com/sds/mock_redis/pull/203))
22
+
23
+ ### 0.27.0
24
+
25
+ * Fix handling of keyword arguments on Ruby 3 ([#199](https://github.com/sds/mock_redis/pull/199))
26
+ * Allow passing string `offset` to `setbit` ([#200](https://github.com/sds/mock_redis/pull/200))
27
+ * Add `connection` method ([#201](https://github.com/sds/mock_redis/pull/201))
28
+
3
29
  ### 0.26.0
4
30
 
5
31
  * Add block and count support to `xread` ([#194](https://github.com/sds/mock_redis/pull/194))
data/lib/mock_redis.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'set'
2
+ require 'ruby2_keywords'
2
3
 
3
4
  require 'mock_redis/assertions'
4
5
  require 'mock_redis/database'
@@ -84,7 +85,7 @@ class MockRedis
84
85
  super || @db.respond_to?(method, include_private)
85
86
  end
86
87
 
87
- def method_missing(method, *args, &block)
88
+ ruby2_keywords def method_missing(method, *args, &block)
88
89
  @db.send(method, *args, &block)
89
90
  end
90
91
 
@@ -0,0 +1,13 @@
1
+ class MockRedis
2
+ module ConnectionMethod
3
+ def connection
4
+ {
5
+ :host => @base.host,
6
+ :port => @base.port,
7
+ :db => @base.db,
8
+ :id => @base.id,
9
+ :location => "#{@base.host}:#{@base.port}"
10
+ }
11
+ end
12
+ end
13
+ end
@@ -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
 
@@ -12,7 +12,7 @@ class MockRedis
12
12
  @db = db
13
13
  end
14
14
 
15
- def method_missing(method, *args, &block)
15
+ ruby2_keywords def method_missing(method, *args, &block)
16
16
  @db.expire_keys
17
17
  @db.send(method, *args, &block)
18
18
  end
@@ -12,7 +12,7 @@ class MockRedis
12
12
  D_R = Math::PI / 180.0
13
13
  EARTH_RADIUS_IN_METERS = 6_372_797.560856
14
14
 
15
- def geoadd(key, *args)
15
+ ruby2_keywords def geoadd(key, *args)
16
16
  points = parse_points(args)
17
17
 
18
18
  scored_points = points.map do |point|
@@ -94,7 +94,7 @@ class MockRedis
94
94
  assert_has_args(kvpairs, 'hmset')
95
95
 
96
96
  if kvpairs.length.odd?
97
- raise Redis::CommandError, err_msg || 'ERR wrong number of arguments for HMSET'
97
+ raise Redis::CommandError, err_msg || 'ERR wrong number of arguments for \'hmset\' command'
98
98
  end
99
99
 
100
100
  kvpairs.each_slice(2) do |(k, v)|
@@ -131,6 +131,10 @@ class MockRedis
131
131
  def hset(key, *args)
132
132
  added = 0
133
133
  with_hash_at(key) do |hash|
134
+ if args.length == 1 && args[0].is_a?(Hash)
135
+ args = args[0].to_a.flatten
136
+ end
137
+
134
138
  args.each_slice(2) do |field, value|
135
139
  added += 1 unless hash.key?(field.to_s)
136
140
  hash[field.to_s] = value.to_s
@@ -17,7 +17,7 @@ class MockRedis
17
17
  super || current_db.respond_to?(method, include_private)
18
18
  end
19
19
 
20
- def method_missing(method, *args, &block)
20
+ ruby2_keywords def method_missing(method, *args, &block)
21
21
  current_db.send(method, *args, &block)
22
22
  end
23
23
 
@@ -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
@@ -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
- 'ERR The ID specified in XADD is equal or smaller than ' \
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
@@ -52,9 +49,15 @@ class MockRedis
52
49
  opts = options opts_in, ['count']
53
50
  start_id = MockRedis::Stream::Id.new(start)
54
51
  finish_id = MockRedis::Stream::Id.new(finish, sequence: Float::INFINITY)
55
- items = members
56
- .select { |m| (start_id <= m[0]) && (finish_id >= m[0]) }
57
- .map { |m| [m[0].to_s, m[1]] }
52
+ if start_id.exclusive
53
+ items = members
54
+ .select { |m| (start_id < m[0]) && (finish_id >= m[0]) }
55
+ .map { |m| [m[0].to_s, m[1]] }
56
+ else
57
+ items = members
58
+ .select { |m| (start_id <= m[0]) && (finish_id >= m[0]) }
59
+ .map { |m| [m[0].to_s, m[1]] }
60
+ end
58
61
  items.reverse! if reversed
59
62
  return items.first(opts['count'].to_i) if opts.key?('count')
60
63
  items
@@ -3,9 +3,10 @@ class MockRedis
3
3
  class Id
4
4
  include Comparable
5
5
 
6
- attr_accessor :timestamp, :sequence
6
+ attr_accessor :timestamp, :sequence, :exclusive
7
7
 
8
8
  def initialize(id, min: nil, sequence: 0)
9
+ @exclusive = false
9
10
  case id
10
11
  when '*'
11
12
  @timestamp = (Time.now.to_f * 1000).to_i
@@ -20,8 +21,12 @@ class MockRedis
20
21
  @timestamp = @sequence = Float::INFINITY
21
22
  else
22
23
  if id.is_a? String
23
- (_, @timestamp, @sequence) = id.match(/^(\d+)-?(\d+)?$/)
24
- .to_a
24
+ # See https://redis.io/topics/streams-intro
25
+ # Ids are a unix timestamp in milliseconds followed by an
26
+ # optional dash sequence number, e.g. -0. They can also optionally
27
+ # be prefixed with '(' to change the XRANGE to exclusive.
28
+ (_, @timestamp, @sequence) = id.match(/^\(?(\d+)-?(\d+)?$/).to_a
29
+ @exclusive = true if id[0] == '('
25
30
  if @timestamp.nil?
26
31
  raise Redis::CommandError,
27
32
  'ERR Invalid stream ID specified as stream command argument'
@@ -93,6 +93,7 @@ class MockRedis
93
93
  def getbit(key, offset)
94
94
  assert_stringy(key)
95
95
 
96
+ offset = offset.to_i
96
97
  offset_of_byte = offset / 8
97
98
  offset_within_byte = offset % 8
98
99
 
@@ -153,14 +154,16 @@ class MockRedis
153
154
  new_value
154
155
  end
155
156
 
156
- def mget(*keys)
157
+ def mget(*keys, &blk)
157
158
  keys.flatten!
158
159
 
159
160
  assert_has_args(keys, 'mget')
160
161
 
161
- keys.map do |key|
162
+ data = keys.map do |key|
162
163
  get(key) if stringy?(key)
163
164
  end
165
+
166
+ blk ? blk.call(data) : data
164
167
  end
165
168
 
166
169
  def mapped_mget(*keys)
@@ -201,18 +204,19 @@ class MockRedis
201
204
  msetnx(*hash.to_a.flatten)
202
205
  end
203
206
 
204
- def set(key, value, options = {})
207
+ # Parameer list required to ensure the ArgumentError is returned correctly
208
+ # rubocop:disable Metrics/ParameterLists
209
+ def set(key, value, ex: nil, px: nil, nx: nil, xx: nil, keepttl: nil)
205
210
  key = key.to_s
206
211
  return_true = false
207
- options = options.dup
208
- if options.delete(:nx)
212
+ if nx
209
213
  if exists?(key)
210
214
  return false
211
215
  else
212
216
  return_true = true
213
217
  end
214
218
  end
215
- if options.delete(:xx)
219
+ if xx
216
220
  if exists?(key)
217
221
  return_true = true
218
222
  else
@@ -221,27 +225,24 @@ class MockRedis
221
225
  end
222
226
  data[key] = value.to_s
223
227
 
224
- duration = options.delete(:ex)
225
- if duration
226
- if duration == 0
228
+ remove_expiration(key) unless keepttl
229
+ if ex
230
+ if ex == 0
227
231
  raise Redis::CommandError, 'ERR invalid expire time in set'
228
232
  end
229
- expire(key, duration)
233
+ expire(key, ex)
230
234
  end
231
235
 
232
- duration = options.delete(:px)
233
- if duration
234
- if duration == 0
236
+ if px
237
+ if px == 0
235
238
  raise Redis::CommandError, 'ERR invalid expire time in set'
236
239
  end
237
- pexpire(key, duration)
238
- end
239
- unless options.empty?
240
- raise ArgumentError, "unknown keyword: #{options.keys[0]}"
240
+ pexpire(key, px)
241
241
  end
242
242
 
243
243
  return_true ? true : 'OK'
244
244
  end
245
+ # rubocop:enable Metrics/ParameterLists
245
246
 
246
247
  def setbit(key, offset, value)
247
248
  assert_stringy(key, 'ERR bit is not an integer or out of range')
@@ -249,6 +250,7 @@ class MockRedis
249
250
 
250
251
  str = data[key] || ''
251
252
 
253
+ offset = offset.to_i
252
254
  offset_of_byte = offset / 8
253
255
  offset_within_byte = offset % 8
254
256
 
@@ -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
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  class MockRedis
5
- VERSION = '0.26.0'
5
+ VERSION = '0.28.0'
6
6
  end
data/mock_redis.gemspec CHANGED
@@ -23,6 +23,8 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.required_ruby_version = '>= 2.4'
25
25
 
26
+ s.add_runtime_dependency 'ruby2_keywords'
27
+
26
28
  s.add_development_dependency 'redis', '~> 4.2.0'
27
29
  s.add_development_dependency 'rspec', '~> 3.0'
28
30
  s.add_development_dependency 'rspec-its', '~> 1.0'
@@ -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
@@ -6,7 +6,9 @@ describe '#del(key [, key, ...])' do
6
6
  end
7
7
 
8
8
  before :each do
9
- @redises._gsub(/\d{3}-\d/, '...-.')
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
@@ -34,5 +34,9 @@ describe '#hset(key, field)' do
34
34
  @redises.hget(@key, '1').should == 'one'
35
35
  end
36
36
 
37
+ it 'stores fields sent in a hash' do
38
+ @redises.hset(@key, {'k1' => 'v1', 'k2' => 'v2'}).should == 2
39
+ end
40
+
37
41
  it_should_behave_like 'a hash-only command'
38
42
  end
@@ -56,4 +56,10 @@ describe '#mget(key [, key, ...])' do
56
56
  end.should raise_error(Redis::CommandError)
57
57
  end
58
58
  end
59
+
60
+ context 'emulate block' do
61
+ it 'returns an array of values' do
62
+ @redises.mget(@key1, @key2) { |values| values.map(&:to_i) }.should == [1, 2]
63
+ end
64
+ end
59
65
  end
@@ -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, 'unknown keyword: logger')
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)
@@ -7,24 +7,27 @@ describe '#xadd("mystream", { f1: "v1", f2: "v2" }, id: "0-0", maxlen: 1000, app
7
7
  end
8
8
 
9
9
  before :each do
10
- @redises._gsub(/\d{3}-\d/, '...-.')
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
15
- expect(@redises.xadd(@key, key: 'value')).to match(/#{t}\d{3}-0/)
17
+ id = @redises.xadd(@key, { key: 'value' })
18
+ expect(@redises.xadd(@key, { key: 'value' })).to match(/#{t}\d{3}-0/)
16
19
  end
17
20
 
18
21
  it 'adds data with symbols' do
19
- @redises.xadd(@key, symbol_key: :symbol_value)
22
+ @redises.xadd(@key, { symbol_key: :symbol_value })
20
23
  expect(@redises.xrange(@key, '-', '+').last[1])
21
24
  .to eq('symbol_key' => 'symbol_value')
22
25
  end
23
26
 
24
27
  it 'increments the sequence number with the same timestamp' do
25
28
  Timecop.freeze do
26
- @redises.xadd(@key, key: 'value')
27
- expect(@redises.xadd(@key, key: 'value')).to match(/\d+-1/)
29
+ @redises.xadd(@key, { key: 'value' })
30
+ expect(@redises.xadd(@key, { key: 'value' })).to match(/\d+-1/)
28
31
  end
29
32
  end
30
33
 
@@ -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 is equal or smaller than the target ' \
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
 
@@ -67,7 +67,7 @@ describe '#xadd("mystream", { f1: "v1", f2: "v2" }, id: "0-0", maxlen: 1000, app
67
67
  it 'caters for the current time being before the last time' do
68
68
  t = (Time.now.to_f * 1000).to_i + 2000
69
69
  @redises.xadd(@key, { key: 'value' }, id: "#{t}-0")
70
- expect(@redises.xadd(@key, key: 'value')).to match(/#{t}-1/)
70
+ expect(@redises.xadd(@key, { key: 'value' })).to match(/#{t}-1/)
71
71
  end
72
72
 
73
73
  it 'appends a sequence number if it is missing' do
@@ -7,14 +7,16 @@ describe '#xlen(key)' do
7
7
  end
8
8
 
9
9
  before :each do
10
- @redises._gsub(/\d{3}-\d/, '...-.')
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
14
16
  expect(@redises.xlen(@key)).to eq 0
15
- @redises.xadd(@key, key: 'value')
17
+ @redises.xadd(@key, { key: 'value' })
16
18
  expect(@redises.xlen(@key)).to eq 1
17
- 3.times { @redises.xadd(@key, key: 'value') }
19
+ 3.times { @redises.xadd(@key, { key: 'value' }) }
18
20
  expect(@redises.xlen(@key)).to eq 4
19
21
  end
20
22
  end
@@ -79,13 +79,23 @@ describe '#xrange("mystream", first: "0-1", last: "0-3", count: 10)' do
79
79
  )
80
80
  end
81
81
 
82
- it 'returns entries with both a lower and an upper limit' do
83
- expect(@redises.xrange(@key, '1234567891239-0', '1234567891285-0')).to eq(
82
+ it 'returns entries with both a lower and an upper limit inclusive' do
83
+ expect(@redises.xrange(@key, '1234567891245-0', '1234567891278-0')).to eq(
84
84
  [
85
85
  ['1234567891245-0', { 'key2' => 'value2' }],
86
86
  ['1234567891245-1', { 'key3' => 'value3' }],
87
+ ['1234567891278-0', { 'key4' => 'value4' }]
88
+ ]
89
+ )
90
+ end
91
+
92
+ it 'returns entries with both a lower and an upper limit exclusive' do
93
+ expect(@redises.xrange(@key, '(1234567891245-0', '1234567891285-1')).to eq(
94
+ [
95
+ # We no longer get '1234567891245-0'
96
+ ['1234567891245-1', { 'key3' => 'value3' }],
87
97
  ['1234567891278-0', { 'key4' => 'value4' }],
88
- ['1234567891278-1', { 'key5' => 'value5' }]
98
+ ['1234567891278-1', { 'key5' => 'value5' }] # Note sequence -1
89
99
  ]
90
100
  )
91
101
  end
data/spec/spec_helper.rb CHANGED
@@ -40,8 +40,6 @@ end
40
40
  RSpec.configure do |config|
41
41
  config.expect_with :rspec do |c|
42
42
  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
43
  end
46
44
 
47
45
  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,16 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.0
4
+ version: 0.28.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: 2020-08-26 00:00:00.000000000 Z
12
+ date: 2021-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ruby2_keywords
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: redis
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -90,6 +104,7 @@ files:
90
104
  - Rakefile
91
105
  - lib/mock_redis.rb
92
106
  - lib/mock_redis/assertions.rb
107
+ - lib/mock_redis/connection_method.rb
93
108
  - lib/mock_redis/database.rb
94
109
  - lib/mock_redis/exceptions.rb
95
110
  - lib/mock_redis/expire_wrapper.rb
@@ -126,6 +141,7 @@ files:
126
141
  - spec/commands/brpop_spec.rb
127
142
  - spec/commands/brpoplpush_spec.rb
128
143
  - spec/commands/connected_spec.rb
144
+ - spec/commands/connection_spec.rb
129
145
  - spec/commands/dbsize_spec.rb
130
146
  - spec/commands/decr_spec.rb
131
147
  - spec/commands/decrby_spec.rb
@@ -279,7 +295,7 @@ homepage: https://github.com/sds/mock_redis
279
295
  licenses:
280
296
  - MIT
281
297
  metadata: {}
282
- post_install_message:
298
+ post_install_message:
283
299
  rdoc_options: []
284
300
  require_paths:
285
301
  - lib
@@ -294,8 +310,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
294
310
  - !ruby/object:Gem::Version
295
311
  version: '0'
296
312
  requirements: []
297
- rubygems_version: 3.1.1
298
- signing_key:
313
+ rubygems_version: 3.1.4
314
+ signing_key:
299
315
  specification_version: 4
300
316
  summary: Redis mock that just lives in memory; useful for testing.
301
317
  test_files:
@@ -311,6 +327,7 @@ test_files:
311
327
  - spec/commands/brpop_spec.rb
312
328
  - spec/commands/brpoplpush_spec.rb
313
329
  - spec/commands/connected_spec.rb
330
+ - spec/commands/connection_spec.rb
314
331
  - spec/commands/dbsize_spec.rb
315
332
  - spec/commands/decr_spec.rb
316
333
  - spec/commands/decrby_spec.rb