Class: Async::Redis::Protocol::Authenticated

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

Overview

Executes AUTH after the user has established a connection.

Defined Under Namespace

Classes: AuthenticationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials, protocol = Async::Redis::Protocol::RESP2) ⇒ Authenticated

Create a new authenticated protocol.



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

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

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



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

def credentials
  @credentials
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/authenticated.rb', line 29

def client(stream)
	client = @protocol.client(stream)
	
	client.write_request(["AUTH", *@credentials])
	response = client.read_response
	
	if response != "OK"
		raise AuthenticationError, "Could not authenticate: #{response}"
	end
	
	return client
end