Package net.rubyeye.xmemcached
Interface MemcachedClient
- All Known Implementing Classes:
AWSElasticCacheClient
,XMemcachedClient
public interface MemcachedClient
The memcached client's interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Default connect timeout,1 minutesstatic final int
With java nio,there is only one connection to a memcached.In a high concurrent enviroment,you may want to pool memcached clients.But a xmemcached client has to start a reactor thread and some thread pools,if you create too many clients,the cost is very large.static final long
Default heal session interval in milliseconds.static final int
Default max queued noreply operations number.It is calcuated dynamically based on your jvm maximum memory.static final int
Maximum number of timeout exception for close connection.static final long
Default operation timeout,if the operation is not returned in 5 second,throw TimeoutException.static final int
Default thread number for reading nio's receive buffer and dispatch commands.Recommend users to set it equal or less to the memcached server's number on linux platform,keep default on windows.Default is 0.static final int
Default session idle timeout,if session is idle,xmemcached will do a heartbeat action to check if connection is alive.static final int
Default session read buffer size,16kstatic final boolean
Default TCP keeplive option,which is truestatic final boolean
Disable nagle algorithm by defaultstatic final int
Default socket's receive buffer size,16kstatic final int
Default socket's send buffer size,8kstatic final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
<T> boolean
add
(String key, int exp, T value, Transcoder<T> transcoder) <T> boolean
add
(String key, int exp, T value, Transcoder<T> transcoder, long timeout) Add key-value item to memcached, success only when the key is not exists in memcached.void
Add many memcached servers.You can call this method through JMX or programvoid
Aadd a memcached server,the thread call this method will be blocked until the connecting operations completed(success or fail)void
add a memcached server to MemcachedClientvoid
addServer
(InetSocketAddress inetSocketAddress) Add a memcached server,the thread call this method will be blocked until the connecting operations completed(success or fail)void
addServer
(InetSocketAddress inetSocketAddress, int weight) void
addStateListener
(MemcachedClientStateListener listener) Add a memcached client listenervoid
addWithNoReply
(String key, int exp, Object value) Add key-value item to memcached, success only when the key is not exists in memcached.This method doesn't wait for reply.<T> void
addWithNoReply
(String key, int exp, T value, Transcoder<T> transcoder) boolean
boolean
Append value to key's data item,this method will wait for replyvoid
appendWithNoReply
(String key, Object value) Append value to key's data item,this method doesn't wait for reply.void
set current namespace for following operations with memcached client.It must be ended withendWithNamespace()
method.For example:boolean
boolean
<T> boolean
cas
(String key, int exp, CASOperation<T> operation) <T> boolean
cas
(String key, int exp, CASOperation<T> operation, Transcoder<T> transcoder) Cas is a check and set operation which means "store this data but only if no one else has updated since I last fetched it."<T> boolean
cas
(String key, int exp, GetsResponse<T> getsReponse, CASOperation<T> operation) <T> boolean
cas
(String key, int exp, GetsResponse<T> getsReponse, CASOperation<T> operation, Transcoder<T> transcoder) cas is a check and set operation which means "store this data but only if no one else has updated since I last fetched it."<T> boolean
cas
(String key, int exp, T value, Transcoder<T> transcoder, long cas) <T> boolean
cas
(String key, int exp, T value, Transcoder<T> transcoder, long timeout, long cas) Cas is a check and set operation which means "store this data but only if no one else has updated since I last fetched it."<T> boolean
cas
(String key, CASOperation<T> operation) <T> boolean
cas
(String key, GetsResponse<T> getsResponse, CASOperation<T> operation) <T> void
casWithNoReply
(String key, int exp, CASOperation<T> operation) <T> void
casWithNoReply
(String key, int exp, GetsResponse<T> getsReponse, CASOperation<T> operation) cas noreply<T> void
casWithNoReply
(String key, CASOperation<T> operation) <T> void
casWithNoReply
(String key, GetsResponse<T> getsResponse, CASOperation<T> operation) long
"decr" are used to change data for some item in-place, decrementing it.long
long
"decr" are used to change data for some item in-place, decrementing it.long
"incr" are used to change data for some item in-place, incrementing it.void
decrWithNoReply
(String key, long delta) "decr" are used to change data for some item in-place, decrementing it.boolean
boolean
Deprecated.boolean
Delete key's date item from memcachedboolean
Delete key's date item from memcached only if its cas value is the same as what was read.void
deleteWithNoReply
(String key) void
deleteWithNoReply
(String key, int time) Deprecated.void
Remove current namespace set for this memcached client.It must begin withbeginWithNamespace(String)
method.void
flushAll()
Make All connected memcached's data item invalidvoid
flushAll
(int exptime, long timeout) void
flushAll
(long timeout) Make All connected memcached's data item invalidvoid
Deprecated.void
flushAll
(InetSocketAddress address) Invalidate all existing items immediatelyvoid
flushAll
(InetSocketAddress address, long timeout) void
flushAll
(InetSocketAddress address, long timeout, int exptime) void
void
flushAllWithNoReply
(int exptime) void
flushAllWithNoReply
(InetSocketAddress address) void
flushAllWithNoReply
(InetSocketAddress address, int exptime) <T> T
<T> T
<T> T
get
(String key, long timeout, Transcoder<T> transcoder) Get value by key<T> T
get
(String key, Transcoder<T> transcoder) get
(Collection<String> keyCollections) get
(Collection<String> keyCollections, long timeout) get
(Collection<String> keyCollections, long opTimeout, Transcoder<T> transcoder) Bulk get itemsget
(Collection<String> keyCollections, Transcoder<T> transcoder) <T> T
getAndTouch
(String key, int newExp) Get item and set a new expiration time for it,using default opTimeout<T> T
getAndTouch
(String key, int newExp, long opTimeout) Get item and set a new expiration time for itreturn current all auth infoRetruns the AuthInfo for all server strings (hostname:port)Returns available memcached servers list.Deprecated.return the session managerlong
Get the connect timeoutgetCounter
(String key) Get counter for key,and if the key's value is not set,then set it with 0.getCounter
(String key, long initialValue) Get counter for key,and if the key's value is not set,then set it with initial value.long
Return the default heal session interval in millisecondsgetKeyIterator
(InetSocketAddress address) Deprecated.memcached 1.6.x will remove cachedump stats command,so this method will be removed in the futuregetName()
Return the cache instance namelong
get operation timeout settingReturns reconnecting task queue,the queue is thread-safe and 'weakly consistent',but maybe you should not modify it at all.<T> GetsResponse
<T> <T> GetsResponse
<T> <T> GetsResponse
<T> gets
(String key, long timeout, Transcoder<T> transcoder) Just like get,But it return a GetsResponse,include cas value for cas update.<T> GetsResponse
<T> gets
(String key, Transcoder transcoder) <T> Map
<String, GetsResponse<T>> gets
(Collection<String> keyCollections) <T> Map
<String, GetsResponse<T>> gets
(Collection<String> keyCollections, long timeout) <T> Map
<String, GetsResponse<T>> gets
(Collection<String> keyCollections, long opTime, Transcoder<T> transcoder) Bulk gets items<T> Map
<String, GetsResponse<T>> gets
(Collection<String> keyCollections, Transcoder<T> transcoder) Get current server list.You can call this method through JMX or programGet all current state listenersgetStats()
getStats
(long timeout) Get stats from all memcached serversgetStatsByItem
(String itemName) Get special item stats.getStatsByItem
(String itemName, long timeout) int
Returns maximum number of timeout exception for closing connection.return default transcoder,default is SerializingTranscoderGet all connected memcached servers's version.getVersions
(long timeout) long
"incr" are used to change data for some item in-place, incrementing it.long
long
"incr" are used to change data for some item in-place, incrementing it.long
"incr" are used to change data for some item in-place, incrementing it.void
incrWithNoReply
(String key, long delta) "incr" are used to change data for some item in-place, incrementing it.void
Invalidate all namespace under the namespace using the default operation timeout.void
invalidateNamespace
(String ns, long opTimeout) Invalidate all items under the namespace.boolean
Returns if client is in failure mode.boolean
boolean
boolean
boolean
Prepend value to key's data item in memcached.This method doesn't wait for reply.void
prependWithNoReply
(String key, Object value) Prepend value to key's data item in memcached.This method doesn't wait for reply.void
removeServer
(String hostList) Remove many memcached servervoid
removeServer
(InetSocketAddress address) Remove memcached server with the exact given address.void
Remove a memcached client listenerboolean
boolean
<T> boolean
replace
(String key, int exp, T value, Transcoder<T> transcoder) <T> boolean
replace
(String key, int exp, T value, Transcoder<T> transcoder, long timeout) Replace the key's data item in memcached,success only when the key's data item is exists in memcached.This method will wait for reply from server.void
replaceWithNoReply
(String key, int exp, Object value) Replace the key's data item in memcached,success only when the key's data item is exists in memcached.This method doesn't wait for reply from server.<T> void
replaceWithNoReply
(String key, int exp, T value, Transcoder<T> transcoder) boolean
boolean
<T> boolean
set
(String key, int exp, T value, Transcoder<T> transcoder) <T> boolean
set
(String key, int exp, T value, Transcoder<T> transcoder, long timeout) Store key-value item to memcachedvoid
Configure auth infovoid
setBufferAllocator
(BufferAllocator bufferAllocator) Deprecated.void
setConnectionPoolSize
(int poolSize) In a high concurrent enviroment,you may want to pool memcached clients.But a xmemcached client has to start a reactor thread and some thread pools,if you create too many clients,the cost is very large.void
setConnectTimeout
(long connectTimeout) Set the connect timeout,default is 1 minutesvoid
setEnableHealSession
(boolean enableHealSession) If the memcached dump or network error cause connection closed,xmemcached would try to heal the connection.You can disable this behaviour by using this method:
client.setEnableHealSession(false);
The default value is true.void
setEnableHeartBeat
(boolean enableHeartBeat) Whether to enable heart beatvoid
setFailureMode
(boolean failureMode) Configure wheather to set client in failure mode.If set it to true,that means you want to configure client in failure mode.void
setHealSessionInterval
(long healConnectionInterval) If the memcached dump or network error cause connection closed,xmemcached would try to heal the connection.The interval between reconnections is 2 seconds by default.void
setKeyProvider
(KeyProvider keyProvider) Set a key provider for pre-processing keys before sending them to memcached.void
setLoggingLevelVerbosity
(InetSocketAddress address, int level) Set the verbosity level of the memcached's logging output.This method will wait for reply.void
setLoggingLevelVerbosityWithNoReply
(InetSocketAddress address, int level) Set the verbosity level of the memcached's logging output.This method doesn't wait for reply from servervoid
setMergeFactor
(int mergeFactor) Set the merge factor,this factor determins how many 'get' commands would be merge to one multi-get command.default is 150void
Set cache instance namevoid
setOpTimeout
(long opTimeout) set operation timeout,default is one second.void
setOptimizeGet
(boolean optimizeGet) Enable/Disable merge many get commands to one multi-get command.true is to enable it,false is to disable it.Default is true.Recommend users to enable it.void
setOptimizeMergeBuffer
(boolean optimizeMergeBuffer) Enable/Disable merge many command's buffers to one big buffer fit socket's send buffer size.Default is true.Recommend true.void
setPrimitiveAsString
(boolean primitiveAsString) Store all primitive type as string,defualt is false.void
setSanitizeKeys
(boolean sanitizeKey) Enables/disables sanitizing keys by URLEncoding.void
setTimeoutExceptionThreshold
(int timeoutExceptionThreshold) Set maximum number of timeout exception for closing connection.You can set it to be a large value to disable this feature.void
setTranscoder
(Transcoder transcoder) set transcodervoid
setWithNoReply
(String key, int exp, Object value) Store key-value item to memcached,doesn't wait for reply<T> void
setWithNoReply
(String key, int exp, T value, Transcoder<T> transcoder) void
shutdown()
stats
(InetSocketAddress address) stats
(InetSocketAddress address, long timeout) �ョ��瑰������emcached server缁��淇℃�boolean
Set a new expiration time for an existing item,using default opTimeout second.boolean
Set a new expiration time for an existing item<T> T
withNamespace
(String ns, MemcachedClientCallable<T> callable) With the namespae to do something with current memcached client.All operations with memcached client done in callable will be under the namespace.
-
Field Details
-
DEFAULT_READ_THREAD_COUNT
static final int DEFAULT_READ_THREAD_COUNTDefault thread number for reading nio's receive buffer and dispatch commands.Recommend users to set it equal or less to the memcached server's number on linux platform,keep default on windows.Default is 0.- See Also:
-
DEFAULT_TCP_KEEPLIVE
static final boolean DEFAULT_TCP_KEEPLIVEDefault TCP keeplive option,which is true- See Also:
-
DEFAULT_CONNECT_TIMEOUT
static final int DEFAULT_CONNECT_TIMEOUTDefault connect timeout,1 minutes- See Also:
-
DEFAULT_TCP_SEND_BUFF_SIZE
static final int DEFAULT_TCP_SEND_BUFF_SIZEDefault socket's send buffer size,8k- See Also:
-
DEFAULT_TCP_NO_DELAY
static final boolean DEFAULT_TCP_NO_DELAYDisable nagle algorithm by default- See Also:
-
DEFAULT_SESSION_READ_BUFF_SIZE
static final int DEFAULT_SESSION_READ_BUFF_SIZEDefault session read buffer size,16k- See Also:
-
DEFAULT_TCP_RECV_BUFF_SIZE
static final int DEFAULT_TCP_RECV_BUFF_SIZEDefault socket's receive buffer size,16k- See Also:
-
DEFAULT_OP_TIMEOUT
static final long DEFAULT_OP_TIMEOUTDefault operation timeout,if the operation is not returned in 5 second,throw TimeoutException.- See Also:
-
DEFAULT_CONNECTION_POOL_SIZE
static final int DEFAULT_CONNECTION_POOL_SIZEWith java nio,there is only one connection to a memcached.In a high concurrent enviroment,you may want to pool memcached clients.But a xmemcached client has to start a reactor thread and some thread pools,if you create too many clients,the cost is very large. Xmemcached supports connection pool instreadof client pool.you can create more connections to one or more memcached servers,and these connections share the same reactor and thread pools,it will reduce the cost of system.Default pool size is 1.- See Also:
-
DEFAULT_SESSION_IDLE_TIMEOUT
static final int DEFAULT_SESSION_IDLE_TIMEOUTDefault session idle timeout,if session is idle,xmemcached will do a heartbeat action to check if connection is alive.- See Also:
-
DEFAULT_HEAL_SESSION_INTERVAL
static final long DEFAULT_HEAL_SESSION_INTERVALDefault heal session interval in milliseconds.- See Also:
-
MAX_QUEUED_NOPS
static final int MAX_QUEUED_NOPS- See Also:
-
DYNAMIC_MAX_QUEUED_NOPS
static final int DYNAMIC_MAX_QUEUED_NOPS -
DEFAULT_MAX_QUEUED_NOPS
static final int DEFAULT_MAX_QUEUED_NOPSDefault max queued noreply operations number.It is calcuated dynamically based on your jvm maximum memory.- Since:
- 1.3.8
-
DEFAULT_MAX_TIMEOUTEXCEPTION_THRESHOLD
static final int DEFAULT_MAX_TIMEOUTEXCEPTION_THRESHOLDMaximum number of timeout exception for close connection.- Since:
- 1.4.0
- See Also:
-
-
Method Details
-
setMergeFactor
void setMergeFactor(int mergeFactor) Set the merge factor,this factor determins how many 'get' commands would be merge to one multi-get command.default is 150- Parameters:
mergeFactor
-
-
getConnectTimeout
long getConnectTimeout()Get the connect timeout -
setConnectTimeout
void setConnectTimeout(long connectTimeout) Set the connect timeout,default is 1 minutes- Parameters:
connectTimeout
-
-
getConnector
Connector getConnector()return the session manager- Returns:
-
setOptimizeGet
void setOptimizeGet(boolean optimizeGet) Enable/Disable merge many get commands to one multi-get command.true is to enable it,false is to disable it.Default is true.Recommend users to enable it.- Parameters:
optimizeGet
-
-
setOptimizeMergeBuffer
void setOptimizeMergeBuffer(boolean optimizeMergeBuffer) Enable/Disable merge many command's buffers to one big buffer fit socket's send buffer size.Default is true.Recommend true.- Parameters:
optimizeMergeBuffer
-
-
isShutdown
boolean isShutdown()- Returns:
-
addServer
Aadd a memcached server,the thread call this method will be blocked until the connecting operations completed(success or fail)- Parameters:
server
- host stringport
- port number- Throws:
IOException
-
addServer
Add a memcached server,the thread call this method will be blocked until the connecting operations completed(success or fail)- Parameters:
inetSocketAddress
- memcached server's socket address- Throws:
IOException
-
addServer
Add many memcached servers.You can call this method through JMX or program- Parameters:
host
- String like [host1]:[port1] [host2]:[port2] ...- Throws:
IOException
-
getServersDescription
Get current server list.You can call this method through JMX or program -
removeServer
Remove many memcached server- Parameters:
host
- String like [host1]:[port1] [host2]:[port2] ...
-
removeServer
Remove memcached server with the exact given address.- Parameters:
address
- Resolved server address
-
setBufferAllocator
Deprecated.Set the nio's ByteBuffer Allocator,use SimpleBufferAllocator by default.- Parameters:
bufferAllocator
-
-
get
<T> T get(String key, long timeout, Transcoder<T> transcoder) throws TimeoutException, InterruptedException, MemcachedException Get value by key- Type Parameters:
T
-- Parameters:
key
- Keytimeout
- Operation timeout,if the method is not returned in this time,throw TimeoutExceptiontranscoder
- The value's transcoder- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
get
<T> T get(String key, long timeout) throws TimeoutException, InterruptedException, MemcachedException -
get
<T> T get(String key, Transcoder<T> transcoder) throws TimeoutException, InterruptedException, MemcachedException -
get
-
gets
<T> GetsResponse<T> gets(String key, long timeout, Transcoder<T> transcoder) throws TimeoutException, InterruptedException, MemcachedException Just like get,But it return a GetsResponse,include cas value for cas update.- Type Parameters:
T
-- Parameters:
key
- keytimeout
- operation timeouttranscoder
-- Returns:
- GetsResponse
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
gets
<T> GetsResponse<T> gets(String key) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
gets
<T> GetsResponse<T> gets(String key, long timeout) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-timeout
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
gets
<T> GetsResponse<T> gets(String key, Transcoder transcoder) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-transcoder
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
get
<T> Map<String,T> get(Collection<String> keyCollections, long opTimeout, Transcoder<T> transcoder) throws TimeoutException, InterruptedException, MemcachedException Bulk get items- Type Parameters:
T
-- Parameters:
keyCollections
- key collectionopTimeout
- opTimeouttranscoder
- Value transcoder- Returns:
- Exists items map
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
get
<T> Map<String,T> get(Collection<String> keyCollections, Transcoder<T> transcoder) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
keyCollections
-transcoder
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
get
<T> Map<String,T> get(Collection<String> keyCollections) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
keyCollections
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
get
<T> Map<String,T> get(Collection<String> keyCollections, long timeout) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
keyCollections
-timeout
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
gets
<T> Map<String,GetsResponse<T>> gets(Collection<String> keyCollections, long opTime, Transcoder<T> transcoder) throws TimeoutException, InterruptedException, MemcachedException Bulk gets items- Type Parameters:
T
-- Parameters:
keyCollections
- key collectionopTime
- Operation timeouttranscoder
- Value transcoder- Returns:
- Exists GetsResponse map
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
gets
<T> Map<String,GetsResponse<T>> gets(Collection<String> keyCollections) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
keyCollections
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
gets
<T> Map<String,GetsResponse<T>> gets(Collection<String> keyCollections, long timeout) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
keyCollections
-timeout
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
gets
<T> Map<String,GetsResponse<T>> gets(Collection<String> keyCollections, Transcoder<T> transcoder) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
keyCollections
-transcoder
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
set
<T> boolean set(String key, int exp, T value, Transcoder<T> transcoder, long timeout) throws TimeoutException, InterruptedException, MemcachedException Store key-value item to memcached- Type Parameters:
T
-- Parameters:
key
- stored keyexp
- An expiration time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.value
- stored datatranscoder
- transocdertimeout
- operation timeout,in milliseconds- Returns:
- boolean result
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
set
boolean set(String key, int exp, Object value) throws TimeoutException, InterruptedException, MemcachedException - Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
set
boolean set(String key, int exp, Object value, long timeout) throws TimeoutException, InterruptedException, MemcachedException - Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
set
<T> boolean set(String key, int exp, T value, Transcoder<T> transcoder) throws TimeoutException, InterruptedException, MemcachedException - Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
setWithNoReply
void setWithNoReply(String key, int exp, Object value) throws InterruptedException, MemcachedException Store key-value item to memcached,doesn't wait for reply- Type Parameters:
T
-- Parameters:
key
- stored keyexp
- An expiration time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.value
- stored datatranscoder
- transocder- Throws:
TimeoutException
InterruptedException
MemcachedException
-
setWithNoReply
<T> void setWithNoReply(String key, int exp, T value, Transcoder<T> transcoder) throws InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-exp
-value
-transcoder
-- Throws:
InterruptedException
MemcachedException
- See Also:
-
add
<T> boolean add(String key, int exp, T value, Transcoder<T> transcoder, long timeout) throws TimeoutException, InterruptedException, MemcachedException Add key-value item to memcached, success only when the key is not exists in memcached.- Type Parameters:
T
-- Parameters:
key
-exp
- An expiration time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.value
-transcoder
-timeout
-- Returns:
- boolean result
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
add
boolean add(String key, int exp, Object value) throws TimeoutException, InterruptedException, MemcachedException - Parameters:
key
-exp
-value
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
add
boolean add(String key, int exp, Object value, long timeout) throws TimeoutException, InterruptedException, MemcachedException - Parameters:
key
-exp
-value
-timeout
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
add
<T> boolean add(String key, int exp, T value, Transcoder<T> transcoder) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-exp
-value
-transcoder
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
addWithNoReply
void addWithNoReply(String key, int exp, Object value) throws InterruptedException, MemcachedException Add key-value item to memcached, success only when the key is not exists in memcached.This method doesn't wait for reply.- Type Parameters:
T
-- Parameters:
key
-exp
- An expiration time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.value
-transcoder
-- Throws:
TimeoutException
InterruptedException
MemcachedException
-
addWithNoReply
<T> void addWithNoReply(String key, int exp, T value, Transcoder<T> transcoder) throws InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-exp
-value
-transcoder
-- Throws:
InterruptedException
MemcachedException
- See Also:
-
replace
<T> boolean replace(String key, int exp, T value, Transcoder<T> transcoder, long timeout) throws TimeoutException, InterruptedException, MemcachedException Replace the key's data item in memcached,success only when the key's data item is exists in memcached.This method will wait for reply from server.- Type Parameters:
T
-- Parameters:
key
-exp
- An expiration time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.value
-transcoder
-timeout
-- Returns:
- boolean result
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
replace
boolean replace(String key, int exp, Object value) throws TimeoutException, InterruptedException, MemcachedException - Parameters:
key
-exp
-value
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
replace
boolean replace(String key, int exp, Object value, long timeout) throws TimeoutException, InterruptedException, MemcachedException - Parameters:
key
-exp
-value
-timeout
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
replace
<T> boolean replace(String key, int exp, T value, Transcoder<T> transcoder) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-exp
-value
-transcoder
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
replaceWithNoReply
void replaceWithNoReply(String key, int exp, Object value) throws InterruptedException, MemcachedException Replace the key's data item in memcached,success only when the key's data item is exists in memcached.This method doesn't wait for reply from server.- Type Parameters:
T
-- Parameters:
key
-exp
- An expiration time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.value
-transcoder
-- Throws:
TimeoutException
InterruptedException
MemcachedException
-
replaceWithNoReply
<T> void replaceWithNoReply(String key, int exp, T value, Transcoder<T> transcoder) throws InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-exp
-value
-transcoder
-- Throws:
InterruptedException
MemcachedException
- See Also:
-
append
boolean append(String key, Object value) throws TimeoutException, InterruptedException, MemcachedException - Parameters:
key
-value
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
append
boolean append(String key, Object value, long timeout) throws TimeoutException, InterruptedException, MemcachedException Append value to key's data item,this method will wait for reply- Parameters:
key
-value
-timeout
-- Returns:
- boolean result
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
appendWithNoReply
Append value to key's data item,this method doesn't wait for reply.- Parameters:
key
-value
-- Throws:
TimeoutException
InterruptedException
MemcachedException
-
prepend
boolean prepend(String key, Object value) throws TimeoutException, InterruptedException, MemcachedException - Parameters:
key
-value
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
prepend
boolean prepend(String key, Object value, long timeout) throws TimeoutException, InterruptedException, MemcachedException Prepend value to key's data item in memcached.This method doesn't wait for reply.- Parameters:
key
-value
-- Returns:
- boolean result
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
prependWithNoReply
Prepend value to key's data item in memcached.This method doesn't wait for reply.- Parameters:
key
-value
-- Throws:
TimeoutException
InterruptedException
MemcachedException
-
cas
boolean cas(String key, int exp, Object value, long cas) throws TimeoutException, InterruptedException, MemcachedException - Parameters:
key
-exp
-value
-cas
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
cas
<T> boolean cas(String key, int exp, T value, Transcoder<T> transcoder, long timeout, long cas) throws TimeoutException, InterruptedException, MemcachedException Cas is a check and set operation which means "store this data but only if no one else has updated since I last fetched it."- Type Parameters:
T
-- Parameters:
key
-exp
- An expiration time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.value
-transcoder
-timeout
-cas
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
cas
boolean cas(String key, int exp, Object value, long timeout, long cas) throws TimeoutException, InterruptedException, MemcachedException - Parameters:
key
-exp
-value
-timeout
-cas
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
cas
<T> boolean cas(String key, int exp, T value, Transcoder<T> transcoder, long cas) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-exp
-value
-transcoder
-cas
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
cas
<T> boolean cas(String key, int exp, CASOperation<T> operation, Transcoder<T> transcoder) throws TimeoutException, InterruptedException, MemcachedException Cas is a check and set operation which means "store this data but only if no one else has updated since I last fetched it."- Type Parameters:
T
-- Parameters:
key
-exp
- An expiration time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.operation
- CASOperationtranscoder
- object transcoder- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
cas
<T> boolean cas(String key, int exp, GetsResponse<T> getsReponse, CASOperation<T> operation, Transcoder<T> transcoder) throws TimeoutException, InterruptedException, MemcachedException cas is a check and set operation which means "store this data but only if no one else has updated since I last fetched it."- Type Parameters:
T
-- Parameters:
key
-exp
- An expiration time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.getsReponse
- gets method's resultoperation
- CASOperationtranscoder
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
cas
<T> boolean cas(String key, int exp, GetsResponse<T> getsReponse, CASOperation<T> operation) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-exp
-getsReponse
-operation
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
cas
<T> boolean cas(String key, GetsResponse<T> getsResponse, CASOperation<T> operation) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-getsResponse
-operation
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
cas
<T> boolean cas(String key, int exp, CASOperation<T> operation) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-exp
-operation
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
cas
<T> boolean cas(String key, CASOperation<T> operation) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-operation
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
casWithNoReply
<T> void casWithNoReply(String key, GetsResponse<T> getsResponse, CASOperation<T> operation) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-getsResponse
-operation
-- Throws:
TimeoutException
InterruptedException
MemcachedException
-
casWithNoReply
<T> void casWithNoReply(String key, int exp, GetsResponse<T> getsReponse, CASOperation<T> operation) throws TimeoutException, InterruptedException, MemcachedException cas noreply- Type Parameters:
T
-- Parameters:
key
-exp
-getsReponse
-operation
-- Throws:
TimeoutException
InterruptedException
MemcachedException
-
casWithNoReply
<T> void casWithNoReply(String key, int exp, CASOperation<T> operation) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-exp
-operation
-- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
casWithNoReply
<T> void casWithNoReply(String key, CASOperation<T> operation) throws TimeoutException, InterruptedException, MemcachedException - Type Parameters:
T
-- Parameters:
key
-operation
-- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
delete
@Deprecated boolean delete(String key, int time) throws TimeoutException, InterruptedException, MemcachedException Deprecated.Delete key's data item from memcached.It it is not exists,return false. time is 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. Note: This method is deprecated,because memcached 1.4.0 remove the optional argument "time".You can still use this method on old version,but is not recommended.- Parameters:
key
-time
-- Throws:
InterruptedException
MemcachedException
TimeoutException
-
delete
boolean delete(String key, long opTimeout) throws TimeoutException, InterruptedException, MemcachedException Delete key's date item from memcached- Parameters:
key
-opTimeout
- Operation timeout- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- Since:
- 1.3.2
-
delete
boolean delete(String key, long cas, long opTimeout) throws TimeoutException, InterruptedException, MemcachedException Delete key's date item from memcached only if its cas value is the same as what was read.- Parameters:
key
-opTimeout
- Operation timeout- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- Since:
- 1.3.2
-
touch
boolean touch(String key, int exp, long opTimeout) throws TimeoutException, InterruptedException, MemcachedException Set a new expiration time for an existing item- Parameters:
key
- item's keyexp
- New expiration time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.opTimeout
- operation timeout- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
touch
boolean touch(String key, int exp) throws TimeoutException, InterruptedException, MemcachedException Set a new expiration time for an existing item,using default opTimeout second.- Parameters:
key
- item's keyexp
- New expiration time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
getAndTouch
<T> T getAndTouch(String key, int newExp, long opTimeout) throws TimeoutException, InterruptedException, MemcachedException Get item and set a new expiration time for it- Type Parameters:
T
-- Parameters:
key
- item's keynewExp
- New expiration time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.opTimeout
- operation timeout- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
getAndTouch
<T> T getAndTouch(String key, int newExp) throws TimeoutException, InterruptedException, MemcachedException Get item and set a new expiration time for it,using default opTimeout- Type Parameters:
T
-- Parameters:
key
-newExp
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
getVersions
Map<InetSocketAddress,String> getVersions() throws TimeoutException, InterruptedException, MemcachedExceptionGet all connected memcached servers's version.- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
incr
"incr" are used to change data for some item in-place, incrementing it. The data for the item is treated as decimal representation of a 64-bit unsigned integer. If the current data value does not conform to such a representation, the commands behave as if the value were 0. Also, the item must already exist for incr to work; these commands won't pretend that a non-existent key exists with value 0; instead, it will fail.This method doesn't wait for reply.- Parameters:
key
-num
-- Returns:
- the new value of the item's data, after the increment operation was carried out.
- Throws:
InterruptedException
MemcachedException
TimeoutException
-
incr
long incr(String key, long delta, long initValue) throws TimeoutException, InterruptedException, MemcachedException -
incr
long incr(String key, long delta, long initValue, long timeout) throws TimeoutException, InterruptedException, MemcachedException "incr" are used to change data for some item in-place, incrementing it. The data for the item is treated as decimal representation of a 64-bit unsigned integer. If the current data value does not conform to such a representation, the commands behave as if the value were 0. Also, the item must already exist for incr to work; these commands won't pretend that a non-existent key exists with value 0; instead, it will fail.This method doesn't wait for reply.- Parameters:
key
- keyinitValue
- initValue if the data is not exists.timeout
- operation timeoutnum
- increment- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
decr
"decr" are used to change data for some item in-place, decrementing it. The data for the item is treated as decimal representation of a 64-bit unsigned integer. If the current data value does not conform to such a representation, the commands behave as if the value were 0. Also, the item must already exist for decr to work; these commands won't pretend that a non-existent key exists with value 0; instead, it will fail.This method doesn't wait for reply.- Parameters:
key
-num
-- Returns:
- the new value of the item's data, after the decrement operation was carried out.
- Throws:
InterruptedException
MemcachedException
TimeoutException
-
decr
long decr(String key, long delta, long initValue) throws TimeoutException, InterruptedException, MemcachedException - Parameters:
key
-initValue
-num
-- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
- See Also:
-
decr
long decr(String key, long delta, long initValue, long timeout) throws TimeoutException, InterruptedException, MemcachedException "decr" are used to change data for some item in-place, decrementing it. The data for the item is treated as decimal representation of a 64-bit unsigned integer. If the current data value does not conform to such a representation, the commands behave as if the value were 0. Also, the item must already exist for decr to work; these commands won't pretend that a non-existent key exists with value 0; instead, it will fail.This method doesn't wait for reply.- Parameters:
key
- The keyinitValue
- The initial value if the data is not exists.timeout
- Operation timeoutnum
- The increment- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
flushAll
Make All connected memcached's data item invalid -
flushAllWithNoReply
-
flushAll
Make All connected memcached's data item invalid- Parameters:
timeout
- operation timeout- Throws:
TimeoutException
InterruptedException
MemcachedException
-
flushAll
void flushAll(InetSocketAddress address) throws MemcachedException, InterruptedException, TimeoutException Invalidate all existing items immediately- Parameters:
address
- Target memcached servertimeout
- operation timeout- Throws:
TimeoutException
InterruptedException
MemcachedException
-
flushAllWithNoReply
-
flushAll
void flushAll(InetSocketAddress address, long timeout) throws MemcachedException, InterruptedException, TimeoutException -
flushAll
@Deprecated void flushAll(String host) throws TimeoutException, InterruptedException, MemcachedException Deprecated.This method is deprecated,please use flushAll(InetSocketAddress) instead.- Parameters:
host
-- Throws:
TimeoutException
InterruptedException
MemcachedException
-
stats
Map<String,String> stats(InetSocketAddress address) throws MemcachedException, InterruptedException, TimeoutException -
stats
Map<String,String> stats(InetSocketAddress address, long timeout) throws MemcachedException, InterruptedException, TimeoutException �ョ��瑰������emcached server缁��淇℃�- Parameters:
address
- ����板�timeout
- ���瓒��- Returns:
- Throws:
MemcachedException
InterruptedException
TimeoutException
-
getStats
Map<InetSocketAddress,Map<String, getStatsString>> (long timeout) throws MemcachedException, InterruptedException, TimeoutException Get stats from all memcached servers- Parameters:
timeout
-- Returns:
- server->item->value map
- Throws:
MemcachedException
InterruptedException
TimeoutException
-
getStats
Map<InetSocketAddress,Map<String, getStats() throws MemcachedException, InterruptedException, TimeoutExceptionString>> -
getStatsByItem
Map<InetSocketAddress,Map<String, getStatsByItemString>> (String itemName) throws MemcachedException, InterruptedException, TimeoutException Get special item stats. "stats items" for example- Parameters:
item
-- Returns:
- Throws:
MemcachedException
InterruptedException
TimeoutException
-
shutdown
- Throws:
IOException
-
delete
-
getTranscoder
Transcoder getTranscoder()return default transcoder,default is SerializingTranscoder- Returns:
-
setTranscoder
set transcoder- Parameters:
transcoder
-
-
getStatsByItem
Map<InetSocketAddress,Map<String, getStatsByItemString>> (String itemName, long timeout) throws MemcachedException, InterruptedException, TimeoutException -
getOpTimeout
long getOpTimeout()get operation timeout setting- Returns:
-
setOpTimeout
void setOpTimeout(long opTimeout) set operation timeout,default is one second.- Parameters:
opTimeout
-
-
getVersions
Map<InetSocketAddress,String> getVersions(long timeout) throws TimeoutException, InterruptedException, MemcachedException -
getAvaliableServers
Deprecated.Returns available memcached servers list.This method is drepcated,please use getAvailableServers instead.- Returns:
- See Also:
-
getAvailableServers
Collection<InetSocketAddress> getAvailableServers()Returns available memcached servers list.- Returns:
- A available server collection
-
addServer
add a memcached server to MemcachedClient- Parameters:
server
-port
-weight
-- Throws:
IOException
-
addServer
- Throws:
IOException
-
deleteWithNoReply
@Deprecated void deleteWithNoReply(String key, int time) throws InterruptedException, MemcachedException Deprecated.Delete key's data item from memcached.This method doesn't wait for reply. This method does not work on memcached 1.3 or later version.See i s s u e 3 Note: This method is deprecated,because memcached 1.4.0 remove the optional argument "time".You can still use this method on old version,but is not recommended.- Parameters:
key
-time
-- Throws:
InterruptedException
MemcachedException
-
deleteWithNoReply
-
incrWithNoReply
"incr" are used to change data for some item in-place, incrementing it. The data for the item is treated as decimal representation of a 64-bit unsigned integer. If the current data value does not conform to such a representation, the commands behave as if the value were 0. Also, the item must already exist for incr to work; these commands won't pretend that a non-existent key exists with value 0; instead, it will fail.This method doesn't wait for reply.- Parameters:
key
-num
-- Throws:
InterruptedException
MemcachedException
-
decrWithNoReply
"decr" are used to change data for some item in-place, decrementing it. The data for the item is treated as decimal representation of a 64-bit unsigned integer. If the current data value does not conform to such a representation, the commands behave as if the value were 0. Also, the item must already exist for decr to work; these commands won't pretend that a non-existent key exists with value 0; instead, it will fail.This method doesn't wait for reply.- Parameters:
key
-num
-- Throws:
InterruptedException
MemcachedException
-
setLoggingLevelVerbosity
void setLoggingLevelVerbosity(InetSocketAddress address, int level) throws TimeoutException, InterruptedException, MemcachedException Set the verbosity level of the memcached's logging output.This method will wait for reply.- Parameters:
address
-level
- logging level- Throws:
TimeoutException
InterruptedException
MemcachedException
-
setLoggingLevelVerbosityWithNoReply
void setLoggingLevelVerbosityWithNoReply(InetSocketAddress address, int level) throws InterruptedException, MemcachedException Set the verbosity level of the memcached's logging output.This method doesn't wait for reply from server- Parameters:
address
- memcached server addresslevel
- logging level- Throws:
InterruptedException
MemcachedException
-
addStateListener
Add a memcached client listener- Parameters:
listener
-
-
removeStateListener
Remove a memcached client listener- Parameters:
listener
-
-
getStateListeners
Collection<MemcachedClientStateListener> getStateListeners()Get all current state listeners- Returns:
-
flushAllWithNoReply
-
flushAll
void flushAll(int exptime, long timeout) throws TimeoutException, InterruptedException, MemcachedException -
flushAllWithNoReply
void flushAllWithNoReply(InetSocketAddress address, int exptime) throws MemcachedException, InterruptedException -
flushAll
void flushAll(InetSocketAddress address, long timeout, int exptime) throws MemcachedException, InterruptedException, TimeoutException -
setHealSessionInterval
void setHealSessionInterval(long healConnectionInterval) If the memcached dump or network error cause connection closed,xmemcached would try to heal the connection.The interval between reconnections is 2 seconds by default. You can change that value by this method.- Parameters:
healConnectionInterval
- MILLISECONDS
-
setEnableHealSession
void setEnableHealSession(boolean enableHealSession) If the memcached dump or network error cause connection closed,xmemcached would try to heal the connection.You can disable this behaviour by using this method:
client.setEnableHealSession(false);
The default value is true.- Parameters:
enableHealSession
-- Since:
- 1.3.9
-
getHealSessionInterval
long getHealSessionInterval()Return the default heal session interval in milliseconds- Returns:
-
getProtocol
Protocol getProtocol() -
setPrimitiveAsString
void setPrimitiveAsString(boolean primitiveAsString) Store all primitive type as string,defualt is false. -
setConnectionPoolSize
void setConnectionPoolSize(int poolSize) In a high concurrent enviroment,you may want to pool memcached clients.But a xmemcached client has to start a reactor thread and some thread pools,if you create too many clients,the cost is very large. Xmemcached supports connection pool instreadof client pool.you can create more connections to one or more memcached servers,and these connections share the same reactor and thread pools,it will reduce the cost of system.- Parameters:
poolSize
- pool size,default is one,every memcached has only one connection.
-
setEnableHeartBeat
void setEnableHeartBeat(boolean enableHeartBeat) Whether to enable heart beat- Parameters:
enableHeartBeat
- if true,then enable heartbeat,true by default
-
setSanitizeKeys
void setSanitizeKeys(boolean sanitizeKey) Enables/disables sanitizing keys by URLEncoding.- Parameters:
sanitizeKey
- if true, then URLEncode all keys
-
isSanitizeKeys
boolean isSanitizeKeys() -
getCounter
Get counter for key,and if the key's value is not set,then set it with 0.- Parameters:
key
-- Returns:
-
getCounter
Get counter for key,and if the key's value is not set,then set it with initial value.- Parameters:
key
-initialValue
-- Returns:
-
getKeyIterator
@Deprecated KeyIterator getKeyIterator(InetSocketAddress address) throws MemcachedException, InterruptedException, TimeoutException Deprecated.memcached 1.6.x will remove cachedump stats command,so this method will be removed in the futureGet key iterator for special memcached server.You must known that the iterator is a snapshot for memcached all keys,it is not real-time.The 'stats cachedump" has length limitation,so iterator could not visit all keys if you have many keys.Your application should not be dependent on this feature.- Parameters:
address
-- Returns:
- Throws:
MemcachedException
InterruptedException
TimeoutException
-
setAuthInfoMap
Configure auth info- Parameters:
map
- Auth info map,key is memcached server address,and value is the auth info for the key.
-
getAuthInfoMap
Map<InetSocketAddress,AuthInfo> getAuthInfoMap()return current all auth info- Returns:
- Auth info map,key is memcached server address,and value is the auth info for the key.
-
getAuthInfoStringMap
Retruns the AuthInfo for all server strings (hostname:port)- Returns:
- A map of AuthInfos for server strings (hostname:port)
-
decr
long decr(String key, long delta, long initValue, long timeout, int exp) throws TimeoutException, InterruptedException, MemcachedException "incr" are used to change data for some item in-place, incrementing it. The data for the item is treated as decimal representation of a 64-bit unsigned integer. If the current data value does not conform to such a representation, the commands behave as if the value were 0. Also, the item must already exist for incr to work; these commands won't pretend that a non-existent key exists with value 0; instead, it will fail.This method doesn't wait for reply.- Parameters:
key
-delta
-initValue
- the initial value to be added when value is not foundtimeout
-exp
- the initial vlaue expire time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
incr
long incr(String key, long delta, long initValue, long timeout, int exp) throws TimeoutException, InterruptedException, MemcachedException "incr" are used to change data for some item in-place, incrementing it. The data for the item is treated as decimal representation of a 64-bit unsigned integer. If the current data value does not conform to such a representation, the commands behave as if the value were 0. Also, the item must already exist for incr to work; these commands won't pretend that a non-existent key exists with value 0; instead, it will fail.This method doesn't wait for reply.- Parameters:
key
- keydelta
- increment deltainitValue
- the initial value to be added when value is not foundtimeout
- operation timeoutexp
- the initial vlaue expire time, in seconds. Can be up to 30 days. After 30 days, is treated as a unix timestamp of an exact date.- Returns:
- Throws:
TimeoutException
InterruptedException
MemcachedException
-
getName
String getName()Return the cache instance name- Returns:
-
setName
Set cache instance name- Parameters:
name
-
-
getReconnectRequestQueue
Queue<ReconnectRequest> getReconnectRequestQueue()Returns reconnecting task queue,the queue is thread-safe and 'weakly consistent',but maybe you should not modify it at all.- Returns:
- The reconnecting task queue,if the client has not been started,returns null.
-
setFailureMode
void setFailureMode(boolean failureMode) Configure wheather to set client in failure mode.If set it to true,that means you want to configure client in failure mode. Failure mode is that when a memcached server is down,it would not taken from the server list but marked as unavailable,and then further requests to this server will be transformed to standby node if configured or throw an exception until it comes back up.- Parameters:
failureMode
- true is to configure client in failure mode.
-
isFailureMode
boolean isFailureMode()Returns if client is in failure mode.- Returns:
-
setKeyProvider
Set a key provider for pre-processing keys before sending them to memcached.- Parameters:
keyProvider
-- Since:
- 1.3.8
-
getTimeoutExceptionThreshold
int getTimeoutExceptionThreshold()Returns maximum number of timeout exception for closing connection.- Returns:
-
setTimeoutExceptionThreshold
void setTimeoutExceptionThreshold(int timeoutExceptionThreshold) Set maximum number of timeout exception for closing connection.You can set it to be a large value to disable this feature.- Parameters:
timeoutExceptionThreshold
-- See Also:
-
invalidateNamespace
void invalidateNamespace(String ns) throws MemcachedException, InterruptedException, TimeoutException Invalidate all namespace under the namespace using the default operation timeout.- Parameters:
ns
- the namespace- Throws:
MemcachedException
InterruptedException
TimeoutException
- Since:
- 1.4.2
-
invalidateNamespace
void invalidateNamespace(String ns, long opTimeout) throws MemcachedException, InterruptedException, TimeoutException Invalidate all items under the namespace.- Parameters:
ns
- the namespaceopTimeout
- operation timeout in milliseconds.- Throws:
MemcachedException
InterruptedException
TimeoutException
- Since:
- 1.4.2
-
endWithNamespace
void endWithNamespace()Remove current namespace set for this memcached client.It must begin withbeginWithNamespace(String)
method.- See Also:
-
beginWithNamespace
set current namespace for following operations with memcached client.It must be ended withendWithNamespace()
method.For example:memcachedClient.beginWithNamespace(userId); try { memcachedClient.set("username", 0, username); memcachedClient.set("email", 0, email); } finally { memcachedClient.endWithNamespace(); }
- Parameters:
ns
-- See Also:
-
withNamespace
<T> T withNamespace(String ns, MemcachedClientCallable<T> callable) throws MemcachedException, InterruptedException, TimeoutException With the namespae to do something with current memcached client.All operations with memcached client done in callable will be under the namespace.beginWithNamespace(String)
andendWithNamespace()
will called around automatically. For example:memcachedClient.withNamespace(userId,new MemcachedClientCallable
{ public Void call(MemcachedClient client) throws MemcachedException, InterruptedException, TimeoutException{ client.set("username",0,username); client.set("email",0,email); return null; } }); //invalidate all items under the namespace. memcachedClient.invalidateNamespace(userId); - Parameters:
ns
-callable
-- Returns:
- Throws:
MemcachedException
InterruptedException
TimeoutException
- Since:
- 1.4.2
- See Also:
-