Skip to content

Commit 7bc2914

Browse files
committed
Use a thread-local variable for pipeline
1 parent 6c2a8a2 commit 7bc2914

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

lib/kredis/migration.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class Kredis::Migration
55

66
def initialize(config = :shared)
77
@redis = Kredis.configured_for config
8-
@pipeline = nil
98
# TODO: Replace script loading with `copy` command once Redis 6.2+ is the minimum supported version.
109
@copy_sha = @redis.script "load", "redis.call('SETNX', KEYS[2], redis.call('GET', KEYS[1])); return 1;"
1110
end
@@ -40,10 +39,6 @@ def delete_all(key_pattern)
4039
private
4140
SCAN_BATCH_SIZE = 1_000
4241

43-
def connection
44-
@pipeline || @redis
45-
end
46-
4742
def each_key_batch_matching(key_pattern, &block)
4843
cursor = "0"
4944
begin

lib/kredis/types/proxy.rb

Lines changed: 5 additions & 4 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, :pipeline
5+
attr_accessor :redis, :key
66

77
def initialize(redis, key, **options)
88
@redis, @key = redis, key
@@ -11,16 +11,17 @@ def initialize(redis, key, **options)
1111

1212
def multi(*args, **kwargs, &block)
1313
redis.multi(*args, **kwargs) do |pipeline|
14-
self.pipeline = pipeline
14+
Thread.current[:pipeline] = pipeline
1515
block.call
16-
self.pipeline = nil
16+
ensure
17+
Thread.current[:pipeline] = nil
1718
end
1819
end
1920

2021
def method_missing(method, *args, **kwargs)
2122
Kredis.instrument :proxy, **log_message(method, *args, **kwargs) do
2223
failsafe do
23-
(pipeline || redis).public_send method, key, *args, **kwargs
24+
(Thread.current[:pipeline] || redis).public_send method, key, *args, **kwargs
2425
end
2526
end
2627
end

0 commit comments

Comments
 (0)