Class: Jeredis::Pool
- Inherits:
-
Object
- Object
- Jeredis::Pool
- Defined in:
- lib/jeredis.rb
Instance Attribute Summary collapse
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Pool
constructor
Initialize Jedis pool.
- #pipelined ⇒ Object
- #with ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Pool
Initialize Jedis pool
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jeredis.rb', line 23 def initialize( = {}) opts = .dup host = opts.delete(:host) || 'localhost' port = opts.delete(:port) || 6379 timeout = opts.delete(:timeout) || 5000 password = opts.delete(:password) db = opts.delete(:db) || 0 config = JedisPoolConfig.new config.minIdle = opts.fetch(:min_idle) if opts[:min_idle] config.maxIdle = opts.fetch(:max_idle) if opts[:max_idle] config.maxTotal = opts.fetch(:max_total) if opts[:max_total] config.block_when_exhausted = false config.max_wait_millis = timeout config.jmx_enabled = true @pool = JedisPool.new(config, host, port, timeout, password, db) end |
Instance Attribute Details
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
10 11 12 |
# File 'lib/jeredis.rb', line 10 def pool @pool end |
Instance Method Details
#pipelined ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/jeredis.rb', line 49 def pipelined with do |j| pipeline = j.pipelined response = yield pipeline pipeline.sync_and_return_all.to_a end end |
#with ⇒ Object
42 43 44 45 46 47 |
# File 'lib/jeredis.rb', line 42 def with conn = @pool.resource yield conn ensure conn.close if conn end |