mock_redis 0.40.0 → 0.42.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a994c84019da05c17affd08708c56468251ad9c8667893b5841d57c238ae5ad
4
- data.tar.gz: 3d21509554037fc70d813de8265ea64c8dce549c8bbbb2d4872875e83a01fcb1
3
+ metadata.gz: 7c029cb2a22c5d9bdb8fd8d9f1f1266f8d3312d74672024d3e90a4704eb5ff2d
4
+ data.tar.gz: 28d10360caaf1cf17441155a1add6e03f593c22ea1b6565b1100de38db0c632a
5
5
  SHA512:
6
- metadata.gz: 1db6f45379ac2252fd1024e8eecdf1a3f49289bd457cd63cb075c2baa19fdb9e1e775c537c7089e184e7d7e644d6d30b81f796516fa8bd3631bab623154e9531
7
- data.tar.gz: 5177f6c22cd0f7561ee9eaf46ebce4ba1f43f0c2b461fe87baa4c50dfe76ffeee05db2c5cc552e90431be44d01aa293ed6a672bd7a303ab16f0f6ee5659ea34e
6
+ metadata.gz: 2190dafa783552b41b965ec49b97f9dc4183f32d99bd78a3b93ad61c6c1cabc9f62233cd14b6ec7c178bf125dffa214188e4db37111eb8c9b044c5ea285ebcbd
7
+ data.tar.gz: acbdd8e328413f1288fef8a6f0ddead0387630677d2bbb3ae8ef3e02253e45be315ce7243afe257a51931f3cc71a5965ed16705b5dda9fad1c71dedb106e0574
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # MockRedis Changelog
2
2
 
3
+ ### 0.42.0
4
+
5
+ * Drop support for Ruby 2.x
6
+ * Add support for `srem?`
7
+
8
+ ### 0.41.0
9
+
10
+ * Add support for `expire`-related command options `nx`/`xx`/`lt`/`gt`
11
+
3
12
  ### 0.40.0
4
13
 
5
14
  * Add support for `call` method name to be case insensitive
data/README.md CHANGED
@@ -10,7 +10,7 @@ for use in tests.
10
10
 
11
11
  ## Requirements
12
12
 
13
- Ruby 2.7+
13
+ Ruby 3.0+
14
14
 
15
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
 
@@ -43,6 +43,9 @@ class MockRedis
43
43
 
44
44
  # Redis commands go below this line and above 'private'
45
45
 
46
+ # FIXME: Current implementation of `call` does not work propetly with kwarg-options.
47
+ # i.e. `call("EXPIRE", "foo", 40, "NX")` (which redis-rb will simply transmit to redis-server)
48
+ # will be passed to `#expire` without keywords transformation.
46
49
  def call(command, &_block)
47
50
  public_send(command[0].downcase, *command[1..])
48
51
  end
@@ -89,32 +92,42 @@ class MockRedis
89
92
  msg.to_s
90
93
  end
91
94
 
92
- def expire(key, seconds)
95
+ def expire(key, seconds, nx: nil, xx: nil, lt: nil, gt: nil) # rubocop:disable Metrics/ParameterLists
93
96
  assert_valid_integer(seconds)
94
97
 
95
- pexpire(key, seconds.to_i * 1000)
98
+ pexpire(key, seconds.to_i * 1000, nx: nx, xx: xx, lt: lt, gt: gt)
96
99
  end
97
100
 
98
- def pexpire(key, ms)
101
+ def pexpire(key, ms, nx: nil, xx: nil, lt: nil, gt: nil) # rubocop:disable Metrics/ParameterLists
99
102
  assert_valid_integer(ms)
100
103
 
101
104
  now, miliseconds = @base.now
102
105
  now_ms = (now * 1000) + miliseconds
103
- pexpireat(key, now_ms + ms.to_i)
106
+ pexpireat(key, now_ms + ms.to_i, nx: nx, xx: xx, lt: lt, gt: gt)
104
107
  end
105
108
 
106
- def expireat(key, timestamp)
109
+ def expireat(key, timestamp, nx: nil, xx: nil, lt: nil, gt: nil) # rubocop:disable Metrics/ParameterLists
107
110
  assert_valid_integer(timestamp)
108
111
 
109
- pexpireat(key, timestamp.to_i * 1000)
112
+ pexpireat(key, timestamp.to_i * 1000, nx: nx, xx: xx, lt: lt, gt: gt)
110
113
  end
111
114
 
112
- def pexpireat(key, timestamp_ms)
115
+ def pexpireat(key, timestamp_ms, nx: nil, xx: nil, lt: nil, gt: nil) # rubocop:disable Metrics/ParameterLists
113
116
  assert_valid_integer(timestamp_ms)
114
117
 
115
- if exists?(key)
116
- timestamp = Rational(timestamp_ms.to_i, 1000)
117
- set_expiration(key, @base.time_at(timestamp))
118
+ if nx && gt || gt && lt || lt && nx || nx && xx
119
+ raise Redis::CommandError, <<~TXT.chomp
120
+ ERR NX and XX, GT or LT options at the same time are not compatible
121
+ TXT
122
+ end
123
+
124
+ return false unless exists?(key)
125
+
126
+ expiry = expiration(key)
127
+ new_expiry = @base.time_at(Rational(timestamp_ms.to_i, 1000))
128
+
129
+ if should_update_expiration?(expiry, new_expiry, nx: nx, xx: xx, lt: lt, gt: gt)
130
+ set_expiration(key, new_expiry)
118
131
  true
119
132
  else
120
133
  false
@@ -324,7 +337,7 @@ class MockRedis
324
337
  end
325
338
 
326
339
  def expiration(key)
327
- expire_times.find { |(_, k)| k == key.to_s }.first
340
+ expire_times.find { |(_, k)| k == key.to_s }&.first
328
341
  end
329
342
 
330
343
  def has_expiration?(key)
@@ -339,6 +352,14 @@ class MockRedis
339
352
  !!Float(str) rescue false
340
353
  end
341
354
 
355
+ def should_update_expiration?(expiry, new_expiry, nx:, xx:, lt:, gt:) # rubocop:disable Metrics/ParameterLists
356
+ return false if nx && expiry || xx && !expiry
357
+ return false if lt && expiry && new_expiry > expiry
358
+ return false if gt && (!expiry || new_expiry < expiry)
359
+
360
+ true
361
+ end
362
+
342
363
  def redis_pattern_to_ruby_regex(pattern)
343
364
  Regexp.new(
344
365
  "^#{pattern}$".
@@ -1,7 +1,7 @@
1
1
  class MockRedis
2
2
  module GeospatialMethods
3
- LNG_RANGE = (-180..180).freeze
4
- LAT_RANGE = (-85.05112878..85.05112878).freeze
3
+ LNG_RANGE = (-180..180)
4
+ LAT_RANGE = (-85.05112878..85.05112878)
5
5
  STEP = 26
6
6
  UNITS = {
7
7
  m: 1,
@@ -137,6 +137,11 @@ class MockRedis
137
137
  end
138
138
  end
139
139
 
140
+ def srem?(key, members)
141
+ res = srem(key, members)
142
+ res.is_a?(Numeric) ? res > 0 : res
143
+ end
144
+
140
145
  def sscan(key, cursor, opts = {})
141
146
  common_scan(smembers(key), cursor, opts)
142
147
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  class MockRedis
5
- VERSION = '0.40.0'
5
+ VERSION = '0.42.0'
6
6
  end
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.40.0
4
+ version: 0.42.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: 2023-11-16 00:00:00.000000000 Z
12
+ date: 2024-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -123,10 +123,10 @@ licenses:
123
123
  - MIT
124
124
  metadata:
125
125
  bug_tracker_uri: https://github.com/sds/mock_redis/issues
126
- changelog_uri: https://github.com/sds/mock_redis/blob/v0.40.0/CHANGELOG.md
127
- documentation_uri: https://www.rubydoc.info/gems/mock_redis/0.40.0
126
+ changelog_uri: https://github.com/sds/mock_redis/blob/v0.42.0/CHANGELOG.md
127
+ documentation_uri: https://www.rubydoc.info/gems/mock_redis/0.42.0
128
128
  homepage_uri: https://github.com/sds/mock_redis
129
- source_code_uri: https://github.com/sds/mock_redis/tree/v0.40.0
129
+ source_code_uri: https://github.com/sds/mock_redis/tree/v0.42.0
130
130
  post_install_message:
131
131
  rdoc_options: []
132
132
  require_paths:
@@ -135,14 +135,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '2.7'
138
+ version: '3.0'
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - ">="
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
144
  requirements: []
145
- rubygems_version: 3.1.6
145
+ rubygems_version: 3.4.10
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: Redis mock that just lives in memory; useful for testing.