Async::RedisSourceAsyncRedisClientMethods

module Methods

Methods module providing Redis-specific functionality.

Definitions

def subscribe(*channels)

Subscribe to one or more channels for pub/sub messaging.

Signature

parameter channels Array(String)

The channels to subscribe to.

yields {|context| ...}

If a block is given, it will be executed within the subscription context.

parameter context Context::Subscription

The subscription context.

returns Object

The result of the block if block given.

returns Context::Subscription

The subscription context if no block given.

Implementation

def subscribe(*channels)
	context = Context::Subscription.new(@pool, channels)
	
	return context unless block_given?
	
	begin
		yield context
	ensure
		context.close
	end
end

def psubscribe(*patterns)

Subscribe to one or more channel patterns for pub/sub messaging.

Signature

parameter patterns Array(String)

The channel patterns to subscribe to.

yields {|context| ...}

If a block is given, it will be executed within the subscription context.

parameter context Context::Subscription

The subscription context.

returns Object

The result of the block if block given.

returns Context::Subscription

The subscription context if no block given.

Implementation

def psubscribe(*patterns)
	context = Context::Subscription.new(@pool, [])
	context.psubscribe(patterns)
	
	return context unless block_given?
	
	begin
		yield context
	ensure
		context.close
	end
end

def ssubscribe(*channels)

Subscribe to one or more sharded channels for pub/sub messaging (Redis 7.0+).

Signature

parameter channels Array(String)

The sharded channels to subscribe to.

yields {|context| ...}

If a block is given, it will be executed within the subscription context.

parameter context Context::Subscription

The subscription context.

returns Object

The result of the block if block given.

returns Context::Subscription

The subscription context if no block given.

Implementation

def ssubscribe(*channels)
	context = Context::Subscription.new(@pool, [])
	context.ssubscribe(channels)
	
	return context unless block_given?
	
	begin
		yield context
	ensure
		context.close
	end
end

def transaction(&block)

Execute commands within a Redis transaction.

Signature

yields {|context| ...}

If a block is given, it will be executed within the transaction context.

parameter context Context::Transaction

The transaction context.

returns Object

The result of the block if block given.

returns Context::Transaction

Else if no block is given, returns the transaction context.

Implementation

def transaction(&block)
	context = Context::Transaction.new(@pool)
	
	return context unless block_given?
	
	begin
		yield context
	ensure
		context.close
	end
end

def pipeline(&block)

Execute commands in a pipeline for improved performance.

Signature

yields {|context| ...}

If a block is given, it will be executed within the pipeline context.

parameter context Context::Pipeline

The pipeline context.

returns Object

The result of the block if block given.

returns Context::Pipeline

The pipeline context if no block given.

Implementation

def pipeline(&block)
	context = Context::Pipeline.new(@pool)
	
	return context unless block_given?
	
	begin
		yield context
	ensure
		context.close
	end
end

alias nested pipeline

Deprecated.

def call(*arguments)

Execute a Redis command directly.

Signature

parameter arguments Array

The command and its arguments.

returns Object

The response from the Redis server.

Implementation

def call(*arguments)
	@pool.acquire do |connection|
		connection.write_request(arguments)
		
		connection.flush
		
		return connection.read_response
	end
end

def close

Close the client and all its connections.

Implementation

def close
	@pool.close
end