lib/oxblood/pipeline.rb in oxblood-0.1.0.dev4 vs lib/oxblood/pipeline.rb in oxblood-0.1.0.dev5
- old
+ new
@@ -1,18 +1,33 @@
+require 'oxblood/session'
+
module Oxblood
+ # Redis pipeling class. Commands won't be send until {#sync} is called.
+ # @see http://redis.io/topics/pipelining#redis-pipelining
+ #
+ # @example Basic workflow
+ # pipeline = Pipeline.new(connection)
+ # pipeline.echo('ping')
+ # pipeline.ping
+ # pipeline.echo('!')
+ # pipeline.sync # => ["ping", "PONG", "!"]
class Pipeline < Session
def initialize(connection)
super
@commands = Array.new
end
- def run(command)
- @commands << command
- end
-
+ # Sends all commands at once and reads responses
+ # @return [Array] of responses
def sync
- serialized_commands = @commands.map { |c| serialize(command) }
+ serialized_commands = @commands.map { |c| serialize(*c) }
@connection.write(serialized_commands.join)
@connection.read_responses(@commands.size)
+ end
+
+ private
+
+ def run(*command)
+ @commands << command
end
end
end