Class: Gitlab::Redis::CrossSlot::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/redis/cross_slot.rb

Overview

Pipeline allows cross-slot pipelined to be called. The fan-out logic is implemented in github.com/redis-rb/redis-cluster-client/blob/master/lib/redis_client/cluster/pipeline.rb which is available in redis-rb v5.0.

This file can be deprecated after redis-rb v4.8.0 is upgraded to v5.0

Instance Method Summary collapse

Constructor Details

#initialize(redis) ⇒ Pipeline

Initializes the CrossSlot::Pipeline

Parameters:

  • (::Redis)


81
82
83
# File 'lib/gitlab/redis/cross_slot.rb', line 81

def initialize(redis)
  @redis = redis
end

Instance Method Details

#pipelined(&block) ⇒ Object

pipelined is used in place of ::Redis ‘.pipelined` when running in a cluster context where cross-slot operations may happen.



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/gitlab/redis/cross_slot.rb', line 87

def pipelined(&block)
  # Directly call .pipelined and defer the pipeline execution to MultiStore.
  # MultiStore could wrap over 0, 1, or 2 Redis Cluster clients, handling it here
  # will not work for 2 clients since the key-slot topology can differ.
  if use_cross_slot_pipelining?
    router = Router.new(@redis)
    yield router
    execute_commands(router)
  else
    # use redis-rb's pipelined method
    @redis.pipelined(&block)
  end
end