Package com.danga.MemCached
Class MemCachedClient
java.lang.Object
com.danga.MemCached.MemCachedClient
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.
The add and replace methods do the same, but with a slight difference.
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.
- add -- will store the object only if the server does not have an entry for this key
- replace -- will store the object only if the server already has an entry for this key
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();
- Version:
- 1.5
- Author:
- greg whalin <greg@meetup.com>, Richard 'toast' Russo <russor@msoe.edu>, Kevin Burton <burton@peerfear.org>, Robert Watts <robert@wattsit.co.uk>, Vin Chawla <vin@tivo.com>
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private ClassLoader
private static final String
private static final int
private boolean
private long
private String
private static final String
private static final String
private static final String
private ErrorHandler
static final int
static final int
private static final String
private static org.apache.log4j.Logger
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
private static final String
private static final String
private static final String
private SockIOPool
private String
private boolean
private boolean
private static final String
private static final String
private static final String
private static final String
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of MemCachedClient.MemCachedClient
(ClassLoader classLoader) Creates a new instance of MemCacheClient but acceptes a passed in ClassLoader.MemCachedClient
(ClassLoader classLoader, ErrorHandler errorHandler) Creates a new instance of MemCacheClient but acceptes a passed in ClassLoader and a passed in ErrorHandler.MemCachedClient
(ClassLoader classLoader, ErrorHandler errorHandler, String poolName) Creates a new instance of MemCacheClient but acceptes a passed in ClassLoader, ErrorHandler, and SockIOPool name.MemCachedClient
(String poolName) Creates a new instance of MemCachedClient accepting a passed in pool name. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds data to the server; only the key and the value are specified.boolean
Adds data to the server; the key, value, and an optional hashcode are passed in.boolean
Adds data to the server; the key, value, and an expiration time are specified.boolean
Adds data to the server; the key, value, and an expiration time are specified.long
Thread safe way to initialize and decrement a counter.long
Thread safe way to initialize and decrement a counter.long
Thread safe way to initialize and decrement a counter.long
Thread safe way to initialize and increment a counter.long
Thread safe way to initialize and increment a counter.long
Thread safe way to initialize and increment a counter.long
Decrement the value at the specified key by 1, and then return it.long
Decrement the value at the specified key by passed in value, and then return it.long
Decrement the value at the specified key by the specified increment, and then return it.boolean
Deletes an object from cache given cache key.boolean
Deletes an object from cache given cache key, a delete time, and an optional hashcode.boolean
Deletes an object from cache given cache key and expiration date.boolean
flushAll()
Invalidates the entire cache.boolean
Invalidates the entire cache.Retrieve a key from the server, using a specific hash.Retrieve a key from the server, using a specific hash.Retrieve a key from the server, using a specific hash.long
getCounter
(String key) Returns value in counter at given key as long.long
getCounter
(String key, Integer hashCode) Returns value in counter at given key as long.Retrieve multiple objects from the memcache.Retrieve multiple keys from the memcache.Retrieve multiple keys from the memcache.Object[]
getMultiArray
(String[] keys) Retrieve multiple objects from the memcache.Object[]
getMultiArray
(String[] keys, Integer[] hashCodes) Retrieve multiple objects from the memcache.Object[]
getMultiArray
(String[] keys, Integer[] hashCodes, boolean asString) Retrieve multiple objects from the memcache.long
Increment the value at the specified key by 1, and then return it.long
Increment the value at the specified key by passed in val.long
Increment the value at the specified key by the specified increment, and then return it.private long
Increments/decrements the value at the specified key by inc.private void
init()
Initializes client object to defaults.boolean
Checks to see if key exists in cache.private void
loadMulti
(LineInputStream input, Map<String, Object> hm, boolean asString) This method loads the data from cache into a Map.boolean
Updates data on the server; only the key and the value are specified.boolean
Updates data on the server; only the key and the value and an optional hash are specified.boolean
Updates data on the server; the key, value, and an expiration time are specified.boolean
Updates data on the server; the key, value, and an expiration time are specified.private String
sanitizeKey
(String key) boolean
Stores data on the server; only the key and the value are specified.boolean
Stores data on the server; only the key and the value are specified.boolean
Stores data on the server; the key, value, and an expiration time are specified.boolean
Stores data on the server; the key, value, and an expiration time are specified.private boolean
Stores data to cache.void
setClassLoader
(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
(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.stats()
Retrieves stats for all servers.Retrieves stats for passed in servers (or all servers).private Map
statsCacheDump
(int slabNumber, int limit) Retrieves items cachedump for all servers.statsCacheDump
(String[] servers, int slabNumber, int limit) Retrieves stats for passed in servers (or all servers).Retrieves stats items for all servers.statsItems
(String[] servers) Retrieves stats for passed in servers (or all servers).Retrieves stats items for all servers.statsSlabs
(String[] servers) Retrieves stats for passed in servers (or all servers).boolean
storeCounter
(String key, long counter) Store a counter to memcached given a keyboolean
storeCounter
(String key, Long counter) Store a counter to memcached given a keyboolean
storeCounter
(String key, Long counter, Integer hashCode) Store a counter to memcached given a key
-
Field Details
-
log
private static org.apache.log4j.Logger log -
VALUE
- See Also:
-
STATS
- See Also:
-
ITEM
- See Also:
-
DELETED
- See Also:
-
NOTFOUND
- See Also:
-
STORED
- See Also:
-
NOTSTORED
- See Also:
-
OK
- See Also:
-
END
- See Also:
-
ERROR
- See Also:
-
CLIENT_ERROR
- See Also:
-
SERVER_ERROR
- See Also:
-
B_END
private static final byte[] B_END -
B_NOTFOUND
private static final byte[] B_NOTFOUND -
B_DELETED
private static final byte[] B_DELETED -
B_STORED
private static final byte[] B_STORED -
COMPRESS_THRESH
private static final int COMPRESS_THRESH- See Also:
-
MARKER_BYTE
public static final int MARKER_BYTE- See Also:
-
MARKER_BOOLEAN
public static final int MARKER_BOOLEAN- See Also:
-
MARKER_INTEGER
public static final int MARKER_INTEGER- See Also:
-
MARKER_LONG
public static final int MARKER_LONG- See Also:
-
MARKER_CHARACTER
public static final int MARKER_CHARACTER- See Also:
-
MARKER_STRING
public static final int MARKER_STRING- See Also:
-
MARKER_STRINGBUFFER
public static final int MARKER_STRINGBUFFER- See Also:
-
MARKER_FLOAT
public static final int MARKER_FLOAT- See Also:
-
MARKER_SHORT
public static final int MARKER_SHORT- See Also:
-
MARKER_DOUBLE
public static final int MARKER_DOUBLE- See Also:
-
MARKER_DATE
public static final int MARKER_DATE- See Also:
-
MARKER_STRINGBUILDER
public static final int MARKER_STRINGBUILDER- See Also:
-
MARKER_BYTEARR
public static final int MARKER_BYTEARR- See Also:
-
F_COMPRESSED
public static final int F_COMPRESSED- See Also:
-
F_SERIALIZED
public static final int F_SERIALIZED- See Also:
-
sanitizeKeys
private boolean sanitizeKeys -
primitiveAsString
private boolean primitiveAsString -
compressEnable
private boolean compressEnable -
compressThreshold
private long compressThreshold -
defaultEncoding
-
pool
-
poolName
-
classLoader
-
errorHandler
-
-
Constructor Details
-
MemCachedClient
public MemCachedClient()Creates a new instance of MemCachedClient. -
MemCachedClient
Creates a new instance of MemCachedClient accepting a passed in pool name.- Parameters:
poolName
- name of SockIOPool
-
MemCachedClient
Creates a new instance of MemCacheClient but acceptes a passed in ClassLoader.- Parameters:
classLoader
- ClassLoader object.
-
MemCachedClient
Creates a new instance of MemCacheClient but acceptes a passed in ClassLoader and a passed in ErrorHandler.- Parameters:
classLoader
- ClassLoader object.errorHandler
- ErrorHandler object.
-
MemCachedClient
Creates a new instance of MemCacheClient but acceptes a passed in ClassLoader, ErrorHandler, and SockIOPool name.- Parameters:
classLoader
- ClassLoader object.errorHandler
- ErrorHandler object.poolName
- SockIOPool name
-
-
Method Details
-
init
private void init()Initializes client object to defaults. This enables compression and sets compression threshhold to 15 KB. -
setClassLoader
Sets an optional ClassLoader to be used for serialization.- Parameters:
classLoader
-
-
setErrorHandler
Sets an optional ErrorHandler.- Parameters:
errorHandler
-
-
setSanitizeKeys
public void setSanitizeKeys(boolean sanitizeKeys) Enables/disables sanitizing keys by URLEncoding.- Parameters:
sanitizeKeys
- if true, then URLEncode all keys
-
setPrimitiveAsString
public void setPrimitiveAsString(boolean primitiveAsString) Enables storing primitive types as their String values.- Parameters:
primitiveAsString
- if true, then store all primitives as their string value.
-
setDefaultEncoding
Sets default String encoding when storing primitives as Strings. Default is UTF-8.- Parameters:
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.- Parameters:
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.- Parameters:
compressThreshold
- required length of data to consider compression
-
keyExists
Checks to see if key exists in cache.- Parameters:
key
- the key to look for- Returns:
- true if key found in cache, false if not (or if cache is down)
-
delete
Deletes an object from cache given cache key.- Parameters:
key
- the key to be removed- Returns:
true
, if the data was deleted successfully
-
delete
Deletes an object from cache given cache key and expiration date.- Parameters:
key
- the key to be removedexpiry
- when to expire the record.- Returns:
true
, if the data was deleted successfully
-
delete
Deletes an object from cache given cache key, a delete time, and an optional hashcode. The item is immediately made non retrievable.
Keep in mindadd
andreplace
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.- Parameters:
key
- the key to be removedhashCode
- if not null, then the int hashcode to useexpiry
- when to expire the record.- Returns:
true
, if the data was deleted successfully
-
set
Stores data on the server; only the key and the value are specified.- Parameters:
key
- key to store data undervalue
- value to store- Returns:
- true, if the data was successfully stored
-
set
Stores data on the server; only the key and the value are specified.- Parameters:
key
- key to store data undervalue
- value to storehashCode
- if not null, then the int hashcode to use- Returns:
- true, if the data was successfully stored
-
set
Stores data on the server; the key, value, and an expiration time are specified.- Parameters:
key
- key to store data undervalue
- value to storeexpiry
- when to expire the record- Returns:
- true, if the data was successfully stored
-
set
Stores data on the server; the key, value, and an expiration time are specified.- Parameters:
key
- key to store data undervalue
- value to storeexpiry
- when to expire the recordhashCode
- if not null, then the int hashcode to use- Returns:
- true, if the data was successfully stored
-
add
Adds data to the server; only the key and the value are specified.- Parameters:
key
- key to store data undervalue
- value to store- Returns:
- true, if the data was successfully stored
-
add
Adds data to the server; the key, value, and an optional hashcode are passed in.- Parameters:
key
- key to store data undervalue
- value to storehashCode
- if not null, then the int hashcode to use- Returns:
- true, if the data was successfully stored
-
add
Adds data to the server; the key, value, and an expiration time are specified.- Parameters:
key
- key to store data undervalue
- value to storeexpiry
- when to expire the record- Returns:
- true, if the data was successfully stored
-
add
Adds data to the server; the key, value, and an expiration time are specified.- Parameters:
key
- key to store data undervalue
- value to storeexpiry
- when to expire the recordhashCode
- if not null, then the int hashcode to use- Returns:
- true, if the data was successfully stored
-
replace
Updates data on the server; only the key and the value are specified.- Parameters:
key
- key to store data undervalue
- value to store- Returns:
- true, if the data was successfully stored
-
replace
Updates data on the server; only the key and the value and an optional hash are specified.- Parameters:
key
- key to store data undervalue
- value to storehashCode
- if not null, then the int hashcode to use- Returns:
- true, if the data was successfully stored
-
replace
Updates data on the server; the key, value, and an expiration time are specified.- Parameters:
key
- key to store data undervalue
- value to storeexpiry
- when to expire the record- Returns:
- true, if the data was successfully stored
-
replace
Updates data on the server; the key, value, and an expiration time are specified.- Parameters:
key
- key to store data undervalue
- value to storeexpiry
- when to expire the recordhashCode
- if not null, then the int hashcode to use- Returns:
- true, if the data was successfully stored
-
set
private boolean set(String cmdname, String key, Object value, Date expiry, Integer hashCode, boolean asString) Stores data to cache. If data does not already exist for this key on the server, or if the key is being
deleted, the specified value will not be stored.
The server will automatically delete the value when the expiration time has been reached.
If compression is enabled, and the data is longer than the compression threshold
the data will be stored in compressed form.
As of the current release, all objects stored will use java serialization.- Parameters:
cmdname
- action to take (set, add, replace)key
- key to store cache undervalue
- object to cacheexpiry
- expirationhashCode
- if not null, then the int hashcode to useasString
- store this object as a string?- Returns:
- true/false indicating success
-
storeCounter
Store a counter to memcached given a key- Parameters:
key
- cache keycounter
- number to store- Returns:
- true/false indicating success
-
storeCounter
Store a counter to memcached given a key- Parameters:
key
- cache keycounter
- number to store- Returns:
- true/false indicating success
-
storeCounter
Store a counter to memcached given a key- Parameters:
key
- cache keycounter
- number to storehashCode
- if not null, then the int hashcode to use- Returns:
- true/false indicating success
-
getCounter
Returns value in counter at given key as long.- Parameters:
key
- cache ket- Returns:
- counter value or -1 if not found
-
getCounter
Returns value in counter at given key as long.- Parameters:
key
- cache kethashCode
- if not null, then the int hashcode to use- Returns:
- counter value or -1 if not found
-
addOrIncr
Thread safe way to initialize and increment a counter.- Parameters:
key
- key where the data is stored- Returns:
- value of incrementer
-
addOrIncr
Thread safe way to initialize and increment a counter.- Parameters:
key
- key where the data is storedinc
- value to set or increment by- Returns:
- value of incrementer
-
addOrIncr
Thread safe way to initialize and increment a counter.- Parameters:
key
- key where the data is storedinc
- value to set or increment byhashCode
- if not null, then the int hashcode to use- Returns:
- value of incrementer
-
addOrDecr
Thread safe way to initialize and decrement a counter.- Parameters:
key
- key where the data is stored- Returns:
- value of incrementer
-
addOrDecr
Thread safe way to initialize and decrement a counter.- Parameters:
key
- key where the data is storedinc
- value to set or increment by- Returns:
- value of incrementer
-
addOrDecr
Thread safe way to initialize and decrement a counter.- Parameters:
key
- key where the data is storedinc
- value to set or increment byhashCode
- if not null, then the int hashcode to use- Returns:
- value of incrementer
-
incr
Increment the value at the specified key by 1, and then return it.- Parameters:
key
- key where the data is stored- Returns:
- -1, if the key is not found, the value after incrementing otherwise
-
incr
Increment the value at the specified key by passed in val.- Parameters:
key
- key where the data is storedinc
- how much to increment by- Returns:
- -1, if the key is not found, the value after incrementing otherwise
-
incr
Increment the value at the specified key by the specified increment, and then return it.- Parameters:
key
- key where the data is storedinc
- how much to increment byhashCode
- if not null, then the int hashcode to use- Returns:
- -1, if the key is not found, the value after incrementing otherwise
-
decr
Decrement the value at the specified key by 1, and then return it.- Parameters:
key
- key where the data is stored- Returns:
- -1, if the key is not found, the value after incrementing otherwise
-
decr
Decrement the value at the specified key by passed in value, and then return it.- Parameters:
key
- key where the data is storedinc
- how much to increment by- Returns:
- -1, if the key is not found, the value after incrementing otherwise
-
decr
Decrement the value at the specified key by the specified increment, and then return it.- Parameters:
key
- key where the data is storedinc
- how much to increment byhashCode
- if not null, then the int hashcode to use- Returns:
- -1, if the key is not found, the value after incrementing otherwise
-
incrdecr
Increments/decrements the value at the specified key by inc. Note that the server uses a 32-bit unsigned integer, and checks for
underflow. In the event of underflow, the result will be zero. Because
Java lacks unsigned types, the value is returned as a 64-bit integer.
The server will only decrement a value if it already exists;
if a value is not found, -1 will be returned.- Parameters:
cmdname
- increment/decrementkey
- cache keyinc
- amount to incr or decrhashCode
- if not null, then the int hashcode to use- Returns:
- new value or -1 if not exist
-
get
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- Parameters:
key
- key where data is stored- Returns:
- the object that was previously stored, or null if it was not previously stored
-
get
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- Parameters:
key
- key where data is storedhashCode
- if not null, then the int hashcode to use- Returns:
- the object that was previously stored, or null if it was not previously stored
-
get
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- Parameters:
key
- key where data is storedhashCode
- if not null, then the int hashcode to useasString
- if true, then return string val- Returns:
- the object that was previously stored, or null if it was not previously stored
-
getMultiArray
Retrieve multiple objects from the memcache. This is recommended over repeated calls toget()
, since it
is more efficient.- Parameters:
keys
- String array of keys to retrieve- Returns:
- Object array ordered in same order as key array containing results
-
getMultiArray
Retrieve multiple objects from the memcache. This is recommended over repeated calls toget()
, since it
is more efficient.- Parameters:
keys
- String array of keys to retrievehashCodes
- if not null, then the Integer array of hashCodes- Returns:
- Object array ordered in same order as key array containing results
-
getMultiArray
Retrieve multiple objects from the memcache. This is recommended over repeated calls toget()
, since it
is more efficient.- Parameters:
keys
- String array of keys to retrievehashCodes
- if not null, then the Integer array of hashCodesasString
- if true, retrieve string vals- Returns:
- Object array ordered in same order as key array containing results
-
getMulti
Retrieve multiple objects from the memcache. This is recommended over repeated calls toget()
, since it
is more efficient.- Parameters:
keys
- String array of keys to retrieve- Returns:
- 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
Retrieve multiple keys from the memcache. This is recommended over repeated calls toget()
, since it
is more efficient.- Parameters:
keys
- keys to retrievehashCodes
- if not null, then the Integer array of hashCodes- Returns:
- 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
Retrieve multiple keys from the memcache. This is recommended over repeated calls toget()
, since it
is more efficient.- Parameters:
keys
- keys to retrievehashCodes
- if not null, then the Integer array of hashCodesasString
- if true then retrieve using String val- Returns:
- 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.
-
loadMulti
private void loadMulti(LineInputStream input, Map<String, Object> hm, boolean asString) throws IOExceptionThis method loads the data from cache into a Map. Pass a SockIO object which is ready to receive data and a HashMap
to store the results.- Parameters:
sock
- socket waiting to pass back datahm
- hashmap to store data intoasString
- if true, and if we are using NativehHandler, return string val- Throws:
IOException
- if io exception happens while reading from socket
-
sanitizeKey
- Throws:
UnsupportedEncodingException
-
flushAll
public boolean flushAll()Invalidates the entire cache. Will return true only if succeeds in clearing all servers.- Returns:
- success true/false
-
flushAll
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.- Parameters:
servers
- optional array of host(s) to flush (host:port)- Returns:
- success true/false
-
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.- Returns:
- Stats map
-
stats
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.- Parameters:
servers
- string array of servers to retrieve stats from, or all if this is null- Returns:
- Stats 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.- Returns:
- Stats map
-
statsItems
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.- Parameters:
servers
- string array of servers to retrieve stats from, or all if this is null- Returns:
- Stats 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.- Returns:
- Stats map
-
statsSlabs
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.- Parameters:
servers
- string array of servers to retrieve stats from, or all if this is null- Returns:
- Stats map
-
statsCacheDump
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.- Parameters:
slabNumber
- the item number of the cache dump- Returns:
- Stats map
-
statsCacheDump
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.- Parameters:
servers
- string array of servers to retrieve stats from, or all if this is nullslabNumber
- the item number of the cache dump- Returns:
- Stats map
-
stats
-