Class: Async::Redis::Context::Pipeline

Inherits:
Generic
  • Object
show all
Includes:
Protocol::Redis::Methods
Defined in:
lib/async/redis/context/pipeline.rb

Overview

Send multiple commands without waiting for the response, instead of sending them one by one.

Direct Known Subclasses

Transaction

Defined Under Namespace

Classes: Sync

Instance Method Summary collapse

Methods inherited from Generic

#closed?

Constructor Details

#initialize(pool) ⇒ Pipeline

Initialize a new pipeline context.



39
40
41
42
43
44
# File 'lib/async/redis/context/pipeline.rb', line 39

def initialize(pool)
	super(pool)
	
	@count = 0
	@sync = nil
end

Instance Method Details

#call(command, *arguments) ⇒ Object

This method just accumulates the commands and their params.



80
81
82
83
84
# File 'lib/async/redis/context/pipeline.rb', line 80

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

#closeObject

Close the pipeline and flush all pending responses.



98
99
100
101
102
# File 'lib/async/redis/context/pipeline.rb', line 98

def close
	flush
ensure
	super
end

#collectObject

Collect all pending responses.



57
58
59
60
61
62
63
64
# File 'lib/async/redis/context/pipeline.rb', line 57

def collect
	if block_given?
		flush
		yield
	end
	
	@count.times.map{read_response}
end

#flush(count = 0) ⇒ Object

Flush responses.



48
49
50
51
52
# File 'lib/async/redis/context/pipeline.rb', line 48

def flush(count = 0)
	while @count > count
		read_response
	end
end

#read_responseObject

Read a response from the pipeline.



88
89
90
91
92
93
94
95
# File 'lib/async/redis/context/pipeline.rb', line 88

def read_response
	if @count > 0
		@count -= 1
		super
	else
		raise RuntimeError, "No more responses available!"
	end
end

#syncObject

Get a synchronous wrapper for this pipeline.



68
69
70
# File 'lib/async/redis/context/pipeline.rb', line 68

def sync
	@sync ||= Sync.new(self)
end

#write_requestObject

This method just accumulates the commands and their params.



73
74
75
76
77
# File 'lib/async/redis/context/pipeline.rb', line 73

def write_request(*)
	super
	
	@count += 1
end