mock_redis 0.51.0 → 0.53.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: 4f278d6ac15f13918a500dcac29da0b08ffe9ea98a1de2ffbd85b1f15458288c
4
- data.tar.gz: d7de319b624279223b559191e3074f302dd3e0756361c3b8518bf54a48c65459
3
+ metadata.gz: bc774e7b8052b25ca3ca059f197038b854da5cd7d82cae73d5b786cd94fdd318
4
+ data.tar.gz: 674f66037a10dbae4fc547e402931d689a9a1603ffa20335e394c0b9d37db90d
5
5
  SHA512:
6
- metadata.gz: 751aadfbe494b01f02366846da113c70b88f7b50183eb7720be068b8d3e4216405d611c1cc4c7e601a0d7ccded20c5e53b610d81b3c83057c7edc3f310682f43
7
- data.tar.gz: df3486c232915f484be3d8b5979d7f2a128698d7f3f3069d0121ebd1108b07ef77e305b2945d2cf21fdef9fabc9a8b690d83a116c7009ec6662e92ed1c7991bd
6
+ metadata.gz: 4934a3233fc0f9bae10f33ced22aac334038f9d7e11563105b19ea4f591980242f16c06c73503342791415af09633189a9f7c57788cd6cf050cdda50374436a4
7
+ data.tar.gz: 166130d7f1cb05e56eaff5be78b52a388bf8eeed60552d95b64884b14139d931323fae97bbcc879f204a61e96e0be833f8f7d3f4d8a7712af2df8adbafe1b68b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # MockRedis Changelog
2
2
 
3
+ ### 0.53.0
4
+
5
+ * Fix `redis.call("info")`
6
+
7
+ ### 0.52.0
8
+
9
+ * Fix handling of `expire*` via `.call`
10
+
3
11
  ### 0.51.0
4
12
 
5
13
  * Improve performance of `hmget` when fetching many fields
@@ -49,9 +49,19 @@ class MockRedis
49
49
  # i.e. `call("EXPIRE", "foo", 40, "NX")` (which redis-rb will simply transmit to redis-server)
50
50
  # will be passed to `#expire` without keywords transformation.
51
51
  def call(*command, &_block)
52
- # allow for single array argument or multiple arguments
53
- command = command[0] if command.length == 1
54
- public_send(command[0].downcase, *command[1..])
52
+ # flatten any nested arrays (eg from [:call, ["GET", "X"]] in pipelined commands)
53
+ command = command.flatten
54
+
55
+ cmd_name = command[0].downcase.to_s
56
+
57
+ if cmd_name.include?('expire')
58
+ send_expires(command)
59
+ elsif cmd_name == 'info'
60
+ # call(:info) returns a string, not a parsed hash
61
+ info_raw(*command[1..])
62
+ else
63
+ public_send(cmd_name, *command[1..])
64
+ end
55
65
  end
56
66
 
57
67
  def auth(_)
@@ -351,6 +361,11 @@ class MockRedis
351
361
  !!Float(str) rescue false
352
362
  end
353
363
 
364
+ def send_expires(command)
365
+ command, key, ttl, option = *command
366
+ public_send(command, key, ttl, option.downcase.to_sym => option)
367
+ end
368
+
354
369
  def should_update_expiration?(expiry, new_expiry, nx:, xx:, lt:, gt:) # rubocop:disable Metrics/ParameterLists
355
370
  return false if nx && expiry || xx && !expiry
356
371
  return false if lt && expiry && new_expiry > expiry
@@ -125,35 +125,65 @@ class MockRedis
125
125
  }.freeze
126
126
  # rubocop:enable Layout/LineLength
127
127
 
128
- DEFAULT_INFO = [
129
- SERVER_INFO,
130
- CLIENTS_INFO,
131
- MEMORY_INFO,
132
- PERSISTENCE_INFO,
133
- STATS_INFO,
134
- REPLICATION_INFO,
135
- CPU_INFO,
136
- KEYSPACE_INFO,
137
- ].inject({}) { |memo, info| memo.merge(info) }
138
-
139
- ALL_INFO = [
140
- DEFAULT_INFO,
141
- COMMAND_STATS_COMBINED_INFO,
142
- ].inject({}) { |memo, info| memo.merge(info) }
128
+ SECTIONS = {
129
+ server: SERVER_INFO,
130
+ clients: CLIENTS_INFO,
131
+ memory: MEMORY_INFO,
132
+ persistence: PERSISTENCE_INFO,
133
+ stats: STATS_INFO,
134
+ replication: REPLICATION_INFO,
135
+ cpu: CPU_INFO,
136
+ keyspace: KEYSPACE_INFO,
137
+ commandstats: COMMAND_STATS_COMBINED_INFO,
138
+ }.freeze
139
+ SECTION_NAMES = {
140
+ server: 'Server',
141
+ clients: 'Clients',
142
+ memory: 'Memory',
143
+ persistence: 'Persistence',
144
+ stats: 'Stats',
145
+ replication: 'Replication',
146
+ cpu: 'Cpu',
147
+ keyspace: 'Keyspace',
148
+ commandstats: 'Commandstats',
149
+ }.freeze
150
+ DEFAULT_SECTIONS = [
151
+ :server, :clients, :memory, :persistence, :stats, :replication, :cpu, :keyspace
152
+ ].freeze
153
+ ALL_SECTIONS = DEFAULT_SECTIONS + [:commandstats].freeze
143
154
 
144
155
  def info(section = :default)
156
+ if section.to_s.downcase == 'commandstats'
157
+ # `redis.info(:commandstats)` gives a nested hash structure,
158
+ # unlike when commandstats is printed as part of `redis.info(:all)`
159
+ COMMAND_STATS_SOLO_INFO
160
+ else
161
+ sections = relevant_info_sections(section)
162
+ sections.inject({}) { |memo, name| memo.merge(SECTIONS[name]) }
163
+ end
164
+ end
165
+
166
+ private
167
+
168
+ # Format info hash as raw string (used by call("info"))
169
+ def info_raw(section = :default)
170
+ sections = relevant_info_sections(section)
171
+ sections.map do |name|
172
+ header = "# #{SECTION_NAMES[name]}"
173
+ lines = SECTIONS[name].map { |k, v| "#{k}:#{v}" }
174
+ [header, *lines].join("\n")
175
+ end.join("\n\n") << "\n"
176
+ end
177
+
178
+ def relevant_info_sections(section)
179
+ section = section.to_s.downcase.to_sym
145
180
  case section
146
- when :default; DEFAULT_INFO
147
- when :all; ALL_INFO
148
- when :server; SERVER_INFO
149
- when :clients; CLIENTS_INFO
150
- when :memory; MEMORY_INFO
151
- when :persistence; PERSISTENCE_INFO
152
- when :stats; STATS_INFO
153
- when :replication; REPLICATION_INFO
154
- when :cpu; CPU_INFO
155
- when :keyspace; KEYSPACE_INFO
156
- when :commandstats; COMMAND_STATS_SOLO_INFO
181
+ when :default
182
+ DEFAULT_SECTIONS
183
+ when :all
184
+ ALL_SECTIONS
185
+ else
186
+ [section]
157
187
  end
158
188
  end
159
189
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  class MockRedis
5
- VERSION = '0.51.0'
5
+ VERSION = '0.53.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.51.0
4
+ version: 0.53.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
8
  - Samuel Merritt
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2025-07-18 00:00:00.000000000 Z
12
+ date: 2025-11-08 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: redis
@@ -124,10 +125,11 @@ licenses:
124
125
  - MIT
125
126
  metadata:
126
127
  bug_tracker_uri: https://github.com/sds/mock_redis/issues
127
- changelog_uri: https://github.com/sds/mock_redis/blob/v0.51.0/CHANGELOG.md
128
- documentation_uri: https://www.rubydoc.info/gems/mock_redis/0.51.0
128
+ changelog_uri: https://github.com/sds/mock_redis/blob/v0.53.0/CHANGELOG.md
129
+ documentation_uri: https://www.rubydoc.info/gems/mock_redis/0.53.0
129
130
  homepage_uri: https://github.com/sds/mock_redis
130
- source_code_uri: https://github.com/sds/mock_redis/tree/v0.51.0
131
+ source_code_uri: https://github.com/sds/mock_redis/tree/v0.53.0
132
+ post_install_message:
131
133
  rdoc_options: []
132
134
  require_paths:
133
135
  - lib
@@ -142,7 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
144
  - !ruby/object:Gem::Version
143
145
  version: '0'
144
146
  requirements: []
145
- rubygems_version: 3.6.2
147
+ rubygems_version: 3.0.3.1
148
+ signing_key:
146
149
  specification_version: 4
147
150
  summary: Redis mock that just lives in memory; useful for testing.
148
151
  test_files: []