Class: Dalli::Server
- Inherits:
-
Object
- Object
- Dalli::Server
- Defined in:
- lib/dalli/server.rb
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#port ⇒ Object
Returns the value of attribute port.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #close ⇒ Object
-
#initialize(attribs, options = nil) ⇒ Server
constructor
A new instance of Server.
- #lock! ⇒ Object
-
#request(op, *args) ⇒ Object
Chokepoint method for instrumentation.
- #unlock! ⇒ Object
Constructor Details
#initialize(attribs, options = nil) ⇒ Server
Returns a new instance of Server.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dalli/server.rb', line 11 def initialize(attribs, =nil) (@hostname, @port, @weight) = attribs.split(':') @port ||= 11211 @port = Integer(@port) @weight ||= 1 @weight = Integer(@weight) @down_at = nil @version = detect_memcached_version @options = Dalli.logger.debug { "#{@hostname}:#{@port} running memcached v#{@version}" } end |
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
7 8 9 |
# File 'lib/dalli/server.rb', line 7 def hostname @hostname end |
#port ⇒ Object
Returns the value of attribute port.
8 9 10 |
# File 'lib/dalli/server.rb', line 8 def port @port end |
#weight ⇒ Object
Returns the value of attribute weight.
9 10 11 |
# File 'lib/dalli/server.rb', line 9 def weight @weight end |
Instance Method Details
#alive? ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dalli/server.rb', line 39 def alive? return true if @sock && !@sock.closed? return false if @down_at && @down_at == Time.now.to_i begin # try to reconnect at most once per second connection true rescue Dalli::NetworkError => dne Dalli.logger.info(dne.) false end end |
#close ⇒ Object
53 54 55 |
# File 'lib/dalli/server.rb', line 53 def close (@sock.close rescue nil; @sock = nil) if @sock end |
#lock! ⇒ Object
57 58 |
# File 'lib/dalli/server.rb', line 57 def lock! end |
#request(op, *args) ⇒ Object
Chokepoint method for instrumentation
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dalli/server.rb', line 24 def request(op, *args) begin send(op, *args) rescue Dalli::NetworkError raise rescue Dalli::DalliError raise rescue Exception => ex Dalli.logger.error "Unexpected exception in Dalli: #{ex.class.name}: #{ex.}" Dalli.logger.error "This is a bug in Dalli, please enter an issue in Github if it does not already exist." Dalli.logger.error ex.backtrace.join("\n\t") down!(true) end end |
#unlock! ⇒ Object
60 61 |
# File 'lib/dalli/server.rb', line 60 def unlock! end |