Skip to content

Commit 4291815

Browse files
committed
Pefer a thread_mattr_accessor over a thread local variable
1 parent 7bc2914 commit 4291815

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/kredis.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "active_support"
22
require "active_support/core_ext/module/attribute_accessors"
3+
require "active_support/core_ext/module/attribute_accessors_per_thread"
34

45
require "kredis/version"
56

lib/kredis/types/proxy.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ class Kredis::Types::Proxy
44

55
attr_accessor :redis, :key
66

7+
thread_mattr_accessor :pipeline
8+
79
def initialize(redis, key, **options)
810
@redis, @key = redis, key
911
options.each { |key, value| send("#{key}=", value) }
1012
end
1113

1214
def multi(*args, **kwargs, &block)
1315
redis.multi(*args, **kwargs) do |pipeline|
14-
Thread.current[:pipeline] = pipeline
16+
self.pipeline = pipeline
1517
block.call
1618
ensure
17-
Thread.current[:pipeline] = nil
19+
self.pipeline = nil
1820
end
1921
end
2022

2123
def method_missing(method, *args, **kwargs)
2224
Kredis.instrument :proxy, **log_message(method, *args, **kwargs) do
2325
failsafe do
24-
(Thread.current[:pipeline] || redis).public_send method, key, *args, **kwargs
26+
(pipeline || redis).public_send method, key, *args, **kwargs
2527
end
2628
end
2729
end

0 commit comments

Comments
 (0)