Class: Async::Redis::Context::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/async/redis/context/generic.rb

Overview

Base class for Redis command execution contexts.

Direct Known Subclasses

Pipeline, Subscription

Instance Method Summary collapse

Constructor Details

#initialize(pool, *arguments) ⇒ Generic

Initialize a new generic context.



18
19
20
21
# File 'lib/async/redis/context/generic.rb', line 18

def initialize(pool, *arguments)
	@pool = pool
	@connection = pool.acquire
end

Instance Method Details

#call(command, *arguments) ⇒ Object

Execute a Redis command and return the response.



55
56
57
58
59
# File 'lib/async/redis/context/generic.rb', line 55

def call(command, *arguments)
	write_request(command, *arguments)
	
	return read_response
end

#closeObject

Close the context and release the connection back to the pool.



24
25
26
27
28
29
# File 'lib/async/redis/context/generic.rb', line 24

def close
	if connection = @connection
		@connection = nil
		@pool.release(connection)
	end
end

#closed?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/async/redis/context/generic.rb', line 32

def closed?
	@connection.nil?
end

#read_responseObject

Read a response from the Redis connection.



45
46
47
48
49
# File 'lib/async/redis/context/generic.rb', line 45

def read_response
	@connection.flush
	
	return @connection.read_response
end

#write_request(command, *arguments) ⇒ Object

Write a Redis command request to the connection.



39
40
41
# File 'lib/async/redis/context/generic.rb', line 39

def write_request(command, *arguments)
	@connection.write_request([command, *arguments])
end