Class: Async::Redis::Protocol::Selected

Inherits:
Object
  • Object
show all
Defined in:
lib/async/redis/protocol/selected.rb

Overview

Executes AUTH after the user has established a connection.

Defined Under Namespace

Classes: SelectionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, protocol = Async::Redis::Protocol::RESP2) ⇒ Selected

Create a new authenticated protocol.



21
22
23
24
# File 'lib/async/redis/protocol/selected.rb', line 21

def initialize(index, protocol = Async::Redis::Protocol::RESP2)
	@index = index
	@protocol = protocol
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



26
27
28
# File 'lib/async/redis/protocol/selected.rb', line 26

def index
  @index
end

Instance Method Details

#client(stream) ⇒ Object

Create a new client and authenticate it.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/async/redis/protocol/selected.rb', line 29

def client(stream)
	client = @protocol.client(stream)
	
	client.write_request(["SELECT", @index])
	response = client.read_response
	
	if response != "OK"
		raise SelectionError, "Could not select database: #{response}"
	end
	
	return client
end