Sha256: d5d1d6480c52346b7fa8f4543c28b9b3ebe8b1207366de14b3c0ad14147787f3
Contents?: true
Size: 951 Bytes
Versions: 1
Compression:
Stored size: 951 Bytes
Contents
require "connection_pool" require "redis" class Redis::Pool < Redis VERSION = "0.1.1" attr :pool def initialize(options = {}) @pool = ConnectionPool.new(size: options.delete(:size)) { Redis::Client.new(options) } @id = "Redis::Pool::#{object_id}" super end def synchronize if current = Thread.current[@id] yield(current) else @pool.with do |client| _with_client(client) { yield(client) } end end end def pipelined pipeline = Pipeline.new _with_client(pipeline) do |client| yield(client) end synchronize do |client| client.call_pipeline(pipeline) end end def multi raise ArgumentError, "Redis::Pool#multi can only be called with a block" unless block_given? super end protected def _with_client(client) old, Thread.current[@id] = Thread.current[@id], client yield(client) ensure Thread.current[@id] = old end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
redis-pool-0.1.1 | lib/redis/pool.rb |