lib/oxblood/session.rb in oxblood-0.1.0.dev10 vs lib/oxblood/session.rb in oxblood-0.1.0.dev11
- old
+ new
@@ -11,15 +11,35 @@
# @example
# conn = Oxblood::Connection.new
# session = Oxblood::Session.new(conn)
# session.ping # => 'PONG'
class Session
- include Oxblood::Commands
+ include Commands
attr_reader :connection
def initialize(connection)
@connection = connection
+ end
+
+ # Send queries using pipelining.
+ # Sync operation will be executed automatically at the end of a block.
+ #
+ # @see https://redis.io/topics/pipelining
+ #
+ # @yield [pipeline] provide {Pipeline} to a block
+ # @yieldreturn [Array] responses from all executed operations
+ #
+ # @example
+ # session = Oxblood::Session.new(Oxblood::Connection.new)
+ # session.pipelined do |pipeline|
+ # pipeline.set('hello', 'world')
+ # pipeline.get('hello')
+ # end # => ['OK', 'world']
+ def pipelined
+ pipeline = Pipeline.new(connection)
+ yield pipeline
+ pipeline.sync
end
private
def run(*command)