class Kredis::Types::Proxy
def initialize(redis, key, **options)
def initialize(redis, key, **options) @redis, @key = redis, key options.each { |key, value| send("#{key}=", value) } end
def log_message(method, *args, **kwargs)
def log_message(method, *args, **kwargs) args = args.flatten.reject(&:blank?).presence kwargs = kwargs.reject { |_k, v| v.blank? }.presence { message: "#{method.upcase} #{key} #{args&.inspect} #{kwargs&.inspect}".chomp } end
def method_missing(method, *args, **kwargs)
def method_missing(method, *args, **kwargs) Kredis.instrument :proxy, **log_message(method, *args, **kwargs) do failsafe do redis.public_send method, key, *args, **kwargs end end end
def multi(*args, **kwargs, &block)
def multi(*args, **kwargs, &block) redis.multi(*args, **kwargs) do |pipeline| self.pipeline = pipeline block.call ensure self.pipeline = nil end end
def redis
def redis pipeline || @redis end
def unwatch
def unwatch redis.unwatch end
def watch(&block)
def watch(&block) redis.watch(key) do block.call end end