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

Constructor Details

#initialize(pool) ⇒ Pipeline

Returns a new instance of Pipeline.



50
51
52
53
54
55
# File 'lib/async/redis/context/pipeline.rb', line 50

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.



77
78
79
80
81
# File 'lib/async/redis/context/pipeline.rb', line 77

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

#closeObject



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

def close
	flush
 ensure
	super
end

#collectObject



92
93
94
95
96
# File 'lib/async/redis/context/pipeline.rb', line 92

def collect
	yield
	
	@count.times.map{read_response}
end

#flush(count = 0) ⇒ Object

Flush responses.

Parameters:

  • count (Integer) (defaults to: 0)

    leave this many responses.



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

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

#read_responseObject



83
84
85
86
87
88
89
90
# File 'lib/async/redis/context/pipeline.rb', line 83

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

#syncObject



65
66
67
# File 'lib/async/redis/context/pipeline.rb', line 65

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

#write_requestObject

This method just accumulates the commands and their params.



70
71
72
73
74
# File 'lib/async/redis/context/pipeline.rb', line 70

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