Proposal: Add Redis::CommandRecorder

Problem

We have a tool to detect N+1 queries for database, however the N+1 problem can occur in Redis too. At the moment, we don't have a convenient way to identify them in tests.

Proposal

Add a Redis::CommandRecorder class with a similar interface as ActiveRecord::QueryRecorder.

Record all commands during the execution

control = Redis::CommandRecorder.new { subject.execute }

expect(control.count).to eq(10)

Record only specific keys

control = Redis::CommandRecorder.new(pattern: 'branch_names') { subject.execute }

expect(control.count).to eq(2)

Access only specific commands

control = Redis::CommandRecorder.new { subject.execute }

expect(control.by_name(:get).count).to eq(5)

MVC prototype

!93180 (merged)

Roadmap

  • Create a simple implementation of Redis::CommandRecorder - !93180 (merged)
  • Add documentation for Redis::CommandRecorder
  • Add Rspec matchers to simplify the testing (for example, exceed_all_query_limit)
  • Extend Redis::CommandRecorder with additional methods if needed

Please leave a comment you have any ideas, suggestions. 📝

Edited by Vasilii Iakliushin