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.



465
466
467
468
# File 'lib/redis_client.rb', line 465

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

Instance Method Details

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



470
471
472
473
# File 'lib/redis_client.rb', line 470

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

#call_v(command) ⇒ Object



475
476
477
478
# File 'lib/redis_client.rb', line 475

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

#closeObject



480
481
482
483
484
# File 'lib/redis_client.rb', line 480

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

#next_event(timeout = nil) ⇒ Object



486
487
488
489
490
491
492
493
494
# File 'lib/redis_client.rb', line 486

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

  raw_connection.read(timeout)
rescue ReadTimeoutError
  nil
end