
Jedis jedis = jedisPool.getResource();
try {
while (true) {
String productCountString = jedis.get("product");
if (Integer.parseInt(productCountString) > 0) {
if (acquireLock(jedis, "abc")) {
int productCount = Integer.parseInt(jedis.get("product"));
System.out.println(String.format("%tT --- Get product: %s", new Date(), productCount));
// System.out.println(productCount);
jedis.decr("product");
releaseLock(jedis, "abc");
return "Success";
}
Thread.sleep(1000L);
} else {
return "Over";
}
}
} finally {
jedis.close();
}

@Override
public String set(final byte[] key, final byte[] value) {
return new JedisClusterCommand<String>(connectionHandler, maxRedirections) {
@Override
public String execute(Jedis connection) {
return connection.set(key, value);
}
}.runBinary(key);
}
@Override
public Jedis getConnection() {
// In antirez's redis-rb-cluster implementation,
// getRandomConnection always return valid connection (able to
// ping-pong)
// or exception if all connections are invalid List<JedisPool> pools = getShuffledNodesPool(); for (JedisPool pool : pools) {
Jedis jedis = null;
try {
jedis = pool.getResource(); if (jedis == null) {
continue;
} String result = jedis.ping(); if (result.equalsIgnoreCase("pong")) return jedis; pool.returnBrokenResource(jedis);
} catch (JedisConnectionException ex) {
if (jedis != null) {
pool.returnBrokenResource(jedis);
}
}
} throw new JedisConnectionException("no reachable node in cluster");
}
return runWithRetries(SafeEncoder.encode(keys[0]), this.redirections, false, false);
@Override
public Jedis getConnectionFromSlot(int slot) {
JedisPool connectionPool = cache.getSlotPool(slot);
if (connectionPool != null) {
// It can't guaranteed to get valid connection because of node
// assignment
return connectionPool.getResource();
} else {
return getConnection();
}
}
5974ed7dd81c112d9a2354a0a985995913b4702c 192.168.1.137:6389 master - 0 1468809898374 26 connected 0-5640
d08dc883ee4fcb90c4bb47992ee03e6474398324 192.168.1.137:6390 master - 0 1468809898875 25 connected 5641-11040
ffb4db4e1ced0f91ea66cd2335f7e4eadc29fd56 192.168.1.138:6390 slave 5974ed7dd81c112d9a2354a0a985995913b4702c 0 1468809899376 26 connected
c69b521a30336caf8bce078047cf9bb5f37363ee 192.168.1.137:6388 master - 0 1468809897873 28 connected 11041-16383
532e58842d001f8097fadc325bdb5541b788a360 192.168.1.138:6389 slave c69b521a30336caf8bce078047cf9bb5f37363ee 0 1468809899876 28 connected
aa52c7810e499d042e94e0aa4bc28c57a1da74e3 192.168.1.138:6388 myself,slave d08dc883ee4fcb90c4bb47992ee03e6474398324 0 0 19 connected
private T runWithRetries(byte[] key, int redirections, boolean tryRandomNode, boolean asking) {
if (redirections <= 0) {
throw new JedisClusterMaxRedirectionsException("Too many Cluster redirections?");
} Jedis connection = null;
try { if (asking) {
// TODO: Pipeline asking with the original command to make it
// faster....
connection = askConnection.get();
connection.asking(); // if asking success, reset asking flag
asking = false;
} else {
if (tryRandomNode) {
connection = connectionHandler.getConnection();
} else {
connection = connectionHandler.getConnectionFromSlot(JedisClusterCRC16.getSlot(key));
}
} return execute(connection);
} catch (JedisConnectionException jce) {
if (tryRandomNode) {
// maybe all connection is down
throw jce;
} // release current connection before recursion
releaseConnection(connection);
connection = null; // retry with random connection
return runWithRetries(key, redirections - 1, true, asking);
} catch (JedisRedirectionException jre) {
// if MOVED redirection occurred,
if (jre instanceof JedisMovedDataException) {
// it rebuilds cluster's slot cache
// recommended by Redis cluster specification
this.connectionHandler.renewSlotCache(connection);
} // release current connection before recursion or renewing
releaseConnection(connection);
connection = null; if (jre instanceof JedisAskDataException) {
asking = true;
askConnection.set(this.connectionHandler.getConnectionFromNode(jre.getTargetNode()));
} else if (jre instanceof JedisMovedDataException) {
} else {
throw new JedisClusterException(jre);
} return runWithRetries(key, redirections - 1, false, asking);
} finally {
releaseConnection(connection);
}
}
- 2016-06-04 00:02:51,911 [// - - ] ERROR xxx - Too many Cluster redirections?
redis.clients.jedis.exceptions.JedisClusterMaxRedirectionsException: Too many Cluster redirections?
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:97)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:131)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:152)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:131)
redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream.
at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:198)
at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
at redis.clients.jedis.Protocol.process(Protocol.java:141)
at redis.clients.jedis.Protocol.read(Protocol.java:205)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297)
at redis.clients.jedis.Connection.getBinaryBulkReply(Connection.java:216)
at redis.clients.jedis.Connection.getBulkReply(Connection.java:205)
at redis.clients.jedis.Jedis.get(Jedis.java:101)
at redis.clients.jedis.JedisCluster$3.execute(JedisCluster.java:79)
at redis.clients.jedis.JedisCluster$3.execute(JedisCluster.java:76)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:119)
at redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:30)
at redis.clients.jedis.JedisCluster.get(JedisCluster.java:81)
at redis.RedisClusterTest.main(RedisClusterTest.java:30)
jce = {[email protected]} "redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream."
detailMessage = "Unexpected end of stream."
cause = {[email protected]} "redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream."
stackTrace = {java.lang.StackTraceElement[0]@1017}
suppressedExceptions = {[email protected]} size = 0
1) "client-output-buffer-limit"
2) "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"
jre = {[email protected]} "redis.clients.jedis.exceptions.JedisMovedDataException: MOVED 8855 192.168.1.137:6390"
targetNode = {[email protected]} "192.168.1.137:6390"
slot = 8855
detailMessage = "MOVED 8855 192.168.1.137:6390"
cause = {[email protected]} "redis.clients.jedis.exceptions.JedisMovedDataException: MOVED 8855 192.168.1.137:6390"
stackTrace = {java.lang.StackTraceElement[0]@1978}
suppressedExceptions = {[email protected]} size = 0
4851:S 18 Jul 11:05:38.005 * Asynchronous AOF fsync is taking too long (disk is busy?). Writing the AOF buffer without waiting for fsync to complete, this may slow down Redis.
JedisCluster The application of Apache Commons Pool More articles on object pooling Technology
- Object pooling Technology org.apache.commons.pool
Using object pooling properly , It can effectively reduce the consumption of object generation and initialization , Improve the efficiency of the system .Jakarta Commons Pool Component provides a complete framework for object pooling , And a number of object pool implementations with their own characteristics , Sure ...
- Apache Commons Pool A story
Apache Commons Pool A story Recently I came across a problem in my work due to commons-pool Problems caused by improper use of , After learning the correct posture , Write this simple story , Help you understand Apache Commons ...
- Pooling - Apache Commons Pool
For those that take a long time to create , Or objects with more resources , For example, network connection , Resources like threads , Pooling is often used to manage these objects , In order to achieve the purpose of improving performance . For example, database connection pool (c3p0, dbcp), java Thread pool of Execu ...
- apache commons pool
apache commons Under the pool Among them borrowObject Function source code shows the process of generating available objects : If stack There are free objects in , be pop object , Activate the object (activate function ), Verify the object (v ...
- Apache Commons Pool A story project
Apache Commons Pool A story Recently I came across a problem in my work due to commons-pool Problems caused by improper use of , After learning the correct posture , Write this simple story , Help you understand Apache Commons ...
- Tomcat Development web Project Report Illegal access: this web application instance has been stopped already. Could not load [org.apache.commons.pool.impl.CursorableLinkedList$Cursor]. error
Development Java web project , stay tomcat The following error will be reported after operation : Illegal access: this web application instance has been stopped already ...
- NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
error :Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/pool/impl ...
- Spring + Tomcat Initiate error reporting java.lang.ClassNotFoundException: org.apache.commons.pool.impl.GenericObjectPool
Error is as follows : -- ::,-[TS] INFO http-- org.springframework.beans.factory.support.DefaultListableBeanFactory - ...
- org/apache/commons/pool/impl/GenericObjectPool Solutions to exceptions
org/apache/commons/pool/impl/GenericObjectPool Solutions to exceptions webwork+spring+hibernate Integration of framework , One start Tomcat The server is out ...
Random recommendation
- With Amazon S3 and RapidMiner Applying machine learning to text mining
This mining typically uses machine learning technology , Such as the clustering , classification , Association rules , And predictive modeling . These technologies reveal meaning and relationships in potential content . Text mining is applied to such fields as competitive intelligence , Life science , Customer voice , Media and Publishing , Laws and taxes , Law enforcement , Emotional analysis and trends ...
- 【POJ】3133 Manhattan Wiring
http://poj.org/problem?id=3133 The question :n×m The grid of , Yes 2 individual 2,2 individual 3, They don't overlap . There are obstacles 1. Now please 2 To 2 The path and 3 To 3 The shortest length of disjoint paths of -2.(2<=n, ...
- alter database open resetlogs
Use resetlogs Options , The current log serial number will be (log sequence number) Reset to 1, And discard all log information . You need to use resetlogs Options : In incomplete recovery ( Media recovery ): Using backup ...
- Unity 3D Call camera to capture photos videotape
1, To call a camera, first turn on the camera driver , If the user allows it, you can use . 2, Definition WebCamTexture The variable used to capture a single photo . 3, Continuous capture must be thread enabled . Implementation code : using UnityEngine; ...
- python3, Interprocess communication
This article comes from python 3.5 Version of the official document multiprocessing Module provides two methods for interprocess communication : 1. Process queue queue The Queue class is a near clone o ...
- IT Wheel series ( Two )——mvc API Automatic generation of instruction documents ——Swagger Use ( One )
This article mainly introduces how to use Swashbuckle Plug in VS 2013 Automatically generate MVC API Documentation of the project . To better illustrate swagger Generate , Let's start with a new empty one API Project start . First step . newly build mvc api ...
- Navicat Premium 12.1.12.0 Installation and activation
Reprinted from :Navicat Premium 12.1.12.0 Installation and activation author : My memory will never die link :https://www.jianshu.com/p/5f693b4c9468 navicat12112 ...
- Elasticsearch Search APIs
Elasticsearch Search APIs By: Give the guest QQ:1033553122 1. Search for 1 Search for... In all types of a single index 1 Searches for... In the specified type of a single index 1 Search multiple specified indexes for 1 ...
- BizTalk Server How to deal with big news
What's big news ? Unfortunately , The answer to this question is not directly related to a specific message size , binding , It's up to you Microsoft The specific bottleneck of BizTalk Server System . The problems associated with big messages can be divided into the following categories : Out of memory error ...
- e1084. Catch errors and exceptions
All errors and exceptions extend from Throwable. By catching Throwable, it is possible to handle all ...