lib/memcache.rb in memcache-client-1.8.1 vs lib/memcache.rb in memcache-client-1.8.2

- old
+ new

@@ -108,11 +108,11 @@ ## # Don't send or look for a reply from the memcached server for write operations. # Please note this feature only works in memcached 1.2.5 and later. Earlier # versions will reply with "ERROR". attr_reader :no_reply - + ## # Accepts a list of +servers+ and a list of +opts+. +servers+ may be # omitted. See +servers=+ for acceptable server list arguments. # # Valid options for +opts+ are: @@ -152,14 +152,15 @@ servers, opts = args else raise ArgumentError, "wrong number of arguments (#{args.length} for 2)" end + @evented = defined?(EM) && EM.reactor_running? opts = DEFAULT_OPTIONS.merge opts @namespace = opts[:namespace] @readonly = opts[:readonly] - @multithread = opts[:multithread] + @multithread = opts[:multithread] && !@evented @autofix_keys = opts[:autofix_keys] @timeout = opts[:timeout] @failover = opts[:failover] @logger = opts[:logger] @no_reply = opts[:no_reply] @@ -168,10 +169,11 @@ @mutex = Mutex.new if @multithread logger.info { "memcache-client #{VERSION} #{Array(servers).inspect}" } if logger Thread.current[:memcache_client] = self.object_id if !@multithread + self.servers = servers end ## @@ -944,10 +946,11 @@ ((total_servers * Continuum::POINTS_PER_SERVER * server.weight) / Float(total_weight)).floor end def check_multithread_status! return if @multithread + return if @evented if Thread.current[:memcache_client] != self.object_id raise MemCacheError, <<-EOM You are accessing this memcache-client instance from multiple threads but have not enabled multithread support. Normally: MemCache.new(['localhost:11211'], :multithread => true) @@ -1009,10 +1012,12 @@ @sock = nil @retry = nil @status = 'NOT CONNECTED' @timeout = memcache.timeout @logger = memcache.logger + + self.extend(MemCache::EventedServer) if defined?(EM) and EM.reactor_running? end ## # Return a string representation of the server object. @@ -1099,11 +1104,10 @@ ## # Mark the server as dead and close its socket. def mark_dead(error) - @sock.close if @sock && !@sock.closed? - @sock = nil + close @retry = Time.now + RETRY_DELAY reason = "#{error.class.name}: #{error.message}" @status = sprintf "%s:%s DEAD (%s), will retry at %s", @host, @port, reason, @retry @logger.info { @status } if @logger