@@ -2,19 +2,21 @@ class Kredis::Types::Proxy
22 require_relative "proxy/failsafe"
33 include Failsafe
44
5- attr_accessor :redis , :key
5+ attr_accessor :key
6+
7+ thread_mattr_accessor :pipeline
68
79 def initialize ( redis , key , **options )
810 @redis , @key = redis , key
911 options . each { |key , value | send ( "#{ key } =" , value ) }
1012 end
1113
12- def multi ( &block )
13- # NOTE: to be removed when Redis 4 compatibility gets dropped
14- return redis . multi unless block
15-
16- redis . multi do | pipeline |
17- block . call ( Kredis :: Types :: Proxy . new ( pipeline , key ) )
14+ def multi ( * args , ** kwargs , &block )
15+ redis . multi ( * args , ** kwargs ) do | pipeline |
16+ self . pipeline = pipeline
17+ block . call
18+ ensure
19+ self . pipeline = nil
1820 end
1921 end
2022
@@ -27,6 +29,10 @@ def method_missing(method, *args, **kwargs)
2729 end
2830
2931 private
32+ def redis
33+ pipeline || @redis
34+ end
35+
3036 def log_message ( method , *args , **kwargs )
3137 args = args . flatten . reject ( &:blank? ) . presence
3238 kwargs = kwargs . reject { |_k , v | v . blank? } . presence
0 commit comments