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.



495
496
497
498
# File 'lib/redis_client.rb', line 495

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

Instance Method Details

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



500
501
502
503
# File 'lib/redis_client.rb', line 500

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

#call_v(command) ⇒ Object



505
506
507
508
# File 'lib/redis_client.rb', line 505

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

#closeObject



510
511
512
513
514
# File 'lib/redis_client.rb', line 510

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

#next_event(timeout = nil) ⇒ Object



516
517
518
519
520
521
522
523
524
# File 'lib/redis_client.rb', line 516

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

  raw_connection.read(timeout)
rescue ReadTimeoutError
  nil
end