redis.clients.jedis.exceptions.JedisClusterException Java Examples
The following examples show how to use
redis.clients.jedis.exceptions.JedisClusterException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JedisClusterFacade.java From HttpSessionReplacer with MIT License | 6 votes |
/** * Implements move of Redis elements where oldkey and newkey don't fall in same slot. The concrete implementation * depends on the type of data at oldkey. * * @param oldkey * @param newkey * @return */ private String renameToDifferentSlots(byte[] oldkey, byte[] newkey) { String type = jedisCluster.type(oldkey); String result; switch (type) { case "string": result = renameString(oldkey, newkey); break; case "hash": result = renameHash(oldkey, newkey); break; case "set": result = renameSet(oldkey, newkey); break; case "list": result = renameList(oldkey, newkey); break; case "zrange": result = renameZRange(oldkey, newkey); break; default: throw new JedisClusterException("Unknown element type " + type + " for key " + encode(oldkey)); } return result; }
Example #2
Source File: Protocol.java From cachecloud with Apache License 2.0 | 6 votes |
private static void processError(final RedisInputStream is) { String message = is.readLine(); // TODO: I'm not sure if this is the best way to do this. // Maybe Read only first 5 bytes instead? if (message.startsWith(MOVED_RESPONSE)) { String[] movedInfo = parseTargetHostAndSlot(message); throw new JedisMovedDataException(message, new HostAndPort(movedInfo[1], Integer.valueOf(movedInfo[2])), Integer.valueOf(movedInfo[0])); } else if (message.startsWith(ASK_RESPONSE)) { String[] askInfo = parseTargetHostAndSlot(message); throw new JedisAskDataException(message, new HostAndPort(askInfo[1], Integer.valueOf(askInfo[2])), Integer.valueOf(askInfo[0])); } else if (message.startsWith(CLUSTERDOWN_RESPONSE)) { throw new JedisClusterException(message); } throw new JedisDataException(message); }
Example #3
Source File: JedisClusterCommand.java From cachecloud with Apache License 2.0 | 6 votes |
public T run(int keyCount, String... keys) { if (keys == null || keys.length == 0) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); } // For multiple keys, only execute if they all share the // same connection slot. if (keys.length > 1) { int slot = JedisClusterCRC16.getSlot(keys[0]); for (int i = 1; i < keyCount; i++) { int nextSlot = JedisClusterCRC16.getSlot(keys[i]); if (slot != nextSlot) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster " + "because keys have different slots."); } } } return runWithRetries(SafeEncoder.encode(keys[0]), this.redirections, false, false); }
Example #4
Source File: JedisClusterCommand.java From cachecloud with Apache License 2.0 | 6 votes |
public T runBinary(int keyCount, byte[]... keys) { if (keys == null || keys.length == 0) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); } // For multiple keys, only execute if they all share the // same connection slot. if (keys.length > 1) { int slot = JedisClusterCRC16.getSlot(keys[0]); for (int i = 1; i < keyCount; i++) { int nextSlot = JedisClusterCRC16.getSlot(keys[i]); if (slot != nextSlot) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster " + "because keys have different slots."); } } } return runWithRetries(keys[0], this.redirections, false, false); }
Example #5
Source File: JedisClusterCommand.java From cachecloud with Apache License 2.0 | 5 votes |
public T run(String key) { if (key == null) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); } return runWithRetries(SafeEncoder.encode(key), this.redirections, false, false); }
Example #6
Source File: JedisClusterCommand.java From cachecloud with Apache License 2.0 | 5 votes |
public T runBinary(byte[] key) { if (key == null) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); } return runWithRetries(key, this.redirections, false, false); }
Example #7
Source File: ClusterScriptingCommandsTest.java From cachecloud with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test(expected = JedisClusterException.class) public void testJedisClusterException() { String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2],ARGV[3]}"; List<String> keys = new ArrayList<String>(); keys.add("key1"); keys.add("key2"); List<String> args = new ArrayList<String>(); args.add("first"); args.add("second"); args.add("third"); jedisCluster.eval(script, keys, args); }
Example #8
Source File: ClusterScriptingCommandsTest.java From cachecloud with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test(expected = JedisClusterException.class) public void testJedisClusterException2() { byte[] script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2],ARGV[3]}".getBytes(); List<byte[]> keys = new ArrayList<byte[]>(); keys.add("key1".getBytes()); keys.add("key2".getBytes()); List<byte[]> args = new ArrayList<byte[]>(); args.add("first".getBytes()); args.add("second".getBytes()); args.add("third".getBytes()); jedisCluster.eval(script, keys, args); }
Example #9
Source File: JedisClusterCommand.java From cachecloud with Apache License 2.0 | 4 votes |
private T runWithRetries(byte[] key, int redirections, boolean tryRandomNode, boolean asking) { if (redirections <= 0) { JedisClusterMaxRedirectionsException exception = new JedisClusterMaxRedirectionsException("Too many Cluster redirections? key=" + SafeEncoder.encode(key)); //收集 UsefulDataCollector.collectException(exception, "", System.currentTimeMillis(), ClientExceptionType.REDIS_CLUSTER); throw exception; } 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); } }
Example #10
Source File: RedisClusterClientImpl.java From nano-framework with Apache License 2.0 | 4 votes |
@Override public List<Map<String, String>> info() { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
Example #11
Source File: RedisClusterClientImpl.java From nano-framework with Apache License 2.0 | 4 votes |
@Override public List<Map<String, String>> info(String section) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }