mock_redis 0.52.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: 9e933ae58d27e242f827d68d17dc8361327ce7c662cba7973ca4a44c4c9265a7
4
- data.tar.gz: f9bd080555a7c7f3aaec09d5e55327281b3a2860d5045d4e172812def4ea8c82
3
+ metadata.gz: bc774e7b8052b25ca3ca059f197038b854da5cd7d82cae73d5b786cd94fdd318
4
+ data.tar.gz: 674f66037a10dbae4fc547e402931d689a9a1603ffa20335e394c0b9d37db90d
5
5
  SHA512:
6
- metadata.gz: c09ef4f19dce4b289f5a205a1d34c284d0c78b98969cfeb8aa04eb76d5a10cf41e5d88f8bb2d85332a5d37d66d09c6262bc19f179ffce2e0e754113c8bfdaa71
7
- data.tar.gz: a8e824ef5dbf40a9406404eb5c8b5e2bd3cde46c0be994f36724be3beac97bb1f2d4168d557ede3c15f3085e8a03f155d4a88f48b83720b28c1779b8ebd5a0a0
6
+ metadata.gz: 4934a3233fc0f9bae10f33ced22aac334038f9d7e11563105b19ea4f591980242f16c06c73503342791415af09633189a9f7c57788cd6cf050cdda50374436a4
7
+ data.tar.gz: 166130d7f1cb05e56eaff5be78b52a388bf8eeed60552d95b64884b14139d931323fae97bbcc879f204a61e96e0be833f8f7d3f4d8a7712af2df8adbafe1b68b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # MockRedis Changelog
2
2
 
3
+ ### 0.53.0
4
+
5
+ * Fix `redis.call("info")`
6
+
3
7
  ### 0.52.0
4
8
 
5
9
  * Fix handling of `expire*` via `.call`
@@ -49,13 +49,18 @@ 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
52
+ # flatten any nested arrays (eg from [:call, ["GET", "X"]] in pipelined commands)
53
+ command = command.flatten
54
54
 
55
- if command[0].downcase.to_s.include?('expire')
55
+ cmd_name = command[0].downcase.to_s
56
+
57
+ if cmd_name.include?('expire')
56
58
  send_expires(command)
59
+ elsif cmd_name == 'info'
60
+ # call(:info) returns a string, not a parsed hash
61
+ info_raw(*command[1..])
57
62
  else
58
- public_send(command[0].downcase, *command[1..])
63
+ public_send(cmd_name, *command[1..])
59
64
  end
60
65
  end
61
66
 
@@ -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.52.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.52.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-08-21 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.52.0/CHANGELOG.md
128
- documentation_uri: https://www.rubydoc.info/gems/mock_redis/0.52.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.52.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: []