Async::RedisSourceAsyncRedisClient

class Client

A Redis client that provides connection pooling and context management.

Nested

Definitions

def initialize(endpoint = Endpoint.local, protocol: endpoint.protocol, **options)

Create a new Redis client.

Signature

parameter endpoint Endpoint

The Redis endpoint to connect to.

parameter protocol Protocol

The protocol to use for communication.

parameter options Hash

Additional options for the connection pool.

Implementation

def initialize(endpoint = Endpoint.local, protocol: endpoint.protocol, **options)
	@endpoint = endpoint
	@protocol = protocol
	
	@pool = make_pool(**options)
end

attr :endpoint

Signature

attribute Endpoint

The Redis endpoint.

attr :protocol

Signature

attribute Protocol

The communication protocol.

def self.open(*arguments, **options, &block)

Open a Redis client and optionally yield it in an async task.

Signature

yields {|client, task| ...}

If a block is given, yield the client in an async task.

parameter client Client

The Redis client instance.

parameter task Async::Task

The async task.

returns Client

The client if no block provided.

returns Object

The result of the block if block given.

Implementation

def self.open(*arguments, **options, &block)
	client = self.new(*arguments, **options)
	
	return client unless block_given?
	
	Async do |task|
		begin
			yield client, task
		ensure
			client.close
		end
	end.wait
end