Class MemcachedClient

  • All Implemented Interfaces:
    ConnectionObserver, MemcachedClientIF

    public class MemcachedClient
    extends SpyObject
    implements MemcachedClientIF, ConnectionObserver
    Client to a memcached server.

    Basic usage

     MemcachedClient c = new MemcachedClient(
        new InetSocketAddress("hostname", portNum));
    
     // Store a value (async) for one hour
     c.set("someKey", 3600, someObject);
     // Retrieve a value.
     Object myObject = c.get("someKey");
     

    Advanced Usage

    MemcachedClient may be processing a great deal of asynchronous messages or possibly dealing with an unreachable memcached, which may delay processing. If a memcached is disabled, for example, MemcachedConnection will continue to attempt to reconnect and replay pending operations until it comes back up. To prevent this from causing your application to hang, you can use one of the asynchronous mechanisms to time out a request and cancel the operation to the server.

          // Get a memcached client connected to several servers
          // over the binary protocol
          MemcachedClient c = new MemcachedClient(new BinaryConnectionFactory(),
                  AddrUtil.getAddresses("server1:11211 server2:11211"));
    
          // Try to get a value, for up to 5 seconds, and cancel if it
          // doesn't return
          Object myObj = null;
          Future<Object> f = c.asyncGet("someKey");
          try {
              myObj = f.get(5, TimeUnit.SECONDS);
          // throws expecting InterruptedException, ExecutionException
          // or TimeoutException
          } catch (Exception e) {  /*  /
              // Since we don't need this, go ahead and cancel the operation.
              // This is not strictly necessary, but it'll save some work on
              // the server.  It is okay to cancel it if running.
              f.cancel(true);
              // Do other timeout related stuff
          }
     

    Optionally, it is possible to activate a check that makes sure that the node is alive and responding before running actual operations (even before authentication. Only enable this if you are sure that you do not run into issues during connection (some memcached services have problems with it). You can enable it by setting the net.spy.verifyAliveOnConnect System Property to "true".

    • Constructor Summary

      Constructors 
      Constructor Description
      MemcachedClient​(java.net.InetSocketAddress... ia)
      Get a memcache client operating on the specified memcached locations.
      MemcachedClient​(java.util.List<java.net.InetSocketAddress> addrs)
      Get a memcache client over the specified memcached locations.
      MemcachedClient​(ConnectionFactory cf, java.util.List<java.net.InetSocketAddress> addrs)
      Get a memcache client over the specified memcached locations.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      OperationFuture<java.lang.Boolean> add​(java.lang.String key, int exp, java.lang.Object o)
      Add an object to the cache (using the default transcoder) iff it does not exist already.
      <T> OperationFuture<java.lang.Boolean> add​(java.lang.String key, int exp, T o, Transcoder<T> tc)
      Add an object to the cache iff it does not exist already.
      boolean addObserver​(ConnectionObserver obs)
      Add a connection observer.
      OperationFuture<java.lang.Boolean> append​(long cas, java.lang.String key, java.lang.Object val)
      Append to an existing value in the cache.
      <T> OperationFuture<java.lang.Boolean> append​(long cas, java.lang.String key, T val, Transcoder<T> tc)
      Append to an existing value in the cache.
      OperationFuture<java.lang.Boolean> append​(java.lang.String key, java.lang.Object val)
      Append to an existing value in the cache.
      <T> OperationFuture<java.lang.Boolean> append​(java.lang.String key, T val, Transcoder<T> tc)
      Append to an existing value in the cache.
      OperationFuture<CASResponse> asyncCAS​(java.lang.String key, long casId, int exp, java.lang.Object value)
      Asynchronous CAS operation using the default transcoder with expiration.
      <T> OperationFuture<CASResponse> asyncCAS​(java.lang.String key, long casId, int exp, T value, Transcoder<T> tc)
      Asynchronous CAS operation.
      OperationFuture<CASResponse> asyncCAS​(java.lang.String key, long casId, java.lang.Object value)
      Asynchronous CAS operation using the default transcoder.
      <T> OperationFuture<CASResponse> asyncCAS​(java.lang.String key, long casId, T value, Transcoder<T> tc)
      Asynchronous CAS operation.
      private <T> OperationFuture<java.lang.Boolean> asyncCat​(ConcatenationType catType, long cas, java.lang.String key, T value, Transcoder<T> tc)  
      OperationFuture<java.lang.Long> asyncDecr​(java.lang.String key, int by)
      Asynchronous decrement.
      OperationFuture<java.lang.Long> asyncDecr​(java.lang.String key, int by, long def)
      Asynchronous decrement.
      OperationFuture<java.lang.Long> asyncDecr​(java.lang.String key, int by, long def, int exp)
      Asynchronous decrement.
      OperationFuture<java.lang.Long> asyncDecr​(java.lang.String key, long by)
      Asynchronous decrement.
      OperationFuture<java.lang.Long> asyncDecr​(java.lang.String key, long by, long def)
      Asynchronous decrement.
      OperationFuture<java.lang.Long> asyncDecr​(java.lang.String key, long by, long def, int exp)
      Asynchronous decrement.
      GetFuture<java.lang.Object> asyncGet​(java.lang.String key)
      Get the given key asynchronously and decode with the default transcoder.
      <T> GetFuture<T> asyncGet​(java.lang.String key, Transcoder<T> tc)
      Get the given key asynchronously.
      OperationFuture<CASValue<java.lang.Object>> asyncGetAndTouch​(java.lang.String key, int exp)
      Get the given key to reset its expiration time.
      <T> OperationFuture<CASValue<T>> asyncGetAndTouch​(java.lang.String key, int exp, Transcoder<T> tc)
      Get the given key to reset its expiration time.
      BulkFuture<java.util.Map<java.lang.String,​java.lang.Object>> asyncGetBulk​(java.lang.String... keys)
      Varargs wrapper for asynchronous bulk gets with the default transcoder.
      BulkFuture<java.util.Map<java.lang.String,​java.lang.Object>> asyncGetBulk​(java.util.Collection<java.lang.String> keys)
      Asynchronously get a bunch of objects from the cache and decode them with the given transcoder.
      <T> BulkFuture<java.util.Map<java.lang.String,​T>> asyncGetBulk​(java.util.Collection<java.lang.String> keys, java.util.Iterator<Transcoder<T>> tcIter)
      Asynchronously get a bunch of objects from the cache.
      <T> BulkFuture<java.util.Map<java.lang.String,​T>> asyncGetBulk​(java.util.Collection<java.lang.String> keys, Transcoder<T> tc)
      Asynchronously get a bunch of objects from the cache.
      BulkFuture<java.util.Map<java.lang.String,​java.lang.Object>> asyncGetBulk​(java.util.Iterator<java.lang.String> keyIter)
      Asynchronously get a bunch of objects from the cache and decode them with the given transcoder.
      <T> BulkFuture<java.util.Map<java.lang.String,​T>> asyncGetBulk​(java.util.Iterator<java.lang.String> keyIter, java.util.Iterator<Transcoder<T>> tcIter)
      Asynchronously get a bunch of objects from the cache.
      <T> BulkFuture<java.util.Map<java.lang.String,​T>> asyncGetBulk​(java.util.Iterator<java.lang.String> keyIter, Transcoder<T> tc)
      Asynchronously get a bunch of objects from the cache.
      <T> BulkFuture<java.util.Map<java.lang.String,​T>> asyncGetBulk​(Transcoder<T> tc, java.lang.String... keys)
      Varargs wrapper for asynchronous bulk gets.
      OperationFuture<CASValue<java.lang.Object>> asyncGets​(java.lang.String key)
      Gets (with CAS support) the given key asynchronously and decode using the default transcoder.
      <T> OperationFuture<CASValue<T>> asyncGets​(java.lang.String key, Transcoder<T> tc)
      Gets (with CAS support) the given key asynchronously.
      OperationFuture<java.lang.Long> asyncIncr​(java.lang.String key, int by)
      Asychronous increment.
      OperationFuture<java.lang.Long> asyncIncr​(java.lang.String key, int by, long def)
      Asychronous increment.
      OperationFuture<java.lang.Long> asyncIncr​(java.lang.String key, int by, long def, int exp)
      Asychronous increment.
      OperationFuture<java.lang.Long> asyncIncr​(java.lang.String key, long by)
      Asychronous increment.
      OperationFuture<java.lang.Long> asyncIncr​(java.lang.String key, long by, long def)
      Asychronous increment.
      OperationFuture<java.lang.Long> asyncIncr​(java.lang.String key, long by, long def, int exp)
      Asychronous increment.
      private OperationFuture<java.lang.Long> asyncMutate​(Mutator m, java.lang.String key, long by, long def, int exp)  
      private OperationFuture<java.lang.Boolean> asyncStore​(StoreType storeType, java.lang.String key, int exp, java.lang.Object value)  
      private <T> OperationFuture<java.lang.Boolean> asyncStore​(StoreType storeType, java.lang.String key, int exp, T value, Transcoder<T> tc)  
      java.util.concurrent.CountDownLatch broadcastOp​(BroadcastOpFactory of)  
      java.util.concurrent.CountDownLatch broadcastOp​(BroadcastOpFactory of, java.util.Collection<MemcachedNode> nodes)  
      private java.util.concurrent.CountDownLatch broadcastOp​(BroadcastOpFactory of, java.util.Collection<MemcachedNode> nodes, boolean checkShuttingDown)  
      private java.lang.String buildTimeoutMessage​(long timeWaited, java.util.concurrent.TimeUnit unit)  
      CASResponse cas​(java.lang.String key, long casId, int exp, java.lang.Object value)
      Perform a synchronous CAS operation with the default transcoder.
      <T> CASResponse cas​(java.lang.String key, long casId, int exp, T value, Transcoder<T> tc)
      Perform a synchronous CAS operation.
      CASResponse cas​(java.lang.String key, long casId, java.lang.Object value)
      Perform a synchronous CAS operation with the default transcoder.
      <T> CASResponse cas​(java.lang.String key, long casId, T value, Transcoder<T> tc)
      Perform a synchronous CAS operation.
      void connectionEstablished​(java.net.SocketAddress sa, int reconnectCount)
      A connection has just successfully been established on the given socket.
      void connectionLost​(java.net.SocketAddress sa)
      A connection was just lost on the given socket.
      long decr​(java.lang.String key, int by)
      Decrement the given key by the given value.
      long decr​(java.lang.String key, int by, long def)
      Decrement the given counter, returning the new value.
      long decr​(java.lang.String key, int by, long def, int exp)
      Decrement the given counter, returning the new value.
      long decr​(java.lang.String key, long by)
      Decrement the given key by the given value.
      long decr​(java.lang.String key, long by, long def)
      Decrement the given counter, returning the new value.
      long decr​(java.lang.String key, long by, long def, int exp)
      Decrement the given counter, returning the new value.
      OperationFuture<java.lang.Boolean> delete​(java.lang.String key)
      Delete the given key from the cache.
      OperationFuture<java.lang.Boolean> delete​(java.lang.String key, int hold)
      Deprecated.
      Hold values are no longer honored.
      OperationFuture<java.lang.Boolean> delete​(java.lang.String key, long cas)
      Delete the given key from the cache of the given CAS value applies.
      private MemcachedNode findNode​(java.net.SocketAddress sa)  
      OperationFuture<java.lang.Boolean> flush()
      Flush all caches from all servers immediately.
      OperationFuture<java.lang.Boolean> flush​(int delay)
      Flush all caches from all servers with a delay of application.
      java.lang.Object get​(java.lang.String key)
      Get with a single key and decode using the default transcoder.
      <T> T get​(java.lang.String key, Transcoder<T> tc)
      Get with a single key.
      CASValue<java.lang.Object> getAndTouch​(java.lang.String key, int exp)
      Get a single key and reset its expiration using the default transcoder.
      <T> CASValue<T> getAndTouch​(java.lang.String key, int exp, Transcoder<T> tc)
      Get with a single key and reset its expiration.
      java.util.Collection<java.net.SocketAddress> getAvailableServers()
      Get the addresses of available servers.
      java.util.Map<java.lang.String,​java.lang.Object> getBulk​(java.lang.String... keys)
      Get the values for multiple keys from the cache.
      java.util.Map<java.lang.String,​java.lang.Object> getBulk​(java.util.Collection<java.lang.String> keys)
      Get the values for multiple keys from the cache.
      <T> java.util.Map<java.lang.String,​T> getBulk​(java.util.Collection<java.lang.String> keys, Transcoder<T> tc)
      Get the values for multiple keys from the cache.
      java.util.Map<java.lang.String,​java.lang.Object> getBulk​(java.util.Iterator<java.lang.String> keyIter)
      Get the values for multiple keys from the cache.
      <T> java.util.Map<java.lang.String,​T> getBulk​(java.util.Iterator<java.lang.String> keyIter, Transcoder<T> tc)
      Get the values for multiple keys from the cache.
      <T> java.util.Map<java.lang.String,​T> getBulk​(Transcoder<T> tc, java.lang.String... keys)
      Get the values for multiple keys from the cache.
      MemcachedConnection getConnection()  
      java.util.concurrent.ExecutorService getExecutorService()  
      NodeLocator getNodeLocator()
      Get a read-only wrapper around the node locator wrapping this instance.
      long getOperationTimeout()  
      CASValue<java.lang.Object> gets​(java.lang.String key)
      Gets (with CAS support) with a single key using the default transcoder.
      <T> CASValue<T> gets​(java.lang.String key, Transcoder<T> tc)
      Gets (with CAS support) with a single key.
      java.util.Map<java.net.SocketAddress,​java.util.Map<java.lang.String,​java.lang.String>> getStats()
      Get all of the stats from all of the connections.
      java.util.Map<java.net.SocketAddress,​java.util.Map<java.lang.String,​java.lang.String>> getStats​(java.lang.String arg)
      Get a set of stats from all connections.
      Transcoder<java.lang.Object> getTranscoder()
      Get the default transcoder that's in use.
      TranscodeService getTranscoderService()  
      java.util.Collection<java.net.SocketAddress> getUnavailableServers()
      Get the addresses of unavailable servers.
      java.util.Map<java.net.SocketAddress,​java.lang.String> getVersions()
      Get the versions of all of the connected memcacheds.
      long incr​(java.lang.String key, int by)
      Increment the given key by the given amount.
      long incr​(java.lang.String key, int by, long def)
      Increment the given counter, returning the new value.
      long incr​(java.lang.String key, int by, long def, int exp)
      Increment the given counter, returning the new value.
      long incr​(java.lang.String key, long by)
      Increment the given key by the given amount.
      long incr​(java.lang.String key, long by, long def)
      Increment the given counter, returning the new value.
      long incr​(java.lang.String key, long by, long def, int exp)
      Increment the given counter, returning the new value.
      java.util.Set<java.lang.String> listSaslMechanisms()
      Get the set of SASL mechanisms supported by the servers.
      private long mutate​(Mutator m, java.lang.String key, long by, long def, int exp)  
      private long mutateWithDefault​(Mutator t, java.lang.String key, long by, long def, int exp)  
      OperationFuture<java.lang.Boolean> prepend​(long cas, java.lang.String key, java.lang.Object val)
      Prepend to an existing value in the cache.
      <T> OperationFuture<java.lang.Boolean> prepend​(long cas, java.lang.String key, T val, Transcoder<T> tc)
      Prepend to an existing value in the cache.
      OperationFuture<java.lang.Boolean> prepend​(java.lang.String key, java.lang.Object val)
      Prepend to an existing value in the cache.
      <T> OperationFuture<java.lang.Boolean> prepend​(java.lang.String key, T val, Transcoder<T> tc)
      Prepend to an existing value in the cache.
      boolean removeObserver​(ConnectionObserver obs)
      Remove a connection observer.
      OperationFuture<java.lang.Boolean> replace​(java.lang.String key, int exp, java.lang.Object o)
      Replace an object with the given value (transcoded with the default transcoder) iff there is already a value for the given key.
      <T> OperationFuture<java.lang.Boolean> replace​(java.lang.String key, int exp, T o, Transcoder<T> tc)
      Replace an object with the given value iff there is already a value for the given key.
      OperationFuture<java.lang.Boolean> set​(java.lang.String key, int exp, java.lang.Object o)
      Set an object in the cache (using the default transcoder) regardless of any existing value.
      <T> OperationFuture<java.lang.Boolean> set​(java.lang.String key, int exp, T o, Transcoder<T> tc)
      Set an object in the cache regardless of any existing value.
      void shutdown()
      Shut down immediately.
      boolean shutdown​(long timeout, java.util.concurrent.TimeUnit unit)
      Shut down this client gracefully.
      java.lang.String toString()  
      <T> OperationFuture<java.lang.Boolean> touch​(java.lang.String key, int exp)
      Touch the given key to reset its expiration time with the default transcoder.
      <T> OperationFuture<java.lang.Boolean> touch​(java.lang.String key, int exp, Transcoder<T> tc)
      Touch the given key to reset its expiration time.
      boolean waitForQueues​(long timeout, java.util.concurrent.TimeUnit unit)
      Wait for the queues to die down.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • shuttingDown

        protected volatile boolean shuttingDown
      • operationTimeout

        protected final long operationTimeout
      • transcoder

        protected final Transcoder<java.lang.Object> transcoder
      • executorService

        protected final java.util.concurrent.ExecutorService executorService
    • Constructor Detail

      • MemcachedClient

        public MemcachedClient​(java.net.InetSocketAddress... ia)
                        throws java.io.IOException
        Get a memcache client operating on the specified memcached locations.
        Parameters:
        ia - the memcached locations
        Throws:
        java.io.IOException - if connections cannot be established
      • MemcachedClient

        public MemcachedClient​(java.util.List<java.net.InetSocketAddress> addrs)
                        throws java.io.IOException
        Get a memcache client over the specified memcached locations.
        Parameters:
        addrs - the socket addrs
        Throws:
        java.io.IOException - if connections cannot be established
      • MemcachedClient

        public MemcachedClient​(ConnectionFactory cf,
                               java.util.List<java.net.InetSocketAddress> addrs)
                        throws java.io.IOException
        Get a memcache client over the specified memcached locations.
        Parameters:
        cf - the connection factory to configure connections for this client
        addrs - the socket addresses
        Throws:
        java.io.IOException - if connections cannot be established
    • Method Detail

      • getAvailableServers

        public java.util.Collection<java.net.SocketAddress> getAvailableServers()
        Get the addresses of available servers.

        This is based on a snapshot in time so shouldn't be considered completely accurate, but is a useful for getting a feel for what's working and what's not working.

        Specified by:
        getAvailableServers in interface MemcachedClientIF
        Returns:
        point-in-time view of currently available servers
      • getUnavailableServers

        public java.util.Collection<java.net.SocketAddress> getUnavailableServers()
        Get the addresses of unavailable servers.

        This is based on a snapshot in time so shouldn't be considered completely accurate, but is a useful for getting a feel for what's working and what's not working.

        Specified by:
        getUnavailableServers in interface MemcachedClientIF
        Returns:
        point-in-time view of currently available servers
      • getNodeLocator

        public NodeLocator getNodeLocator()
        Get a read-only wrapper around the node locator wrapping this instance.
        Specified by:
        getNodeLocator in interface MemcachedClientIF
        Returns:
        this instance's NodeLocator
      • getTranscoder

        public Transcoder<java.lang.Object> getTranscoder()
        Get the default transcoder that's in use.
        Specified by:
        getTranscoder in interface MemcachedClientIF
        Returns:
        this instance's Transcoder
      • broadcastOp

        private java.util.concurrent.CountDownLatch broadcastOp​(BroadcastOpFactory of,
                                                                java.util.Collection<MemcachedNode> nodes,
                                                                boolean checkShuttingDown)
      • asyncStore

        private OperationFuture<java.lang.Boolean> asyncStore​(StoreType storeType,
                                                              java.lang.String key,
                                                              int exp,
                                                              java.lang.Object value)
      • touch

        public <T> OperationFuture<java.lang.Boolean> touch​(java.lang.String key,
                                                            int exp)
        Touch the given key to reset its expiration time with the default transcoder.
        Specified by:
        touch in interface MemcachedClientIF
        Parameters:
        key - the key to fetch
        exp - the new expiration to set for the given key
        Returns:
        a future that will hold the return value of whether or not the fetch succeeded
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • touch

        public <T> OperationFuture<java.lang.Boolean> touch​(java.lang.String key,
                                                            int exp,
                                                            Transcoder<T> tc)
        Touch the given key to reset its expiration time.
        Specified by:
        touch in interface MemcachedClientIF
        Parameters:
        key - the key to fetch
        exp - the new expiration to set for the given key
        tc - the transcoder to serialize and unserialize value
        Returns:
        a future that will hold the return value of whether or not the fetch succeeded
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • append

        public OperationFuture<java.lang.Boolean> append​(long cas,
                                                         java.lang.String key,
                                                         java.lang.Object val)
        Append to an existing value in the cache. If 0 is passed in as the CAS identifier, it will override the value on the server without performing the CAS check.

        Note that the return will be false any time a mutation has not occurred.

        Specified by:
        append in interface MemcachedClientIF
        Parameters:
        cas - cas identifier (ignored in the ascii protocol)
        key - the key to whose value will be appended
        val - the value to append
        Returns:
        a future indicating success, false if there was no change to the value
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • append

        public OperationFuture<java.lang.Boolean> append​(java.lang.String key,
                                                         java.lang.Object val)
        Append to an existing value in the cache.

        Note that the return will be false any time a mutation has not occurred.

        Specified by:
        append in interface MemcachedClientIF
        Parameters:
        key - the key to whose value will be appended
        val - the value to append
        Returns:
        a future indicating success, false if there was no change to the value
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • append

        public <T> OperationFuture<java.lang.Boolean> append​(long cas,
                                                             java.lang.String key,
                                                             T val,
                                                             Transcoder<T> tc)
        Append to an existing value in the cache. If 0 is passed in as the CAS identifier, it will override the value on the server without performing the CAS check.

        Note that the return will be false any time a mutation has not occurred.

        Specified by:
        append in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        cas - cas identifier (ignored in the ascii protocol)
        key - the key to whose value will be appended
        val - the value to append
        tc - the transcoder to serialize and unserialize the value
        Returns:
        a future indicating success
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • append

        public <T> OperationFuture<java.lang.Boolean> append​(java.lang.String key,
                                                             T val,
                                                             Transcoder<T> tc)
        Append to an existing value in the cache. If 0 is passed in as the CAS identifier, it will override the value on the server without performing the CAS check.

        Note that the return will be false any time a mutation has not occurred.

        Specified by:
        append in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key to whose value will be appended
        val - the value to append
        tc - the transcoder to serialize and unserialize the value
        Returns:
        a future indicating success
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • prepend

        public OperationFuture<java.lang.Boolean> prepend​(long cas,
                                                          java.lang.String key,
                                                          java.lang.Object val)
        Prepend to an existing value in the cache. If 0 is passed in as the CAS identifier, it will override the value on the server without performing the CAS check.

        Note that the return will be false any time a mutation has not occurred.

        Specified by:
        prepend in interface MemcachedClientIF
        Parameters:
        cas - cas identifier (ignored in the ascii protocol)
        key - the key to whose value will be prepended
        val - the value to append
        Returns:
        a future indicating success
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • prepend

        public OperationFuture<java.lang.Boolean> prepend​(java.lang.String key,
                                                          java.lang.Object val)
        Prepend to an existing value in the cache.

        Note that the return will be false any time a mutation has not occurred.

        Specified by:
        prepend in interface MemcachedClientIF
        Parameters:
        key - the key to whose value will be prepended
        val - the value to append
        Returns:
        a future indicating success
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • prepend

        public <T> OperationFuture<java.lang.Boolean> prepend​(long cas,
                                                              java.lang.String key,
                                                              T val,
                                                              Transcoder<T> tc)
        Prepend to an existing value in the cache. If 0 is passed in as the CAS identifier, it will override the value on the server without performing the CAS check.

        Note that the return will be false any time a mutation has not occurred.

        Specified by:
        prepend in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        cas - cas identifier (ignored in the ascii protocol)
        key - the key to whose value will be prepended
        val - the value to append
        tc - the transcoder to serialize and unserialize the value
        Returns:
        a future indicating success
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • prepend

        public <T> OperationFuture<java.lang.Boolean> prepend​(java.lang.String key,
                                                              T val,
                                                              Transcoder<T> tc)
        Prepend to an existing value in the cache.

        Note that the return will be false any time a mutation has not occurred.

        Specified by:
        prepend in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key to whose value will be prepended
        val - the value to append
        tc - the transcoder to serialize and unserialize the value
        Returns:
        a future indicating success
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncCAS

        public <T> OperationFuture<CASResponse> asyncCAS​(java.lang.String key,
                                                         long casId,
                                                         T value,
                                                         Transcoder<T> tc)
        Asynchronous CAS operation.
        Specified by:
        asyncCAS in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key
        casId - the CAS identifier (from a gets operation)
        value - the new value
        tc - the transcoder to serialize and unserialize the value
        Returns:
        a future that will indicate the status of the CAS
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncCAS

        public <T> OperationFuture<CASResponse> asyncCAS​(java.lang.String key,
                                                         long casId,
                                                         int exp,
                                                         T value,
                                                         Transcoder<T> tc)
        Asynchronous CAS operation.
        Specified by:
        asyncCAS in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key
        casId - the CAS identifier (from a gets operation)
        exp - the expiration of this object
        value - the new value
        tc - the transcoder to serialize and unserialize the value
        Returns:
        a future that will indicate the status of the CAS
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncCAS

        public OperationFuture<CASResponse> asyncCAS​(java.lang.String key,
                                                     long casId,
                                                     java.lang.Object value)
        Asynchronous CAS operation using the default transcoder.
        Specified by:
        asyncCAS in interface MemcachedClientIF
        Parameters:
        key - the key
        casId - the CAS identifier (from a gets operation)
        value - the new value
        Returns:
        a future that will indicate the status of the CAS
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncCAS

        public OperationFuture<CASResponse> asyncCAS​(java.lang.String key,
                                                     long casId,
                                                     int exp,
                                                     java.lang.Object value)
        Asynchronous CAS operation using the default transcoder with expiration.
        Specified by:
        asyncCAS in interface MemcachedClientIF
        Parameters:
        key - the key
        casId - the CAS identifier (from a gets operation)
        exp - the expiration of this object
        value - the new value
        Returns:
        a future that will indicate the status of the CAS
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • cas

        public <T> CASResponse cas​(java.lang.String key,
                                   long casId,
                                   T value,
                                   Transcoder<T> tc)
        Perform a synchronous CAS operation.
        Specified by:
        cas in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key
        casId - the CAS identifier (from a gets operation)
        value - the new value
        tc - the transcoder to serialize and unserialize the value
        Returns:
        a CASResponse
        Throws:
        OperationTimeoutException - if global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • cas

        public <T> CASResponse cas​(java.lang.String key,
                                   long casId,
                                   int exp,
                                   T value,
                                   Transcoder<T> tc)
        Perform a synchronous CAS operation.
        Specified by:
        cas in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key
        casId - the CAS identifier (from a gets operation)
        exp - the expiration of this object
        value - the new value
        tc - the transcoder to serialize and unserialize the value
        Returns:
        a CASResponse
        Throws:
        OperationTimeoutException - if global operation timeout is exceeded
        java.util.concurrent.CancellationException - if operation was canceled
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • cas

        public CASResponse cas​(java.lang.String key,
                               long casId,
                               java.lang.Object value)
        Perform a synchronous CAS operation with the default transcoder.
        Specified by:
        cas in interface MemcachedClientIF
        Parameters:
        key - the key
        casId - the CAS identifier (from a gets operation)
        value - the new value
        Returns:
        a CASResponse
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • cas

        public CASResponse cas​(java.lang.String key,
                               long casId,
                               int exp,
                               java.lang.Object value)
        Perform a synchronous CAS operation with the default transcoder.
        Specified by:
        cas in interface MemcachedClientIF
        Parameters:
        key - the key
        casId - the CAS identifier (from a gets operation)
        exp - the expiration of this object
        value - the new value
        Returns:
        a CASResponse
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • add

        public <T> OperationFuture<java.lang.Boolean> add​(java.lang.String key,
                                                          int exp,
                                                          T o,
                                                          Transcoder<T> tc)
        Add an object to the cache iff it does not exist already.

        The exp value is passed along to memcached exactly as given, and will be processed per the memcached protocol specification:

        Note that the return will be false any time a mutation has not occurred.

        The actual value sent may either be Unix time (number of seconds since January 1, 1970, as a 32-bit value), or a number of seconds starting from current time. In the latter case, this number of seconds may not exceed 60*60*24*30 (number of seconds in 30 days); if the number sent by a client is larger than that, the server will consider it to be real Unix time value rather than an offset from current time.

        Specified by:
        add in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key under which this object should be added.
        exp - the expiration of this object
        o - the object to store
        tc - the transcoder to serialize and unserialize the value
        Returns:
        a future representing the processing of this operation
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • add

        public OperationFuture<java.lang.Boolean> add​(java.lang.String key,
                                                      int exp,
                                                      java.lang.Object o)
        Add an object to the cache (using the default transcoder) iff it does not exist already.

        The exp value is passed along to memcached exactly as given, and will be processed per the memcached protocol specification:

        Note that the return will be false any time a mutation has not occurred.

        The actual value sent may either be Unix time (number of seconds since January 1, 1970, as a 32-bit value), or a number of seconds starting from current time. In the latter case, this number of seconds may not exceed 60*60*24*30 (number of seconds in 30 days); if the number sent by a client is larger than that, the server will consider it to be real Unix time value rather than an offset from current time.

        Specified by:
        add in interface MemcachedClientIF
        Parameters:
        key - the key under which this object should be added.
        exp - the expiration of this object
        o - the object to store
        Returns:
        a future representing the processing of this operation
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • set

        public <T> OperationFuture<java.lang.Boolean> set​(java.lang.String key,
                                                          int exp,
                                                          T o,
                                                          Transcoder<T> tc)
        Set an object in the cache regardless of any existing value.

        The exp value is passed along to memcached exactly as given, and will be processed per the memcached protocol specification:

        Note that the return will be false any time a mutation has not occurred.

        The actual value sent may either be Unix time (number of seconds since January 1, 1970, as a 32-bit value), or a number of seconds starting from current time. In the latter case, this number of seconds may not exceed 60*60*24*30 (number of seconds in 30 days); if the number sent by a client is larger than that, the server will consider it to be real Unix time value rather than an offset from current time.

        Specified by:
        set in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key under which this object should be added.
        exp - the expiration of this object
        o - the object to store
        tc - the transcoder to serialize and unserialize the value
        Returns:
        a future representing the processing of this operation
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • set

        public OperationFuture<java.lang.Boolean> set​(java.lang.String key,
                                                      int exp,
                                                      java.lang.Object o)
        Set an object in the cache (using the default transcoder) regardless of any existing value.

        The exp value is passed along to memcached exactly as given, and will be processed per the memcached protocol specification:

        Note that the return will be false any time a mutation has not occurred.

        The actual value sent may either be Unix time (number of seconds since January 1, 1970, as a 32-bit value), or a number of seconds starting from current time. In the latter case, this number of seconds may not exceed 60*60*24*30 (number of seconds in 30 days); if the number sent by a client is larger than that, the server will consider it to be real Unix time value rather than an offset from current time.

        Specified by:
        set in interface MemcachedClientIF
        Parameters:
        key - the key under which this object should be added.
        exp - the expiration of this object
        o - the object to store
        Returns:
        a future representing the processing of this operation
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • replace

        public <T> OperationFuture<java.lang.Boolean> replace​(java.lang.String key,
                                                              int exp,
                                                              T o,
                                                              Transcoder<T> tc)
        Replace an object with the given value iff there is already a value for the given key.

        The exp value is passed along to memcached exactly as given, and will be processed per the memcached protocol specification:

        Note that the return will be false any time a mutation has not occurred.

        The actual value sent may either be Unix time (number of seconds since January 1, 1970, as a 32-bit value), or a number of seconds starting from current time. In the latter case, this number of seconds may not exceed 60*60*24*30 (number of seconds in 30 days); if the number sent by a client is larger than that, the server will consider it to be real Unix time value rather than an offset from current time.

        Specified by:
        replace in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key under which this object should be added.
        exp - the expiration of this object
        o - the object to store
        tc - the transcoder to serialize and unserialize the value
        Returns:
        a future representing the processing of this operation
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • replace

        public OperationFuture<java.lang.Boolean> replace​(java.lang.String key,
                                                          int exp,
                                                          java.lang.Object o)
        Replace an object with the given value (transcoded with the default transcoder) iff there is already a value for the given key.

        The exp value is passed along to memcached exactly as given, and will be processed per the memcached protocol specification:

        Note that the return will be false any time a mutation has not occurred.

        The actual value sent may either be Unix time (number of seconds since January 1, 1970, as a 32-bit value), or a number of seconds starting from current time. In the latter case, this number of seconds may not exceed 60*60*24*30 (number of seconds in 30 days); if the number sent by a client is larger than that, the server will consider it to be real Unix time value rather than an offset from current time.

        Specified by:
        replace in interface MemcachedClientIF
        Parameters:
        key - the key under which this object should be added.
        exp - the expiration of this object
        o - the object to store
        Returns:
        a future representing the processing of this operation
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGet

        public <T> GetFuture<T> asyncGet​(java.lang.String key,
                                         Transcoder<T> tc)
        Get the given key asynchronously.
        Specified by:
        asyncGet in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key to fetch
        tc - the transcoder to serialize and unserialize value
        Returns:
        a future that will hold the return value of the fetch
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGet

        public GetFuture<java.lang.Object> asyncGet​(java.lang.String key)
        Get the given key asynchronously and decode with the default transcoder.
        Specified by:
        asyncGet in interface MemcachedClientIF
        Parameters:
        key - the key to fetch
        Returns:
        a future that will hold the return value of the fetch
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGets

        public <T> OperationFuture<CASValue<T>> asyncGets​(java.lang.String key,
                                                          Transcoder<T> tc)
        Gets (with CAS support) the given key asynchronously.
        Specified by:
        asyncGets in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key to fetch
        tc - the transcoder to serialize and unserialize value
        Returns:
        a future that will hold the return value of the fetch
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGets

        public OperationFuture<CASValue<java.lang.Object>> asyncGets​(java.lang.String key)
        Gets (with CAS support) the given key asynchronously and decode using the default transcoder.
        Specified by:
        asyncGets in interface MemcachedClientIF
        Parameters:
        key - the key to fetch
        Returns:
        a future that will hold the return value of the fetch
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • gets

        public <T> CASValue<T> gets​(java.lang.String key,
                                    Transcoder<T> tc)
        Gets (with CAS support) with a single key.
        Specified by:
        gets in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key to get
        tc - the transcoder to serialize and unserialize value
        Returns:
        the result from the cache and CAS id (null if there is none)
        Throws:
        OperationTimeoutException - if global operation timeout is exceeded
        java.util.concurrent.CancellationException - if operation was canceled
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • getAndTouch

        public <T> CASValue<T> getAndTouch​(java.lang.String key,
                                           int exp,
                                           Transcoder<T> tc)
        Get with a single key and reset its expiration.
        Specified by:
        getAndTouch in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key to get
        exp - the new expiration for the key
        tc - the transcoder to serialize and unserialize value
        Returns:
        the result from the cache (null if there is none)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.util.concurrent.CancellationException - if operation was canceled
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • getAndTouch

        public CASValue<java.lang.Object> getAndTouch​(java.lang.String key,
                                                      int exp)
        Get a single key and reset its expiration using the default transcoder.
        Specified by:
        getAndTouch in interface MemcachedClientIF
        Parameters:
        key - the key to get
        exp - the new expiration for the key
        Returns:
        the result from the cache and CAS id (null if there is none)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • gets

        public CASValue<java.lang.Object> gets​(java.lang.String key)
        Gets (with CAS support) with a single key using the default transcoder.
        Specified by:
        gets in interface MemcachedClientIF
        Parameters:
        key - the key to get
        Returns:
        the result from the cache and CAS id (null if there is none)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • get

        public <T> T get​(java.lang.String key,
                         Transcoder<T> tc)
        Get with a single key.
        Specified by:
        get in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        key - the key to get
        tc - the transcoder to serialize and unserialize value
        Returns:
        the result from the cache (null if there is none)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.util.concurrent.CancellationException - if operation was canceled
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • get

        public java.lang.Object get​(java.lang.String key)
        Get with a single key and decode using the default transcoder.
        Specified by:
        get in interface MemcachedClientIF
        Parameters:
        key - the key to get
        Returns:
        the result from the cache (null if there is none)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGetBulk

        public <T> BulkFuture<java.util.Map<java.lang.String,​T>> asyncGetBulk​(java.util.Iterator<java.lang.String> keyIter,
                                                                                    java.util.Iterator<Transcoder<T>> tcIter)
        Asynchronously get a bunch of objects from the cache.
        Specified by:
        asyncGetBulk in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        keyIter - Iterator that produces keys.
        tcIter - an iterator of transcoders to serialize and unserialize values; the transcoders are matched with the keys in the same order. The minimum of the key collection length and number of transcoders is used and no exception is thrown if they do not match
        Returns:
        a Future result of that fetch
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGetBulk

        public <T> BulkFuture<java.util.Map<java.lang.String,​T>> asyncGetBulk​(java.util.Collection<java.lang.String> keys,
                                                                                    java.util.Iterator<Transcoder<T>> tcIter)
        Asynchronously get a bunch of objects from the cache.
        Specified by:
        asyncGetBulk in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        keys - the keys to request
        tcIter - an iterator of transcoders to serialize and unserialize values; the transcoders are matched with the keys in the same order. The minimum of the key collection length and number of transcoders is used and no exception is thrown if they do not match
        Returns:
        a Future result of that fetch
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGetBulk

        public <T> BulkFuture<java.util.Map<java.lang.String,​T>> asyncGetBulk​(java.util.Iterator<java.lang.String> keyIter,
                                                                                    Transcoder<T> tc)
        Asynchronously get a bunch of objects from the cache.
        Specified by:
        asyncGetBulk in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        keyIter - Iterator for the keys to request
        tc - the transcoder to serialize and unserialize values
        Returns:
        a Future result of that fetch
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGetBulk

        public <T> BulkFuture<java.util.Map<java.lang.String,​T>> asyncGetBulk​(java.util.Collection<java.lang.String> keys,
                                                                                    Transcoder<T> tc)
        Asynchronously get a bunch of objects from the cache.
        Specified by:
        asyncGetBulk in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        keys - the keys to request
        tc - the transcoder to serialize and unserialize values
        Returns:
        a Future result of that fetch
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGetBulk

        public BulkFuture<java.util.Map<java.lang.String,​java.lang.Object>> asyncGetBulk​(java.util.Iterator<java.lang.String> keyIter)
        Asynchronously get a bunch of objects from the cache and decode them with the given transcoder.
        Specified by:
        asyncGetBulk in interface MemcachedClientIF
        Parameters:
        keyIter - Iterator that produces the keys to request
        Returns:
        a Future result of that fetch
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGetBulk

        public BulkFuture<java.util.Map<java.lang.String,​java.lang.Object>> asyncGetBulk​(java.util.Collection<java.lang.String> keys)
        Asynchronously get a bunch of objects from the cache and decode them with the given transcoder.
        Specified by:
        asyncGetBulk in interface MemcachedClientIF
        Parameters:
        keys - the keys to request
        Returns:
        a Future result of that fetch
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGetBulk

        public <T> BulkFuture<java.util.Map<java.lang.String,​T>> asyncGetBulk​(Transcoder<T> tc,
                                                                                    java.lang.String... keys)
        Varargs wrapper for asynchronous bulk gets.
        Specified by:
        asyncGetBulk in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        tc - the transcoder to serialize and unserialize value
        keys - one more more keys to get
        Returns:
        the future values of those keys
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGetBulk

        public BulkFuture<java.util.Map<java.lang.String,​java.lang.Object>> asyncGetBulk​(java.lang.String... keys)
        Varargs wrapper for asynchronous bulk gets with the default transcoder.
        Specified by:
        asyncGetBulk in interface MemcachedClientIF
        Parameters:
        keys - one more more keys to get
        Returns:
        the future values of those keys
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGetAndTouch

        public OperationFuture<CASValue<java.lang.Object>> asyncGetAndTouch​(java.lang.String key,
                                                                            int exp)
        Get the given key to reset its expiration time.
        Specified by:
        asyncGetAndTouch in interface MemcachedClientIF
        Parameters:
        key - the key to fetch
        exp - the new expiration to set for the given key
        Returns:
        a future that will hold the return value of the fetch
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncGetAndTouch

        public <T> OperationFuture<CASValue<T>> asyncGetAndTouch​(java.lang.String key,
                                                                 int exp,
                                                                 Transcoder<T> tc)
        Get the given key to reset its expiration time.
        Specified by:
        asyncGetAndTouch in interface MemcachedClientIF
        Parameters:
        key - the key to fetch
        exp - the new expiration to set for the given key
        tc - the transcoder to serialize and unserialize value
        Returns:
        a future that will hold the return value of the fetch
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • getBulk

        public <T> java.util.Map<java.lang.String,​T> getBulk​(java.util.Iterator<java.lang.String> keyIter,
                                                                   Transcoder<T> tc)
        Get the values for multiple keys from the cache.
        Specified by:
        getBulk in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        keyIter - Iterator that produces the keys
        tc - the transcoder to serialize and unserialize value
        Returns:
        a map of the values (for each value that exists)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.util.concurrent.CancellationException - if operation was canceled
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • getBulk

        public java.util.Map<java.lang.String,​java.lang.Object> getBulk​(java.util.Iterator<java.lang.String> keyIter)
        Get the values for multiple keys from the cache.
        Specified by:
        getBulk in interface MemcachedClientIF
        Parameters:
        keyIter - Iterator that produces the keys
        Returns:
        a map of the values (for each value that exists)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • getBulk

        public <T> java.util.Map<java.lang.String,​T> getBulk​(java.util.Collection<java.lang.String> keys,
                                                                   Transcoder<T> tc)
        Get the values for multiple keys from the cache.
        Specified by:
        getBulk in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        keys - the keys
        tc - the transcoder to serialize and unserialize value
        Returns:
        a map of the values (for each value that exists)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • getBulk

        public java.util.Map<java.lang.String,​java.lang.Object> getBulk​(java.util.Collection<java.lang.String> keys)
        Get the values for multiple keys from the cache.
        Specified by:
        getBulk in interface MemcachedClientIF
        Parameters:
        keys - the keys
        Returns:
        a map of the values (for each value that exists)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • getBulk

        public <T> java.util.Map<java.lang.String,​T> getBulk​(Transcoder<T> tc,
                                                                   java.lang.String... keys)
        Get the values for multiple keys from the cache.
        Specified by:
        getBulk in interface MemcachedClientIF
        Type Parameters:
        T -
        Parameters:
        tc - the transcoder to serialize and unserialize value
        keys - the keys
        Returns:
        a map of the values (for each value that exists)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • getBulk

        public java.util.Map<java.lang.String,​java.lang.Object> getBulk​(java.lang.String... keys)
        Get the values for multiple keys from the cache.
        Specified by:
        getBulk in interface MemcachedClientIF
        Parameters:
        keys - the keys
        Returns:
        a map of the values (for each value that exists)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • getVersions

        public java.util.Map<java.net.SocketAddress,​java.lang.String> getVersions()
        Get the versions of all of the connected memcacheds.
        Specified by:
        getVersions in interface MemcachedClientIF
        Returns:
        a Map of SocketAddress to String for connected servers
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • getStats

        public java.util.Map<java.net.SocketAddress,​java.util.Map<java.lang.String,​java.lang.String>> getStats()
        Get all of the stats from all of the connections.
        Specified by:
        getStats in interface MemcachedClientIF
        Returns:
        a Map of a Map of stats replies by SocketAddress
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • getStats

        public java.util.Map<java.net.SocketAddress,​java.util.Map<java.lang.String,​java.lang.String>> getStats​(java.lang.String arg)
        Get a set of stats from all connections.
        Specified by:
        getStats in interface MemcachedClientIF
        Parameters:
        arg - which stats to get
        Returns:
        a Map of the server SocketAddress to a map of String stat keys to String stat values.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • mutate

        private long mutate​(Mutator m,
                            java.lang.String key,
                            long by,
                            long def,
                            int exp)
      • incr

        public long incr​(java.lang.String key,
                         long by)
        Increment the given key by the given amount. Due to the way the memcached server operates on items, incremented and decremented items will be returned as Strings with any operations that return a value.
        Specified by:
        incr in interface MemcachedClientIF
        Parameters:
        key - the key
        by - the amount to increment
        Returns:
        the new value (-1 if the key doesn't exist)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • incr

        public long incr​(java.lang.String key,
                         int by)
        Increment the given key by the given amount. Due to the way the memcached server operates on items, incremented and decremented items will be returned as Strings with any operations that return a value.
        Specified by:
        incr in interface MemcachedClientIF
        Parameters:
        key - the key
        by - the amount to increment
        Returns:
        the new value (-1 if the key doesn't exist)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • decr

        public long decr​(java.lang.String key,
                         long by)
        Decrement the given key by the given value. Due to the way the memcached server operates on items, incremented and decremented items will be returned as Strings with any operations that return a value.
        Specified by:
        decr in interface MemcachedClientIF
        Parameters:
        key - the key
        by - the value
        Returns:
        the new value (-1 if the key doesn't exist)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • decr

        public long decr​(java.lang.String key,
                         int by)
        Decrement the given key by the given value. Due to the way the memcached server operates on items, incremented and decremented items will be returned as Strings with any operations that return a value.
        Specified by:
        decr in interface MemcachedClientIF
        Parameters:
        key - the key
        by - the value
        Returns:
        the new value (-1 if the key doesn't exist)
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • incr

        public long incr​(java.lang.String key,
                         long by,
                         long def,
                         int exp)
        Increment the given counter, returning the new value. Due to the way the memcached server operates on items, incremented and decremented items will be returned as Strings with any operations that return a value.
        Specified by:
        incr in interface MemcachedClientIF
        Parameters:
        key - the key
        by - the amount to increment
        def - the default value (if the counter does not exist)
        exp - the expiration of this object
        Returns:
        the new value, or -1 if we were unable to increment or add
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • incr

        public long incr​(java.lang.String key,
                         int by,
                         long def,
                         int exp)
        Increment the given counter, returning the new value. Due to the way the memcached server operates on items, incremented and decremented items will be returned as Strings with any operations that return a value.
        Specified by:
        incr in interface MemcachedClientIF
        Parameters:
        key - the key
        by - the amount to increment
        def - the default value (if the counter does not exist)
        exp - the expiration of this object
        Returns:
        the new value, or -1 if we were unable to increment or add
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • decr

        public long decr​(java.lang.String key,
                         long by,
                         long def,
                         int exp)
        Decrement the given counter, returning the new value. Due to the way the memcached server operates on items, incremented and decremented items will be returned as Strings with any operations that return a value.
        Specified by:
        decr in interface MemcachedClientIF
        Parameters:
        key - the key
        by - the amount to decrement
        def - the default value (if the counter does not exist)
        exp - the expiration of this object
        Returns:
        the new value, or -1 if we were unable to decrement or add
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • decr

        public long decr​(java.lang.String key,
                         int by,
                         long def,
                         int exp)
        Decrement the given counter, returning the new value. Due to the way the memcached server operates on items, incremented and decremented items will be returned as Strings with any operations that return a value.
        Specified by:
        decr in interface MemcachedClientIF
        Parameters:
        key - the key
        by - the amount to decrement
        def - the default value (if the counter does not exist)
        exp - the expiration of this object
        Returns:
        the new value, or -1 if we were unable to decrement or add
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • mutateWithDefault

        private long mutateWithDefault​(Mutator t,
                                       java.lang.String key,
                                       long by,
                                       long def,
                                       int exp)
      • asyncMutate

        private OperationFuture<java.lang.Long> asyncMutate​(Mutator m,
                                                            java.lang.String key,
                                                            long by,
                                                            long def,
                                                            int exp)
      • asyncIncr

        public OperationFuture<java.lang.Long> asyncIncr​(java.lang.String key,
                                                         long by)
        Asychronous increment.
        Specified by:
        asyncIncr in interface MemcachedClientIF
        Parameters:
        key - key to increment
        by - the amount to increment the value by
        Returns:
        a future with the incremented value, or -1 if the increment failed.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncIncr

        public OperationFuture<java.lang.Long> asyncIncr​(java.lang.String key,
                                                         int by)
        Asychronous increment.
        Specified by:
        asyncIncr in interface MemcachedClientIF
        Parameters:
        key - key to increment
        by - the amount to increment the value by
        Returns:
        a future with the incremented value, or -1 if the increment failed.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncDecr

        public OperationFuture<java.lang.Long> asyncDecr​(java.lang.String key,
                                                         long by)
        Asynchronous decrement.
        Specified by:
        asyncDecr in interface MemcachedClientIF
        Parameters:
        key - key to decrement
        by - the amount to decrement the value by
        Returns:
        a future with the decremented value, or -1 if the decrement failed.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncDecr

        public OperationFuture<java.lang.Long> asyncDecr​(java.lang.String key,
                                                         int by)
        Asynchronous decrement.
        Specified by:
        asyncDecr in interface MemcachedClientIF
        Parameters:
        key - key to decrement
        by - the amount to decrement the value by
        Returns:
        a future with the decremented value, or -1 if the decrement failed.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncIncr

        public OperationFuture<java.lang.Long> asyncIncr​(java.lang.String key,
                                                         long by,
                                                         long def,
                                                         int exp)
        Asychronous increment.
        Specified by:
        asyncIncr in interface MemcachedClientIF
        Parameters:
        key - key to increment
        by - the amount to increment the value by
        def - the default value (if the counter does not exist)
        exp - the expiration of this object
        Returns:
        a future with the incremented value, or -1 if the increment failed.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncIncr

        public OperationFuture<java.lang.Long> asyncIncr​(java.lang.String key,
                                                         int by,
                                                         long def,
                                                         int exp)
        Asychronous increment.
        Specified by:
        asyncIncr in interface MemcachedClientIF
        Parameters:
        key - key to increment
        by - the amount to increment the value by
        def - the default value (if the counter does not exist)
        exp - the expiration of this object
        Returns:
        a future with the incremented value, or -1 if the increment failed.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncDecr

        public OperationFuture<java.lang.Long> asyncDecr​(java.lang.String key,
                                                         long by,
                                                         long def,
                                                         int exp)
        Asynchronous decrement.
        Specified by:
        asyncDecr in interface MemcachedClientIF
        Parameters:
        key - key to decrement
        by - the amount to decrement the value by
        def - the default value (if the counter does not exist)
        exp - the expiration of this object
        Returns:
        a future with the decremented value, or -1 if the decrement failed.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncDecr

        public OperationFuture<java.lang.Long> asyncDecr​(java.lang.String key,
                                                         int by,
                                                         long def,
                                                         int exp)
        Asynchronous decrement.
        Specified by:
        asyncDecr in interface MemcachedClientIF
        Parameters:
        key - key to decrement
        by - the amount to decrement the value by
        def - the default value (if the counter does not exist)
        exp - the expiration of this object
        Returns:
        a future with the decremented value, or -1 if the decrement failed.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncIncr

        public OperationFuture<java.lang.Long> asyncIncr​(java.lang.String key,
                                                         long by,
                                                         long def)
        Asychronous increment.
        Specified by:
        asyncIncr in interface MemcachedClientIF
        Parameters:
        key - key to increment
        by - the amount to increment the value by
        def - the default value (if the counter does not exist)
        Returns:
        a future with the incremented value, or -1 if the increment failed.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncIncr

        public OperationFuture<java.lang.Long> asyncIncr​(java.lang.String key,
                                                         int by,
                                                         long def)
        Asychronous increment.
        Specified by:
        asyncIncr in interface MemcachedClientIF
        Parameters:
        key - key to increment
        by - the amount to increment the value by
        def - the default value (if the counter does not exist)
        Returns:
        a future with the incremented value, or -1 if the increment failed.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncDecr

        public OperationFuture<java.lang.Long> asyncDecr​(java.lang.String key,
                                                         long by,
                                                         long def)
        Asynchronous decrement.
        Specified by:
        asyncDecr in interface MemcachedClientIF
        Parameters:
        key - key to decrement
        by - the amount to decrement the value by
        def - the default value (if the counter does not exist)
        Returns:
        a future with the decremented value, or -1 if the decrement failed.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • asyncDecr

        public OperationFuture<java.lang.Long> asyncDecr​(java.lang.String key,
                                                         int by,
                                                         long def)
        Asynchronous decrement.
        Specified by:
        asyncDecr in interface MemcachedClientIF
        Parameters:
        key - key to decrement
        by - the amount to decrement the value by
        def - the default value (if the counter does not exist)
        Returns:
        a future with the decremented value, or -1 if the decrement failed.
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • incr

        public long incr​(java.lang.String key,
                         long by,
                         long def)
        Increment the given counter, returning the new value.
        Specified by:
        incr in interface MemcachedClientIF
        Parameters:
        key - the key
        by - the amount to increment
        def - the default value (if the counter does not exist)
        Returns:
        the new value, or -1 if we were unable to increment or add
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • incr

        public long incr​(java.lang.String key,
                         int by,
                         long def)
        Increment the given counter, returning the new value.
        Specified by:
        incr in interface MemcachedClientIF
        Parameters:
        key - the key
        by - the amount to increment
        def - the default value (if the counter does not exist)
        Returns:
        the new value, or -1 if we were unable to increment or add
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • decr

        public long decr​(java.lang.String key,
                         long by,
                         long def)
        Decrement the given counter, returning the new value.
        Specified by:
        decr in interface MemcachedClientIF
        Parameters:
        key - the key
        by - the amount to decrement
        def - the default value (if the counter does not exist)
        Returns:
        the new value, or -1 if we were unable to decrement or add
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • decr

        public long decr​(java.lang.String key,
                         int by,
                         long def)
        Decrement the given counter, returning the new value.
        Specified by:
        decr in interface MemcachedClientIF
        Parameters:
        key - the key
        by - the amount to decrement
        def - the default value (if the counter does not exist)
        Returns:
        the new value, or -1 if we were unable to decrement or add
        Throws:
        OperationTimeoutException - if the global operation timeout is exceeded
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • delete

        @Deprecated
        public OperationFuture<java.lang.Boolean> delete​(java.lang.String key,
                                                         int hold)
        Deprecated.
        Hold values are no longer honored.
        Delete the given key from the cache.

        The hold argument specifies the amount of time in seconds (or Unix time until which) the client wishes the server to refuse "add" and "replace" commands with this key. For this amount of item, the item is put into a delete queue, which means that it won't possible to retrieve it by the "get" command, but "add" and "replace" command with this key will also fail (the "set" command will succeed, however). After the time passes, the item is finally deleted from server memory.

        Parameters:
        key - the key to delete
        hold - how long the key should be unavailable to add commands
        Returns:
        whether or not the operation was performed
      • delete

        public OperationFuture<java.lang.Boolean> delete​(java.lang.String key)
        Delete the given key from the cache.
        Specified by:
        delete in interface MemcachedClientIF
        Parameters:
        key - the key to delete
        Returns:
        whether or not the operation was performed
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • delete

        public OperationFuture<java.lang.Boolean> delete​(java.lang.String key,
                                                         long cas)
        Delete the given key from the cache of the given CAS value applies.
        Specified by:
        delete in interface MemcachedClientIF
        Parameters:
        key - the key to delete
        cas - the CAS value to apply.
        Returns:
        whether or not the operation was performed
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • flush

        public OperationFuture<java.lang.Boolean> flush​(int delay)
        Flush all caches from all servers with a delay of application.
        Specified by:
        flush in interface MemcachedClientIF
        Parameters:
        delay - the period of time to delay, in seconds
        Returns:
        whether or not the operation was accepted
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • flush

        public OperationFuture<java.lang.Boolean> flush()
        Flush all caches from all servers immediately.
        Specified by:
        flush in interface MemcachedClientIF
        Returns:
        whether or not the operation was performed
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • listSaslMechanisms

        public java.util.Set<java.lang.String> listSaslMechanisms()
        Description copied from interface: MemcachedClientIF
        Get the set of SASL mechanisms supported by the servers.
        Specified by:
        listSaslMechanisms in interface MemcachedClientIF
        Returns:
        the union of all SASL mechanisms supported by the servers.
      • shutdown

        public boolean shutdown​(long timeout,
                                java.util.concurrent.TimeUnit unit)
        Shut down this client gracefully.
        Specified by:
        shutdown in interface MemcachedClientIF
        Parameters:
        timeout - the amount of time time for shutdown
        unit - the TimeUnit for the timeout
        Returns:
        result of the shutdown request
      • waitForQueues

        public boolean waitForQueues​(long timeout,
                                     java.util.concurrent.TimeUnit unit)
        Wait for the queues to die down.
        Specified by:
        waitForQueues in interface MemcachedClientIF
        Parameters:
        timeout - the amount of time time for shutdown
        unit - the TimeUnit for the timeout
        Returns:
        result of the request for the wait
        Throws:
        java.lang.IllegalStateException - in the rare circumstance where queue is too full to accept any more requests
      • addObserver

        public boolean addObserver​(ConnectionObserver obs)
        Add a connection observer. If connections are already established, your observer will be called with the address and -1.
        Specified by:
        addObserver in interface MemcachedClientIF
        Parameters:
        obs - the ConnectionObserver you wish to add
        Returns:
        true if the observer was added.
      • removeObserver

        public boolean removeObserver​(ConnectionObserver obs)
        Remove a connection observer.
        Specified by:
        removeObserver in interface MemcachedClientIF
        Parameters:
        obs - the ConnectionObserver you wish to add
        Returns:
        true if the observer existed, but no longer does
      • connectionEstablished

        public void connectionEstablished​(java.net.SocketAddress sa,
                                          int reconnectCount)
        Description copied from interface: ConnectionObserver
        A connection has just successfully been established on the given socket.
        Specified by:
        connectionEstablished in interface ConnectionObserver
        Parameters:
        sa - the address of the node whose connection was established
        reconnectCount - the number of attempts before the connection was established
      • findNode

        private MemcachedNode findNode​(java.net.SocketAddress sa)
      • buildTimeoutMessage

        private java.lang.String buildTimeoutMessage​(long timeWaited,
                                                     java.util.concurrent.TimeUnit unit)
      • connectionLost

        public void connectionLost​(java.net.SocketAddress sa)
        Description copied from interface: ConnectionObserver
        A connection was just lost on the given socket.
        Specified by:
        connectionLost in interface ConnectionObserver
        Parameters:
        sa - the address of the node whose connection was lost
      • getOperationTimeout

        public long getOperationTimeout()
      • getExecutorService

        public java.util.concurrent.ExecutorService getExecutorService()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object