Class: RedisClient::Cluster::PubSub::State

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_client/cluster/pub_sub.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, queue) ⇒ State

Returns a new instance of State.



14
15
16
17
18
# File 'lib/redis_client/cluster/pub_sub.rb', line 14

def initialize(client, queue)
  @client = client
  @worker = nil
  @queue = queue
end

Instance Method Details

#call(command) ⇒ Object



20
21
22
# File 'lib/redis_client/cluster/pub_sub.rb', line 20

def call(command)
  @client.call_v(command)
end

#closeObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/redis_client/cluster/pub_sub.rb', line 28

def close
  if @worker&.alive?
    @worker.exit
    @worker.join
  end

  @client.close
rescue ::RedisClient::ConnectionError
  # ignore
end

#ensure_workerObject



24
25
26
# File 'lib/redis_client/cluster/pub_sub.rb', line 24

def ensure_worker
  @worker = spawn_worker(@client, @queue) unless @worker&.alive?
end