Class: Dalli::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/dalli/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribs) ⇒ Server

Returns a new instance of Server.



9
10
11
12
13
14
15
16
17
# File 'lib/dalli/server.rb', line 9

def initialize(attribs)
  (@hostname, @port, @weight) = attribs.split(':')
  @port ||= 11211
  @port = Integer(@port)
  @weight ||= 1
  @weight = Integer(@weight)
  connection
  Dalli.logger.debug { "#{@hostname}:#{@port} running memcached v#{request(:version)}" }
end

Instance Attribute Details

#hostnameObject

Returns the value of attribute hostname.



5
6
7
# File 'lib/dalli/server.rb', line 5

def hostname
  @hostname
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/dalli/server.rb', line 6

def port
  @port
end

#weightObject

Returns the value of attribute weight.



7
8
9
# File 'lib/dalli/server.rb', line 7

def weight
  @weight
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/dalli/server.rb', line 33

def alive?
  @sock && !@sock.closed?
end

#closeObject



37
38
39
# File 'lib/dalli/server.rb', line 37

def close
  (@sock.close rescue nil; @sock = nil) if @sock
end

#lock!Object



41
42
# File 'lib/dalli/server.rb', line 41

def lock!
end

#request(op, *args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dalli/server.rb', line 19

def request(op, *args)
  begin
    send(op, *args)
  rescue Dalli::NetworkError
    raise
  rescue Dalli::DalliError
    raise
  rescue Exception => ex
    puts "Unexpected exception: #{ex.class.name}: #{ex.message}"
    puts ex.backtrace.join("\n")
    down!
  end
end

#unlock!Object



44
45
# File 'lib/dalli/server.rb', line 44

def unlock!
end