class Generic
Base class for Redis command execution contexts.
Definitions
def initialize(pool, *arguments)
Initialize a new generic context.
Signature
-
parameter
pool
Pool
The connection pool to use.
-
parameter
arguments
Array
Additional arguments for the context.
Implementation
def initialize(pool, *arguments)
@pool = pool
@connection = pool.acquire
end
def close
Close the context and release the connection back to the pool.
Implementation
def close
if connection = @connection
@connection = nil
@pool.release(connection)
end
end
def closed?
Signature
-
returns
Boolean
Whether the context is closed.
Implementation
def closed?
@connection.nil?
end
def write_request(command, *arguments)
Write a Redis command request to the connection.
Signature
-
parameter
command
String
The Redis command.
-
parameter
arguments
Array
The command arguments.
Implementation
def write_request(command, *arguments)
@connection.write_request([command, *arguments])
end
def read_response
Read a response from the Redis connection.
Signature
-
returns
Object
The Redis response.
Implementation
def read_response
@connection.flush
return @connection.read_response
end
def call(command, *arguments)
Execute a Redis command and return the response.
Signature
-
parameter
command
String
The Redis command.
-
parameter
arguments
Array
The command arguments.
-
returns
Object
The Redis response.
Implementation
def call(command, *arguments)
write_request(command, *arguments)
return read_response
end