Skip to content

Commit e1425dc

Browse files
committed
Resolve pipelining deprecation warnings
1 parent 20aa4f2 commit e1425dc

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lib/kredis/migration.rb

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

66
def initialize(config = :shared)
77
@redis = Kredis.configured_for config
8+
@pipeline = nil
89
# TODO: Replace script loading with `copy` command once Redis 6.2+ is the minimum supported version.
910
@copy_sha = @redis.script "load", "redis.call('SETNX', KEYS[2], redis.call('GET', KEYS[1])); return 1;"
1011
end
@@ -23,7 +24,7 @@ def migrate(from:, to:)
2324

2425
if to.present? && from != namespaced_to
2526
log_migration "Migrating key #{from} to #{namespaced_to}" do
26-
@redis.evalsha @copy_sha, keys: [ from, namespaced_to ]
27+
connection.evalsha @copy_sha, keys: [ from, namespaced_to ]
2728
end
2829
else
2930
log_migration "Skipping blank/unaltered migration key #{from}#{to}"
@@ -32,18 +33,26 @@ def migrate(from:, to:)
3233

3334
def delete_all(key_pattern)
3435
each_key_batch_matching(key_pattern) do |keys|
35-
@redis.del *keys
36+
connection.del *keys
3637
end
3738
end
3839

3940
private
4041
SCAN_BATCH_SIZE = 1_000
4142

43+
def connection
44+
@pipeline || @redis
45+
end
46+
4247
def each_key_batch_matching(key_pattern, &block)
4348
cursor = "0"
4449
begin
4550
cursor, keys = @redis.scan(cursor, match: key_pattern, count: SCAN_BATCH_SIZE)
46-
@redis.pipelined { yield keys }
51+
@redis.pipelined do |pipeline|
52+
@pipeline = pipeline
53+
yield keys
54+
@pipeline = nil
55+
end
4756
end until cursor == "0"
4857
end
4958

lib/kredis/types/proxy.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@ class Kredis::Types::Proxy
22
require_relative "proxy/failsafe"
33
include Failsafe
44

5-
attr_accessor :redis, :key
5+
attr_accessor :redis, :key, :pipeline
66

77
def initialize(redis, key, **options)
88
@redis, @key = redis, key
99
options.each { |key, value| send("#{key}=", value) }
1010
end
1111

12-
def multi(...)
13-
redis.multi(...)
12+
def multi(*args, **kwargs, &block)
13+
redis.multi(*args, **kwargs) do |pipeline|
14+
self.pipeline = pipeline
15+
block.call
16+
self.pipeline = nil
17+
end
1418
end
1519

1620
def method_missing(method, *args, **kwargs)
1721
Kredis.instrument :proxy, **log_message(method, *args, **kwargs) do
1822
failsafe do
19-
redis.public_send method, key, *args, **kwargs
23+
(pipeline || redis).public_send method, key, *args, **kwargs
2024
end
2125
end
2226
end

0 commit comments

Comments
 (0)