Class: RedisClient::PubSub

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

Instance Method Summary collapse

Constructor Details

#initialize(raw_connection, command_builder) ⇒ PubSub

Returns a new instance of PubSub.



547
548
549
550
# File 'lib/redis_client.rb', line 547

def initialize(raw_connection, command_builder)
  @raw_connection = raw_connection
  @command_builder = command_builder
end

Instance Method Details

#call(*command, **kwargs) ⇒ Object



552
553
554
555
# File 'lib/redis_client.rb', line 552

def call(*command, **kwargs)
  raw_connection.write(@command_builder.generate(command, kwargs))
  nil
end

#call_v(command) ⇒ Object



557
558
559
560
# File 'lib/redis_client.rb', line 557

def call_v(command)
  raw_connection.write(@command_builder.generate(command))
  nil
end

#closeObject



562
563
564
565
566
# File 'lib/redis_client.rb', line 562

def close
  @raw_connection&.close
  @raw_connection = nil # PubSub can't just reconnect
  self
end

#next_event(timeout = nil) ⇒ Object



568
569
570
571
572
573
574
575
576
# File 'lib/redis_client.rb', line 568

def next_event(timeout = nil)
  unless raw_connection
    raise ConnectionError, "Connection was closed or lost"
  end

  raw_connection.read(timeout)
rescue ReadTimeoutError
  nil
end