Skip to content

Commit 516c14a

Browse files
committed
Coalesce "current pipeline or redis" into the redis method itself
Noting that Proxying subclasses that (mistakenly, perhaps) talk to redis directly will need to take care to check for pipeline presence as well. Also remove the redis attr reader from Proxying to prevent mistaken calling of redis without knowledge of the current MULTI state.
1 parent 4291815 commit 516c14a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/kredis/types/proxy.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Kredis::Types::Proxy
22
require_relative "proxy/failsafe"
33
include Failsafe
44

5-
attr_accessor :redis, :key
5+
attr_accessor :key
66

77
thread_mattr_accessor :pipeline
88

@@ -23,12 +23,16 @@ def multi(*args, **kwargs, &block)
2323
def method_missing(method, *args, **kwargs)
2424
Kredis.instrument :proxy, **log_message(method, *args, **kwargs) do
2525
failsafe do
26-
(pipeline || redis).public_send method, key, *args, **kwargs
26+
redis.public_send method, key, *args, **kwargs
2727
end
2828
end
2929
end
3030

3131
private
32+
def redis
33+
pipeline || @redis
34+
end
35+
3236
def log_message(method, *args, **kwargs)
3337
args = args.flatten.reject(&:blank?).presence
3438
kwargs = kwargs.reject { |_k, v| v.blank? }.presence

lib/kredis/types/proxying.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
require "active_support/core_ext/module/delegation"
22

33
class Kredis::Types::Proxying
4-
attr_accessor :proxy, :redis, :key
4+
attr_accessor :proxy, :key
55

66
def self.proxying(*commands)
77
delegate *commands, to: :proxy
88
end
99

1010
def initialize(redis, key, **options)
11-
@redis, @key = redis, key
11+
@key = key
1212
@proxy = Kredis::Types::Proxy.new(redis, key)
1313
options.each { |key, value| send("#{key}=", value) }
1414
end

0 commit comments

Comments
 (0)