title: spymemcached: how can I tell whether memcached had connected successfully?
body: <p>I'm using the following library:    <code>compile 'net.spy:spymemcached:2.12.0'</code></p>
  
  <p>So if I do this, if memcachedclient is not connected successfully, it gives me an error:</p>
  
  <pre><code>mc.get(myvariable)
  </code></pre>
  
  <p>I want to check the connection status before I call <code>mc.get()</code> to prevent the error.</p>
  
  <p>I thought maybe I could check this: <code>mc.getConnection().connectionsStatus()</code> but all it does it return a string that says:</p>
  
  <pre><code>Connection Status { pub-memcache-XXX active: false, authed: false, last read: 7 ms ago }
  </code></pre>
  
  <p>I thought it would just return a <code>SUCCESS</code> or a <code>FAILURE</code> but it returns a string.</p>
  
  <p>The doc for the method is here: <a href="https://github.com/couchbase/spymemcached/blob/master/src/main/java/net/spy/memcached/MemcachedConnection.java" rel="nofollow">https://github.com/couchbase/spymemcached/blob/master/src/main/java/net/spy/memcached/MemcachedConnection.java</a></p>
  
  <p>I have copied the relevant method below:</p>
  
  <pre><code>  /**
     * Construct a String containing information about all nodes and their state.
     *
     * @return a stringified representation of the connection status.
     */
    public String connectionsStatus() {
      StringBuilder connStatus = new StringBuilder();
      connStatus.append("Connection Status {");
      for (MemcachedNode node : locator.getAll()) {
        connStatus
          .append(" ")
          .append(node.getSocketAddress())
          .append(" active: ")
          .append(node.isActive())
          .append(", authed: ")
          .append(node.isAuthenticated())
          .append(MessageFormat.format(", last read: {0} ms ago",
            node.lastReadDelta()));
      }
      connStatus.append(" }");
      return connStatus.toString();
    }
  </code></pre>
  
  <p>I don't know, I could parse out the <code>active</code> variable and check that but is there an easier way to check whether spymemcached was connected before I call <code>get</code> on it?</p>