redis.clients.jedis.ClusterCommandArguments Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jedis_preview Show documentation
Show all versions of jedis_preview Show documentation
Jedis is a blazingly small and sane Redis java client.
The newest version!
package redis.clients.jedis;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.exceptions.JedisClusterOperationException;
import redis.clients.jedis.util.JedisClusterCRC16;
public class ClusterCommandArguments extends CommandArguments {
private int commandHashSlot = -1;
public ClusterCommandArguments(ProtocolCommand command) {
super(command);
}
public int getCommandHashSlot() {
return commandHashSlot;
}
@Override
protected CommandArguments processKey(byte[] key) {
final int hashSlot = JedisClusterCRC16.getSlot(key);
if (commandHashSlot < 0) {
commandHashSlot = hashSlot;
} else if (commandHashSlot != hashSlot) {
throw new JedisClusterOperationException("Keys must belong to same hashslot.");
}
return this;
}
@Override
protected CommandArguments processKey(String key) {
final int hashSlot = JedisClusterCRC16.getSlot(key);
if (commandHashSlot < 0) {
commandHashSlot = hashSlot;
} else if (commandHashSlot != hashSlot) {
throw new JedisClusterOperationException("Keys must belong to same hashslot.");
}
return this;
}
}