Skip to content

Commit 2965954

Browse files
committed
refactor: specify redis_rb when we are referring to gem
refactor: change name of slowlog method to be less confusing with redis_rb version
1 parent 4e764e7 commit 2965954

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

inject_slow_query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
REDIS = SlowlogCheck::Redis.new(
1616
host: ENV.fetch('REDIS_HOST')
17-
).redis
17+
).redis_rb
1818

1919
if ARGV[0].nil?
2020
raise "Specify milliseconds to inject as the first positional argument to `#{__FILE__}`"

lib/slowlog_check.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def pad_results_with_zero(report)
152152

153153
def slowlogs_by_flush_interval
154154
result = reporting_interval
155-
@redis.slowlog.each do |slowlog|
155+
@redis.slowlog_get.each do |slowlog|
156156
time = slowlog_time(slowlog)
157157
break if minute_precision(time) <= minute_precision(last_time_submitted)
158158

lib/slowlog_check/redis.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def params
2727
end
2828
end
2929

30-
def redis
31-
@redis ||= ::Redis.new(params)
30+
def redis_rb
31+
@redis_rb ||= ::Redis.new(params)
3232
end
3333

3434
def replication_group
@@ -39,13 +39,13 @@ def replication_group
3939
end
4040
end
4141

42-
def slowlog(length = 128)
43-
resp = redis.slowlog('get', length)
42+
def slowlog_get(length = 128)
43+
resp = redis_rb.slowlog('get', length)
4444

4545
return resp if length > MAXLENGTH
4646
return resp if did_i_get_it_all?(resp)
4747

48-
slowlog(length * 2)
48+
slowlog_get(length * 2)
4949
end
5050

5151
private

spec/slowlog_check/redis_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,14 @@
189189
end
190190
end
191191

192-
describe '#slowlog' do
192+
describe '#slowlog_get' do
193193
include_context 'CME:TLS' # which context doesn't matter, so pick any one
194194

195195
# mock the redis-rb gem
196196
let(:redis_rb) { double }
197-
before(:example) { allow(redis).to receive(:redis).and_return(redis_rb) }
197+
before(:example) { allow(redis).to receive(:redis_rb).and_return(redis_rb) }
198198

199-
describe '#slowlog.length' do
199+
describe '#slowlog_get.length' do
200200
context 'redis has 4 entries' do
201201
before(:each) do
202202
# see spec_helper for redis_slowlog definition
@@ -210,7 +210,7 @@
210210
}
211211
end
212212

213-
subject { redis.slowlog.length }
213+
subject { redis.slowlog_get.length }
214214
it { is_expected.to eq(4) }
215215
end
216216

@@ -229,7 +229,7 @@
229229
}
230230
end
231231

232-
subject { redis.slowlog.length }
232+
subject { redis.slowlog_get.length }
233233
it { is_expected.to eq(129) }
234234
end
235235

@@ -245,7 +245,7 @@
245245
}
246246
end
247247

248-
subject { redis.slowlog.length }
248+
subject { redis.slowlog_get.length }
249249
it { is_expected.to eq(1_048_576 * 2) } # with the last entry dropped
250250
end
251251

@@ -261,7 +261,7 @@
261261
}
262262
end
263263

264-
subject { redis.slowlog.length }
264+
subject { redis.slowlog_get.length }
265265
it { is_expected.to eq(567) }
266266
end
267267
end

spec/slowlog_check_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
slowlog_check.instance_variable_set(:@redis, redis)
2828
allow(redis).to receive(:replication_group).and_call_original
2929

30-
allow(redis).to receive(:slowlog) {
30+
allow(redis).to receive(:slowlog_get) {
3131
[
3232
redis_slowlog(3, Time.utc(2020, 4, 20, 4, 19, 45), 400_000),
3333
redis_slowlog(2, Time.utc(2020, 4, 20, 4, 19, 15), 100_000),
@@ -257,7 +257,7 @@ def example_bucket(index)
257257
end
258258

259259
before(:example) do
260-
allow(redis).to receive(:slowlog) {
260+
allow(redis).to receive(:slowlog_get) {
261261
Array.new(5) do |x|
262262
redis_slowlog(x, Time.utc(2020, 0o4, 20, 0o4, 15, 10) + (x * 60), x + 1000, x.to_s)
263263
end.reverse

0 commit comments

Comments
 (0)