Skip to content

Commit

Permalink
Coalesce "current pipeline or redis" into the redis method itself
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lewispb committed Jun 24, 2022
1 parent 4291815 commit 516c14a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/kredis/types/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Kredis::Types::Proxy
require_relative "proxy/failsafe"
include Failsafe

attr_accessor :redis, :key
attr_accessor :key

thread_mattr_accessor :pipeline

Expand All @@ -23,12 +23,16 @@ def multi(*args, **kwargs, &block)
def method_missing(method, *args, **kwargs)
Kredis.instrument :proxy, **log_message(method, *args, **kwargs) do
failsafe do
(pipeline || redis).public_send method, key, *args, **kwargs
redis.public_send method, key, *args, **kwargs
end
end
end

private
def redis
pipeline || @redis
end

def log_message(method, *args, **kwargs)
args = args.flatten.reject(&:blank?).presence
kwargs = kwargs.reject { |_k, v| v.blank? }.presence
Expand Down
4 changes: 2 additions & 2 deletions lib/kredis/types/proxying.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require "active_support/core_ext/module/delegation"

class Kredis::Types::Proxying
attr_accessor :proxy, :redis, :key
attr_accessor :proxy, :key

def self.proxying(*commands)
delegate *commands, to: :proxy
end

def initialize(redis, key, **options)
@redis, @key = redis, key
@key = key
@proxy = Kredis::Types::Proxy.new(redis, key)
options.each { |key, value| send("#{key}=", value) }
end
Expand Down

0 comments on commit 516c14a

Please sign in to comment.