com.alisoft.xplatform.asf.cache.memcached.client
类 MemCachedClient

java.lang.Object
  继承者 com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient

public class MemCachedClient
extends java.lang.Object

This is a Java client for the memcached server available from http://www.danga.com/memcached/.
Supports setting, adding, replacing, deleting compressed/uncompressed and
serialized (can be stored as string if object is native class) objects to memcached.

Now pulls SockIO objects from SockIOPool, which is a connection pool. The server failover
has also been moved into the SockIOPool class.
This pool needs to be initialized prior to the client working. See javadocs from SockIOPool.

Some examples of use follow.

To create cache client object and set params:

 
        MemCachedClient mc = new MemCachedClient();

        // compression is enabled by default    
        mc.setCompressEnable(true);

        // set compression threshhold to 4 KB (default: 15 KB)  
        mc.setCompressThreshold(4096);

        // turn on storing primitive types as a string representation
        // Should not do this in most cases.    
        mc.setPrimitiveAsString(true);
 

To store an object:

        MemCachedClient mc = new MemCachedClient();
        String key   = "cacheKey1";     
        Object value = SomeClass.getObject();   
        mc.set(key, value);
 

To store an object using a custom server hashCode:

        MemCachedClient mc = new MemCachedClient();
        String key   = "cacheKey1";     
        Object value = SomeClass.getObject();   
        Integer hash = new Integer(45); 
        mc.set(key, value, hash);
 
The set method shown above will always set the object in the cache.
The add and replace methods do the same, but with a slight difference.

To delete a cache entry:

        MemCachedClient mc = new MemCachedClient();
        String key   = "cacheKey1";     
        mc.delete(key);
 

To delete a cache entry using a custom hash code:

        MemCachedClient mc = new MemCachedClient();
        String key   = "cacheKey1";     
        Integer hash = new Integer(45); 
        mc.delete(key, hashCode);
 

To store a counter and then increment or decrement that counter:

        MemCachedClient mc = new MemCachedClient();
        String key   = "counterKey";    
        mc.storeCounter(key, new Integer(100));
        System.out.println("counter after adding      1: " mc.incr(key));       
        System.out.println("counter after adding      5: " mc.incr(key, 5));    
        System.out.println("counter after subtracting 4: " mc.decr(key, 4));    
        System.out.println("counter after subtracting 1: " mc.decr(key));       
 

To store a counter and then increment or decrement that counter with custom hash:

        MemCachedClient mc = new MemCachedClient();
        String key   = "counterKey";    
        Integer hash = new Integer(45); 
        mc.storeCounter(key, new Integer(100), hash);
        System.out.println("counter after adding      1: " mc.incr(key, 1, hash));      
        System.out.println("counter after adding      5: " mc.incr(key, 5, hash));      
        System.out.println("counter after subtracting 4: " mc.decr(key, 4, hash));      
        System.out.println("counter after subtracting 1: " mc.decr(key, 1, hash));      
 

To retrieve an object from the cache:

        MemCachedClient mc = new MemCachedClient();
        String key   = "key";   
        Object value = mc.get(key);     
 

To retrieve an object from the cache with custom hash:

        MemCachedClient mc = new MemCachedClient();
        String key   = "key";   
        Integer hash = new Integer(45); 
        Object value = mc.get(key, hash);       
 

To retrieve an multiple objects from the cache

        MemCachedClient mc = new MemCachedClient();
        String[] keys      = { "key", "key1", "key2" };
        Map<Object> values = mc.getMulti(keys);
 

To retrieve an multiple objects from the cache with custom hashing

        MemCachedClient mc = new MemCachedClient();
        String[] keys      = { "key", "key1", "key2" };
        Integer[] hashes   = { new Integer(45), new Integer(32), new Integer(44) };
        Map<Object> values = mc.getMulti(keys, hashes);
 

To flush all items in server(s)

        MemCachedClient mc = new MemCachedClient();
        mc.flushAll();
 

To get stats from server(s)

        MemCachedClient mc = new MemCachedClient();
        Map stats = mc.stats();
 


嵌套类摘要
protected  class MemCachedClient.NIOLoader
           
 
字段摘要
static int F_COMPRESSED
           
static int F_SERIALIZED
           
static int MARKER_BOOLEAN
           
static int MARKER_BYTE
           
static int MARKER_BYTEARR
           
static int MARKER_CHARACTER
           
static int MARKER_DATE
           
static int MARKER_DOUBLE
           
static int MARKER_FLOAT
           
static int MARKER_INTEGER
           
static int MARKER_LONG
           
static int MARKER_SHORT
           
static int MARKER_STRING
           
static int MARKER_STRINGBUFFER
           
static int MARKER_STRINGBUILDER
           
 
构造方法摘要
MemCachedClient()
          Creates a new instance of MemCachedClient.
MemCachedClient(java.lang.ClassLoader classLoader)
          Creates a new instance of MemCacheClient but acceptes a passed in ClassLoader.
MemCachedClient(java.lang.ClassLoader classLoader, ErrorHandler errorHandler)
          Creates a new instance of MemCacheClient but acceptes a passed in ClassLoader and a passed in ErrorHandler.
MemCachedClient(java.lang.ClassLoader classLoader, ErrorHandler errorHandler, java.lang.String poolName)
          Creates a new instance of MemCacheClient but acceptes a passed in ClassLoader, ErrorHandler, and SockIOPool name.
MemCachedClient(java.lang.String poolName)
          Creates a new instance of MemCachedClient accepting a passed in pool name.
 
方法摘要
 boolean add(java.lang.String key, java.lang.Object value)
          Adds data to the server; only the key and the value are specified.
 boolean add(java.lang.String key, java.lang.Object value, java.util.Date expiry)
          Adds data to the server; the key, value, and an expiration time are specified.
 boolean add(java.lang.String key, java.lang.Object value, java.util.Date expiry, java.lang.Integer hashCode)
          Adds data to the server; the key, value, and an expiration time are specified.
 boolean add(java.lang.String key, java.lang.Object value, java.lang.Integer hashCode)
          Adds data to the server; the key, value, and an optional hashcode are passed in.
 long addOrDecr(java.lang.String key)
          Thread safe way to initialize and decrement a counter.
 long addOrDecr(java.lang.String key, long inc)
          Thread safe way to initialize and decrement a counter.
 long addOrDecr(java.lang.String key, long inc, java.lang.Integer hashCode)
          Thread safe way to initialize and decrement a counter.
 long addOrIncr(java.lang.String key)
          Thread safe way to initialize and increment a counter.
 long addOrIncr(java.lang.String key, long inc)
          Thread safe way to initialize and increment a counter.
 long addOrIncr(java.lang.String key, long inc, java.lang.Integer hashCode)
          Thread safe way to initialize and increment a counter.
 long decr(java.lang.String key)
          Decrement the value at the specified key by 1, and then return it.
 long decr(java.lang.String key, long inc)
          Decrement the value at the specified key by passed in value, and then return it.
 long decr(java.lang.String key, long inc, java.lang.Integer hashCode)
          Decrement the value at the specified key by the specified increment, and then return it.
 boolean delete(java.lang.String key)
          Deletes an object from cache given cache key.
 boolean delete(java.lang.String key, java.util.Date expiry)
          Deletes an object from cache given cache key and expiration date.
 boolean delete(java.lang.String key, java.lang.Integer hashCode, java.util.Date expiry)
          Deletes an object from cache given cache key, a delete time, and an optional hashcode.
 boolean flushAll()
          Invalidates the entire cache.
 boolean flushAll(java.lang.String[] servers)
          Invalidates the entire cache.
 java.lang.Object get(java.lang.String key)
          Retrieve a key from the server, using a specific hash.
 java.lang.Object get(java.lang.String key, java.lang.Integer hashCode)
          Retrieve a key from the server, using a specific hash.
 java.lang.Object get(java.lang.String key, java.lang.Integer hashCode, boolean asString)
          Retrieve a key from the server, using a specific hash.
 long getCounter(java.lang.String key)
          Returns value in counter at given key as long.
 long getCounter(java.lang.String key, java.lang.Integer hashCode)
          Returns value in counter at given key as long.
 java.util.Map<java.lang.String,java.lang.Object> getMulti(java.lang.String[] keys)
          Retrieve multiple objects from the memcache.
 java.util.Map<java.lang.String,java.lang.Object> getMulti(java.lang.String[] keys, java.lang.Integer[] hashCodes)
          Retrieve multiple keys from the memcache.
 java.util.Map<java.lang.String,java.lang.Object> getMulti(java.lang.String[] keys, java.lang.Integer[] hashCodes, boolean asString)
          Retrieve multiple keys from the memcache.
 java.lang.Object[] getMultiArray(java.lang.String[] keys)
          Retrieve multiple objects from the memcache.
 java.lang.Object[] getMultiArray(java.lang.String[] keys, java.lang.Integer[] hashCodes)
          Retrieve multiple objects from the memcache.
 java.lang.Object[] getMultiArray(java.lang.String[] keys, java.lang.Integer[] hashCodes, boolean asString)
          Retrieve multiple objects from the memcache.
 long incr(java.lang.String key)
          Increment the value at the specified key by 1, and then return it.
 long incr(java.lang.String key, long inc)
          Increment the value at the specified key by passed in val.
 long incr(java.lang.String key, long inc, java.lang.Integer hashCode)
          Increment the value at the specified key by the specified increment, and then return it.
 boolean keyExists(java.lang.String key)
          Checks to see if key exists in cache.
 boolean replace(java.lang.String key, java.lang.Object value)
          Updates data on the server; only the key and the value are specified.
 boolean replace(java.lang.String key, java.lang.Object value, java.util.Date expiry)
          Updates data on the server; the key, value, and an expiration time are specified.
 boolean replace(java.lang.String key, java.lang.Object value, java.util.Date expiry, java.lang.Integer hashCode)
          Updates data on the server; the key, value, and an expiration time are specified.
 boolean replace(java.lang.String key, java.lang.Object value, java.lang.Integer hashCode)
          Updates data on the server; only the key and the value and an optional hash are specified.
 boolean set(java.lang.String key, java.lang.Object value)
          Stores data on the server; only the key and the value are specified.
 boolean set(java.lang.String key, java.lang.Object value, java.util.Date expiry)
          Stores data on the server; the key, value, and an expiration time are specified.
 boolean set(java.lang.String key, java.lang.Object value, java.util.Date expiry, java.lang.Integer hashCode)
          Stores data on the server; the key, value, and an expiration time are specified.
 boolean set(java.lang.String key, java.lang.Object value, java.lang.Integer hashCode)
          Stores data on the server; only the key and the value are specified.
 void setClassLoader(java.lang.ClassLoader classLoader)
          Sets an optional ClassLoader to be used for serialization.
 void setCompressEnable(boolean compressEnable)
          Enable storing compressed data, provided it meets the threshold requirements.
 void setCompressThreshold(long compressThreshold)
          Sets the required length for data to be considered for compression.
 void setDefaultEncoding(java.lang.String defaultEncoding)
          Sets default String encoding when storing primitives as Strings.
 void setErrorHandler(ErrorHandler errorHandler)
          Sets an optional ErrorHandler.
 void setPrimitiveAsString(boolean primitiveAsString)
          Enables storing primitive types as their String values.
 void setSanitizeKeys(boolean sanitizeKeys)
          Enables/disables sanitizing keys by URLEncoding.
 java.util.Map stats()
          Retrieves stats for all servers.
 java.util.Map stats(java.lang.String[] servers)
          Retrieves stats for passed in servers (or all servers).
 java.util.Map statsCacheDump(int slabNumber, int limit)
          Retrieves items cachedump for all servers.
 java.util.Map statsCacheDump(java.lang.String[] servers, int slabNumber, int limit)
          Retrieves stats for passed in servers (or all servers).
 java.util.Map statsItems()
          Retrieves stats items for all servers.
 java.util.Map statsItems(java.lang.String[] servers)
          Retrieves stats for passed in servers (or all servers).
 java.util.Map statsSlabs()
          Retrieves stats items for all servers.
 java.util.Map statsSlabs(java.lang.String[] servers)
          Retrieves stats for passed in servers (or all servers).
 boolean storeCounter(java.lang.String key, long counter)
          Store a counter to memcached given a key
 boolean storeCounter(java.lang.String key, java.lang.Long counter)
          Store a counter to memcached given a key
 boolean storeCounter(java.lang.String key, java.lang.Long counter, java.lang.Integer hashCode)
          Store a counter to memcached given a key
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

MARKER_BYTE

public static final int MARKER_BYTE
另请参见:
常量字段值

MARKER_BOOLEAN

public static final int MARKER_BOOLEAN
另请参见:
常量字段值

MARKER_INTEGER

public static final int MARKER_INTEGER
另请参见:
常量字段值

MARKER_LONG

public static final int MARKER_LONG
另请参见:
常量字段值

MARKER_CHARACTER

public static final int MARKER_CHARACTER
另请参见:
常量字段值

MARKER_STRING

public static final int MARKER_STRING
另请参见:
常量字段值

MARKER_STRINGBUFFER

public static final int MARKER_STRINGBUFFER
另请参见:
常量字段值

MARKER_FLOAT

public static final int MARKER_FLOAT
另请参见:
常量字段值

MARKER_SHORT

public static final int MARKER_SHORT
另请参见:
常量字段值

MARKER_DOUBLE

public static final int MARKER_DOUBLE
另请参见:
常量字段值

MARKER_DATE

public static final int MARKER_DATE
另请参见:
常量字段值

MARKER_STRINGBUILDER

public static final int MARKER_STRINGBUILDER
另请参见:
常量字段值

MARKER_BYTEARR

public static final int MARKER_BYTEARR
另请参见:
常量字段值

F_COMPRESSED

public static final int F_COMPRESSED
另请参见:
常量字段值

F_SERIALIZED

public static final int F_SERIALIZED
另请参见:
常量字段值
构造方法详细信息

MemCachedClient

public MemCachedClient()
Creates a new instance of MemCachedClient.


MemCachedClient

public MemCachedClient(java.lang.String poolName)
Creates a new instance of MemCachedClient accepting a passed in pool name.

参数:
poolName - name of SockIOPool

MemCachedClient

public MemCachedClient(java.lang.ClassLoader classLoader)
Creates a new instance of MemCacheClient but acceptes a passed in ClassLoader.

参数:
classLoader - ClassLoader object.

MemCachedClient

public MemCachedClient(java.lang.ClassLoader classLoader,
                       ErrorHandler errorHandler)
Creates a new instance of MemCacheClient but acceptes a passed in ClassLoader and a passed in ErrorHandler.

参数:
classLoader - ClassLoader object.
errorHandler - ErrorHandler object.

MemCachedClient

public MemCachedClient(java.lang.ClassLoader classLoader,
                       ErrorHandler errorHandler,
                       java.lang.String poolName)
Creates a new instance of MemCacheClient but acceptes a passed in ClassLoader, ErrorHandler, and SockIOPool name.

参数:
classLoader - ClassLoader object.
errorHandler - ErrorHandler object.
poolName - SockIOPool name
方法详细信息

setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Sets an optional ClassLoader to be used for serialization.

参数:
classLoader -

setErrorHandler

public void setErrorHandler(ErrorHandler errorHandler)
Sets an optional ErrorHandler.

参数:
errorHandler -

setSanitizeKeys

public void setSanitizeKeys(boolean sanitizeKeys)
Enables/disables sanitizing keys by URLEncoding.

参数:
sanitizeKeys - if true, then URLEncode all keys

setPrimitiveAsString

public void setPrimitiveAsString(boolean primitiveAsString)
Enables storing primitive types as their String values.

参数:
primitiveAsString - if true, then store all primitives as their string value.

setDefaultEncoding

public void setDefaultEncoding(java.lang.String defaultEncoding)
Sets default String encoding when storing primitives as Strings. Default is UTF-8.

参数:
defaultEncoding -

setCompressEnable

public void setCompressEnable(boolean compressEnable)
Enable storing compressed data, provided it meets the threshold requirements. If enabled, data will be stored in compressed form if it is
longer than the threshold length set with setCompressThreshold(int)

The default is that compression is enabled.

Even if compression is disabled, compressed data will be automatically
decompressed.

参数:
compressEnable - true to enable compression, false to disable compression

setCompressThreshold

public void setCompressThreshold(long compressThreshold)
Sets the required length for data to be considered for compression. If the length of the data to be stored is not equal or larger than this value, it will not be compressed. This defaults to 15 KB.

参数:
compressThreshold - required length of data to consider compression

keyExists

public boolean keyExists(java.lang.String key)
Checks to see if key exists in cache.

参数:
key - the key to look for
返回:
true if key found in cache, false if not (or if cache is down)

delete

public boolean delete(java.lang.String key)
Deletes an object from cache given cache key.

参数:
key - the key to be removed
返回:
true, if the data was deleted successfully

delete

public boolean delete(java.lang.String key,
                      java.util.Date expiry)
Deletes an object from cache given cache key and expiration date.

参数:
key - the key to be removed
expiry - when to expire the record.
返回:
true, if the data was deleted successfully

delete

public boolean delete(java.lang.String key,
                      java.lang.Integer hashCode,
                      java.util.Date expiry)
Deletes an object from cache given cache key, a delete time, and an optional hashcode. The item is immediately made non retrievable.
Keep in mind add and replace
will fail when used with the same key will fail, until the server reaches the
specified time. However, set will succeed,
and the new value will not be deleted.

参数:
key - the key to be removed
hashCode - if not null, then the int hashcode to use
expiry - when to expire the record.
返回:
true, if the data was deleted successfully

set

public boolean set(java.lang.String key,
                   java.lang.Object value)
Stores data on the server; only the key and the value are specified.

参数:
key - key to store data under
value - value to store
返回:
true, if the data was successfully stored

set

public boolean set(java.lang.String key,
                   java.lang.Object value,
                   java.lang.Integer hashCode)
Stores data on the server; only the key and the value are specified.

参数:
key - key to store data under
value - value to store
hashCode - if not null, then the int hashcode to use
返回:
true, if the data was successfully stored

set

public boolean set(java.lang.String key,
                   java.lang.Object value,
                   java.util.Date expiry)
Stores data on the server; the key, value, and an expiration time are specified.

参数:
key - key to store data under
value - value to store
expiry - when to expire the record
返回:
true, if the data was successfully stored

set

public boolean set(java.lang.String key,
                   java.lang.Object value,
                   java.util.Date expiry,
                   java.lang.Integer hashCode)
Stores data on the server; the key, value, and an expiration time are specified.

参数:
key - key to store data under
value - value to store
expiry - when to expire the record
hashCode - if not null, then the int hashcode to use
返回:
true, if the data was successfully stored

add

public boolean add(java.lang.String key,
                   java.lang.Object value)
Adds data to the server; only the key and the value are specified.

参数:
key - key to store data under
value - value to store
返回:
true, if the data was successfully stored

add

public boolean add(java.lang.String key,
                   java.lang.Object value,
                   java.lang.Integer hashCode)
Adds data to the server; the key, value, and an optional hashcode are passed in.

参数:
key - key to store data under
value - value to store
hashCode - if not null, then the int hashcode to use
返回:
true, if the data was successfully stored

add

public boolean add(java.lang.String key,
                   java.lang.Object value,
                   java.util.Date expiry)
Adds data to the server; the key, value, and an expiration time are specified.

参数:
key - key to store data under
value - value to store
expiry - when to expire the record
返回:
true, if the data was successfully stored

add

public boolean add(java.lang.String key,
                   java.lang.Object value,
                   java.util.Date expiry,
                   java.lang.Integer hashCode)
Adds data to the server; the key, value, and an expiration time are specified.

参数:
key - key to store data under
value - value to store
expiry - when to expire the record
hashCode - if not null, then the int hashcode to use
返回:
true, if the data was successfully stored

replace

public boolean replace(java.lang.String key,
                       java.lang.Object value)
Updates data on the server; only the key and the value are specified.

参数:
key - key to store data under
value - value to store
返回:
true, if the data was successfully stored

replace

public boolean replace(java.lang.String key,
                       java.lang.Object value,
                       java.lang.Integer hashCode)
Updates data on the server; only the key and the value and an optional hash are specified.

参数:
key - key to store data under
value - value to store
hashCode - if not null, then the int hashcode to use
返回:
true, if the data was successfully stored

replace

public boolean replace(java.lang.String key,
                       java.lang.Object value,
                       java.util.Date expiry)
Updates data on the server; the key, value, and an expiration time are specified.

参数:
key - key to store data under
value - value to store
expiry - when to expire the record
返回:
true, if the data was successfully stored

replace

public boolean replace(java.lang.String key,
                       java.lang.Object value,
                       java.util.Date expiry,
                       java.lang.Integer hashCode)
Updates data on the server; the key, value, and an expiration time are specified.

参数:
key - key to store data under
value - value to store
expiry - when to expire the record
hashCode - if not null, then the int hashcode to use
返回:
true, if the data was successfully stored

storeCounter

public boolean storeCounter(java.lang.String key,
                            long counter)
Store a counter to memcached given a key

参数:
key - cache key
counter - number to store
返回:
true/false indicating success

storeCounter

public boolean storeCounter(java.lang.String key,
                            java.lang.Long counter)
Store a counter to memcached given a key

参数:
key - cache key
counter - number to store
返回:
true/false indicating success

storeCounter

public boolean storeCounter(java.lang.String key,
                            java.lang.Long counter,
                            java.lang.Integer hashCode)
Store a counter to memcached given a key

参数:
key - cache key
counter - number to store
hashCode - if not null, then the int hashcode to use
返回:
true/false indicating success

getCounter

public long getCounter(java.lang.String key)
Returns value in counter at given key as long.

参数:
key - cache ket
返回:
counter value or -1 if not found

getCounter

public long getCounter(java.lang.String key,
                       java.lang.Integer hashCode)
Returns value in counter at given key as long.

参数:
key - cache ket
hashCode - if not null, then the int hashcode to use
返回:
counter value or -1 if not found

addOrIncr

public long addOrIncr(java.lang.String key)
Thread safe way to initialize and increment a counter.

参数:
key - key where the data is stored
返回:
value of incrementer

addOrIncr

public long addOrIncr(java.lang.String key,
                      long inc)
Thread safe way to initialize and increment a counter.

参数:
key - key where the data is stored
inc - value to set or increment by
返回:
value of incrementer

addOrIncr

public long addOrIncr(java.lang.String key,
                      long inc,
                      java.lang.Integer hashCode)
Thread safe way to initialize and increment a counter.

参数:
key - key where the data is stored
inc - value to set or increment by
hashCode - if not null, then the int hashcode to use
返回:
value of incrementer

addOrDecr

public long addOrDecr(java.lang.String key)
Thread safe way to initialize and decrement a counter.

参数:
key - key where the data is stored
返回:
value of incrementer

addOrDecr

public long addOrDecr(java.lang.String key,
                      long inc)
Thread safe way to initialize and decrement a counter.

参数:
key - key where the data is stored
inc - value to set or increment by
返回:
value of incrementer

addOrDecr

public long addOrDecr(java.lang.String key,
                      long inc,
                      java.lang.Integer hashCode)
Thread safe way to initialize and decrement a counter.

参数:
key - key where the data is stored
inc - value to set or increment by
hashCode - if not null, then the int hashcode to use
返回:
value of incrementer

incr

public long incr(java.lang.String key)
Increment the value at the specified key by 1, and then return it.

参数:
key - key where the data is stored
返回:
-1, if the key is not found, the value after incrementing otherwise

incr

public long incr(java.lang.String key,
                 long inc)
Increment the value at the specified key by passed in val.

参数:
key - key where the data is stored
inc - how much to increment by
返回:
-1, if the key is not found, the value after incrementing otherwise

incr

public long incr(java.lang.String key,
                 long inc,
                 java.lang.Integer hashCode)
Increment the value at the specified key by the specified increment, and then return it.

参数:
key - key where the data is stored
inc - how much to increment by
hashCode - if not null, then the int hashcode to use
返回:
-1, if the key is not found, the value after incrementing otherwise

decr

public long decr(java.lang.String key)
Decrement the value at the specified key by 1, and then return it.

参数:
key - key where the data is stored
返回:
-1, if the key is not found, the value after incrementing otherwise

decr

public long decr(java.lang.String key,
                 long inc)
Decrement the value at the specified key by passed in value, and then return it.

参数:
key - key where the data is stored
inc - how much to increment by
返回:
-1, if the key is not found, the value after incrementing otherwise

decr

public long decr(java.lang.String key,
                 long inc,
                 java.lang.Integer hashCode)
Decrement the value at the specified key by the specified increment, and then return it.

参数:
key - key where the data is stored
inc - how much to increment by
hashCode - if not null, then the int hashcode to use
返回:
-1, if the key is not found, the value after incrementing otherwise

get

public java.lang.Object get(java.lang.String key)
Retrieve a key from the server, using a specific hash. If the data was compressed or serialized when compressed, it will automatically
be decompressed or serialized, as appropriate. (Inclusive or)

Non-serialized data will be returned as a string, so explicit conversion to
numeric types will be necessary, if desired

参数:
key - key where data is stored
返回:
the object that was previously stored, or null if it was not previously stored

get

public java.lang.Object get(java.lang.String key,
                            java.lang.Integer hashCode)
Retrieve a key from the server, using a specific hash. If the data was compressed or serialized when compressed, it will automatically
be decompressed or serialized, as appropriate. (Inclusive or)

Non-serialized data will be returned as a string, so explicit conversion to
numeric types will be necessary, if desired

参数:
key - key where data is stored
hashCode - if not null, then the int hashcode to use
返回:
the object that was previously stored, or null if it was not previously stored

get

public java.lang.Object get(java.lang.String key,
                            java.lang.Integer hashCode,
                            boolean asString)
Retrieve a key from the server, using a specific hash. If the data was compressed or serialized when compressed, it will automatically
be decompressed or serialized, as appropriate. (Inclusive or)

Non-serialized data will be returned as a string, so explicit conversion to
numeric types will be necessary, if desired

参数:
key - key where data is stored
hashCode - if not null, then the int hashcode to use
asString - if true, then return string val
返回:
the object that was previously stored, or null if it was not previously stored

getMultiArray

public java.lang.Object[] getMultiArray(java.lang.String[] keys)
Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(), since it
is more efficient.

参数:
keys - String array of keys to retrieve
返回:
Object array ordered in same order as key array containing results

getMultiArray

public java.lang.Object[] getMultiArray(java.lang.String[] keys,
                                        java.lang.Integer[] hashCodes)
Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(), since it
is more efficient.

参数:
keys - String array of keys to retrieve
hashCodes - if not null, then the Integer array of hashCodes
返回:
Object array ordered in same order as key array containing results

getMultiArray

public java.lang.Object[] getMultiArray(java.lang.String[] keys,
                                        java.lang.Integer[] hashCodes,
                                        boolean asString)
Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(), since it
is more efficient.

参数:
keys - String array of keys to retrieve
hashCodes - if not null, then the Integer array of hashCodes
asString - if true, retrieve string vals
返回:
Object array ordered in same order as key array containing results

getMulti

public java.util.Map<java.lang.String,java.lang.Object> getMulti(java.lang.String[] keys)
Retrieve multiple objects from the memcache. This is recommended over repeated calls to get(), since it
is more efficient.

参数:
keys - String array of keys to retrieve
返回:
a hashmap with entries for each key is found by the server, keys that are not found are not entered into the hashmap, but attempting to retrieve them from the hashmap gives you null.

getMulti

public java.util.Map<java.lang.String,java.lang.Object> getMulti(java.lang.String[] keys,
                                                                 java.lang.Integer[] hashCodes)
Retrieve multiple keys from the memcache. This is recommended over repeated calls to get(), since it
is more efficient.

参数:
keys - keys to retrieve
hashCodes - if not null, then the Integer array of hashCodes
返回:
a hashmap with entries for each key is found by the server, keys that are not found are not entered into the hashmap, but attempting to retrieve them from the hashmap gives you null.

getMulti

public java.util.Map<java.lang.String,java.lang.Object> getMulti(java.lang.String[] keys,
                                                                 java.lang.Integer[] hashCodes,
                                                                 boolean asString)
Retrieve multiple keys from the memcache. This is recommended over repeated calls to get(), since it
is more efficient.

参数:
keys - keys to retrieve
hashCodes - if not null, then the Integer array of hashCodes
asString - if true then retrieve using String val
返回:
a hashmap with entries for each key is found by the server, keys that are not found are not entered into the hashmap, but attempting to retrieve them from the hashmap gives you null.

flushAll

public boolean flushAll()
Invalidates the entire cache. Will return true only if succeeds in clearing all servers.

返回:
success true/false

flushAll

public boolean flushAll(java.lang.String[] servers)
Invalidates the entire cache. Will return true only if succeeds in clearing all servers. If pass in null, then will try to flush all servers.

参数:
servers - optional array of host(s) to flush (host:port)
返回:
success true/false

stats

public java.util.Map stats()
Retrieves stats for all servers. Returns a map keyed on the servername. The value is another map which contains stats with stat name as key and value as value.

返回:
Stats map

stats

public java.util.Map stats(java.lang.String[] servers)
Retrieves stats for passed in servers (or all servers). Returns a map keyed on the servername. The value is another map which contains stats with stat name as key and value as value.

参数:
servers - string array of servers to retrieve stats from, or all if this is null
返回:
Stats map

statsItems

public java.util.Map statsItems()
Retrieves stats items for all servers. Returns a map keyed on the servername. The value is another map which contains item stats with itemname:number:field as key and value as value.

返回:
Stats map

statsItems

public java.util.Map statsItems(java.lang.String[] servers)
Retrieves stats for passed in servers (or all servers). Returns a map keyed on the servername. The value is another map which contains item stats with itemname:number:field as key and value as value.

参数:
servers - string array of servers to retrieve stats from, or all if this is null
返回:
Stats map

statsSlabs

public java.util.Map statsSlabs()
Retrieves stats items for all servers. Returns a map keyed on the servername. The value is another map which contains slabs stats with slabnumber:field as key and value as value.

返回:
Stats map

statsSlabs

public java.util.Map statsSlabs(java.lang.String[] servers)
Retrieves stats for passed in servers (or all servers). Returns a map keyed on the servername. The value is another map which contains slabs stats with slabnumber:field as key and value as value.

参数:
servers - string array of servers to retrieve stats from, or all if this is null
返回:
Stats map

statsCacheDump

public java.util.Map statsCacheDump(int slabNumber,
                                    int limit)
Retrieves items cachedump for all servers. Returns a map keyed on the servername. The value is another map which contains cachedump stats with the cachekey as key and byte size and unix timestamp as value.

参数:
slabNumber - the item number of the cache dump
返回:
Stats map

statsCacheDump

public java.util.Map statsCacheDump(java.lang.String[] servers,
                                    int slabNumber,
                                    int limit)
Retrieves stats for passed in servers (or all servers). Returns a map keyed on the servername. The value is another map which contains cachedump stats with the cachekey as key and byte size and unix timestamp as value.

参数:
servers - string array of servers to retrieve stats from, or all if this is null
slabNumber - the item number of the cache dump
返回:
Stats map


Copyright © 2009 . All Rights Reserved.