Sha256: 8a80c568d5427f7477c73b3de2003c893f6ce8fc2a9f733823e564e159f94ba0

Contents?: true

Size: 909 Bytes

Versions: 2

Compression:

Stored size: 909 Bytes

Contents

class MockRedis
  class PipelinedWrapper
    include UndefRedisMethods

    def respond_to?(method, include_private=false)
      super || @db.respond_to?(method)
    end

    def initialize(db)
      @db = db
      @pipelined_commands = []
      @in_pipeline = false
    end

    def initialize_copy(source)
      super
      @db = @db.clone
      @pipelined_commands = @pipelined_commands.clone
    end

    def method_missing(method, *args, &block)
      if @in_pipeline
        @pipelined_commands << [method, *args]
        nil
      else
        @db.send(method, *args, &block)
      end
    end

    def pipelined(options = {})
      @in_pipeline = true
      yield self
      @in_pipeline = false
      responses = @pipelined_commands.map do |cmd|
        begin
          send(*cmd)
        rescue => e
          e
        end
      end
      @pipelined_commands = []
      responses
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mock_redis-0.8.2 lib/mock_redis/pipelined_wrapper.rb
mock_redis-0.8.1 lib/mock_redis/pipelined_wrapper.rb