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); } else if (message.startsWith(BUSY_RESPONSE)) { throw new JedisBusyException(message); } else if (message.startsWith(NOSCRIPT_RESPONSE)) { throw new JedisNoScriptException(message); } throw new JedisDataException(message); }
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.maxAttempts, false, false); }
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.maxAttempts, false, false); }
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); }
/** * 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; }
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); }
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); }
/** * 处理Redis集群重定向"请求错误"响应。 * * @param is */ private static void processError(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); }
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.maxAttempts, false, false); }
public T runBinary(byte[] key) { if (key == null) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); } return runWithRetries(key, this.maxAttempts, false, false); }
@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); }
@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); }
public T run(String key) { if (key == null) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); } return runWithRetries(key, this.redirections, false, false); }
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); }
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); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster scheduled * to be removed on next major release */ @Deprecated @Override public String ping() { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster scheduled * to be removed on next major release */ @Deprecated @Override public String quit() { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster scheduled * to be removed on next major release */ @Deprecated @Override public String flushDB() { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster and Redis * Cluster only uses db index 0 scheduled to be removed on next * major release */ @Deprecated @Override public Long dbSize() { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster and Redis * Cluster only uses db index 0 scheduled to be removed on next * major release */ @Deprecated @Override public String select(int index) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster scheduled * to be removed on next major release */ @Deprecated @Override public String flushAll() { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster and Redis * Cluster doesn't support authorization scheduled to be removed on * next major release */ @Deprecated @Override public String auth(String password) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster scheduled * to be removed on next major release */ @Deprecated @Override public String save() { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster scheduled * to be removed on next major release */ @Deprecated @Override public String bgsave() { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster scheduled * to be removed on next major release */ @Deprecated @Override public String bgrewriteaof() { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster scheduled * to be removed on next major release */ @Deprecated @Override public Long lastsave() { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster scheduled * to be removed on next major release */ @Deprecated @Override public String shutdown() { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster scheduled * to be removed on next major release */ @Deprecated @Override public String info() { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster scheduled * to be removed on next major release */ @Deprecated @Override public String info(String section) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }
/** * @deprecated No key operation doesn't make sense for Redis Cluster scheduled * to be removed on next major release */ @Deprecated @Override public String slaveof(String host, int port) { throw new JedisClusterException("No way to dispatch this command to Redis Cluster."); }