Skip to content

Commit 6657887

Browse files
authored
fix: use monkey patch instead of calling Object#send and Object#instance_variable_get (#170)
1 parent 5c949e0 commit 6657887

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

Rakefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# frozen_string_literal: true
22

33
require 'rake/testtask'
4+
require 'rubocop/rake_task'
5+
6+
RuboCop::RakeTask.new
47

58
SLUGGISH_TEST_TYPES = %w[broken scale state].freeze
69

lib/redis_client/cluster/node/latency_replica.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def measure_latencies(clients) # rubocop:disable Metrics/AbcSize
4848
min = DUMMY_LATENCY_NSEC
4949
MEASURE_ATTEMPT_COUNT.times do
5050
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
51-
client.send(:call_once, 'PING')
51+
client.call_once('PING')
5252
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond) - starting
5353
min = duration if duration < min
5454
end

lib/redis_client/cluster/pipeline.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ def call_pipelined_aware_of_redirection(commands, timeouts) # rubocop:disable Me
8181
end
8282
end
8383

84+
::RedisClient.class_eval do
85+
attr_reader :middlewares
86+
87+
def ensure_connected_cluster_scoped(retryable: true, &block)
88+
ensure_connected(retryable: retryable, &block)
89+
end
90+
end
91+
8492
ReplySizeError = Class.new(::RedisClient::Error)
8593

8694
class RedirectionNeeded < ::RedisClient::Error
@@ -198,9 +206,9 @@ def do_pipelining(client, pipeline)
198206
end
199207

200208
def send_pipeline(client, pipeline)
201-
results = client.send(:ensure_connected, retryable: pipeline._retryable?) do |connection|
209+
results = client.ensure_connected_cluster_scoped(retryable: pipeline._retryable?) do |connection|
202210
commands = pipeline._commands
203-
client.instance_variable_get(:@middlewares).call_pipelined(commands, client.config) do
211+
client.middlewares.call_pipelined(commands, client.config) do
204212
connection.call_pipelined_aware_of_redirection(commands, pipeline._timeouts)
205213
end
206214
end

0 commit comments

Comments
 (0)