Sha256: 47c0fcf3594032b4ef881b4bd16bb9d82d3acc44607695d2e4fdff5c89bd29e7

Contents?: true

Size: 1.01 KB

Versions: 12

Compression:

Stored size: 1.01 KB

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_futures = []
      @in_pipeline = false
    end

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

    def method_missing(method, *args, &block)
      if @in_pipeline
        future = MockRedis::Future.new([method, *args])
        @pipelined_futures << future
        future
      else
        @db.send(method, *args, &block)
      end
    end

    def pipelined(_options = {})
      @in_pipeline = true
      yield self
      @in_pipeline = false
      responses = @pipelined_futures.map do |future|
        begin
          result = send(*future.command)
          future.store_result(result)
          result
        rescue => e
          e
        end
      end
      @pipelined_futures = []
      responses
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mock_redis-0.18.0 lib/mock_redis/pipelined_wrapper.rb
mock_redis-0.17.3 lib/mock_redis/pipelined_wrapper.rb
mock_redis-0.17.2 lib/mock_redis/pipelined_wrapper.rb
mock_redis-0.17.1 lib/mock_redis/pipelined_wrapper.rb
mock_redis-0.17.0 lib/mock_redis/pipelined_wrapper.rb
mock_redis-0.16.1 lib/mock_redis/pipelined_wrapper.rb
mock_redis-0.16.0 lib/mock_redis/pipelined_wrapper.rb
mock_redis-0.15.4 lib/mock_redis/pipelined_wrapper.rb
mock_redis-0.15.3 lib/mock_redis/pipelined_wrapper.rb
mock_redis-0.15.2 lib/mock_redis/pipelined_wrapper.rb
mock_redis-0.15.1 lib/mock_redis/pipelined_wrapper.rb
mock_redis-0.15.0 lib/mock_redis/pipelined_wrapper.rb