Object
This class represents a memcached server instance.
The amount of time to wait before attempting to re-establish a connection with a server that is marked dead.
Create a new MemCache::Server object for the memcached instance listening on the given host and port, weighted by the given weight.
# File lib/memcache.rb, line 945 945: def initialize(memcache, host, port = DEFAULT_PORT, weight = DEFAULT_WEIGHT) 946: raise ArgumentError, "No host specified" if host.nil? or host.empty? 947: raise ArgumentError, "No port specified" if port.nil? or port.to_i.zero? 948: 949: @host = host 950: @port = port.to_i 951: @weight = weight.to_i 952: 953: @sock = nil 954: @retry = nil 955: @status = 'NOT CONNECTED' 956: @timeout = memcache.timeout 957: @logger = memcache.logger 958: end
Check whether the server connection is alive. This will cause the socket to attempt to connect if it isn’t already connected and or if the server was previously marked as down and the retry time has been exceeded.
# File lib/memcache.rb, line 973 973: def alive? 974: !!socket 975: end
Close the connection to the memcached server targeted by this object. The server is not considered dead.
# File lib/memcache.rb, line 1013 1013: def close 1014: @sock.close if @sock && !@sock.closed? 1015: @sock = nil 1016: @retry = nil 1017: @status = "NOT CONNECTED" 1018: end
# File lib/memcache.rb, line 1003 1003: def connect_to(host, port, timeout=nil) 1004: io = MemCache::BufferedIO.new(TCPSocket.new(host, port)) 1005: io.read_timeout = timeout 1006: io 1007: end
Return a string representation of the server object.
# File lib/memcache.rb, line 963 963: def inspect 964: "<MemCache::Server: %s:%d [%d] (%s)>" % [@host, @port, @weight, @status] 965: end
Mark the server as dead and close its socket.
# File lib/memcache.rb, line 1023 1023: def mark_dead(error) 1024: @sock.close if @sock && !@sock.closed? 1025: @sock = nil 1026: @retry = Time.now + RETRY_DELAY 1027: 1028: reason = "#{error.class.name}: #{error.message}" 1029: @status = sprintf "%s:%s DEAD (%s), will retry at %s", @host, @port, reason, @retry 1030: @logger.info { @status } if @logger 1031: end
Try to connect to the memcached server targeted by this object. Returns the connected socket object on success or nil on failure.
# File lib/memcache.rb, line 981 981: def socket 982: return @sock if @sock and not @sock.closed? 983: 984: @sock = nil 985: 986: # If the host was dead, don't retry for a while. 987: return if @retry and @retry > Time.now 988: 989: # Attempt to connect if not already connected. 990: begin 991: @sock = connect_to(@host, @port, @timeout) 992: @sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 993: @retry = nil 994: @status = 'CONNECTED' 995: rescue SocketError, SystemCallError, IOError => err 996: logger.warn { "Unable to open socket: #{err.class.name}, #{err.message}" } if logger 997: mark_dead err 998: end 999: 1000: return @sock 1001: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.