Sha256: 5f49c8392b7a1aa20ecba966d5c7644a0f3d085d31cf6ba9417d0d14b48d978c

Contents?: true

Size: 830 Bytes

Versions: 2

Compression:

Stored size: 830 Bytes

Contents

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

    # Sends all commands at once and reads responses
    # @return [Array] of responses
    def sync
      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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
oxblood-0.1.0.dev6 lib/oxblood/pipeline.rb
oxblood-0.1.0.dev5 lib/oxblood/pipeline.rb