use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class LLenExecutor method executeCommand.
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
List<byte[]> commandElems = command.getProcessedCommand();
if (commandElems.size() < 2) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.LLEN));
return;
}
ByteArrayWrapper key = command.getKey();
int listSize = 0;
checkDataType(key, RedisDataType.REDIS_LIST, context);
Region<Integer, ByteArrayWrapper> keyRegion = getRegion(context, key);
if (keyRegion == null) {
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_EXISTS));
return;
}
listSize = keyRegion.size() - LIST_EMPTY_SIZE;
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), listSize));
}
use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class LRemExecutor method executeCommand.
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
List<byte[]> commandElems = command.getProcessedCommand();
if (commandElems.size() < 4) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.LREM));
return;
}
ByteArrayWrapper key = command.getKey();
byte[] countArray = commandElems.get(2);
byte[] value = commandElems.get(3);
int count;
checkDataType(key, RedisDataType.REDIS_LIST, context);
Region<Integer, ByteArrayWrapper> keyRegion = getRegion(context, key);
if (keyRegion == null) {
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_EXISTS));
return;
}
try {
count = Coder.bytesToInt(countArray);
} catch (NumberFormatException e) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ERROR_NOT_NUMERIC));
return;
}
List<Struct> removeList;
try {
removeList = getRemoveList(context, key, new ByteArrayWrapper(value), count);
} catch (Exception e) {
throw new RuntimeException(e);
}
int numRemoved = 0;
if (removeList == null) {
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), numRemoved));
return;
}
for (Struct entry : removeList) {
Integer removeKey = (Integer) entry.getFieldValues()[0];
Object oldVal = keyRegion.remove(removeKey);
if (oldVal != null)
numRemoved++;
}
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), numRemoved));
}
use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class TypeExecutor method executeCommand.
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
List<byte[]> commandElems = command.getProcessedCommand();
if (commandElems.size() < 2) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.TYPE));
return;
}
ByteArrayWrapper key = command.getKey();
RedisDataType type = context.getRegionProvider().getRedisDataType(key);
if (type == null)
command.setResponse(Coder.getBulkStringResponse(context.getByteBufAllocator(), "none"));
else
command.setResponse(Coder.getBulkStringResponse(context.getByteBufAllocator(), type.toString()));
}
use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class HExistsExecutor method executeCommand.
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
List<byte[]> commandElems = command.getProcessedCommand();
if (commandElems.size() < 3) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.HEXISTS));
return;
}
ByteArrayWrapper key = command.getKey();
checkDataType(key, RedisDataType.REDIS_HASH, context);
Region<ByteArrayWrapper, ByteArrayWrapper> keyRegion = getRegion(context, key);
if (keyRegion == null) {
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_EXISTS));
return;
}
byte[] byteField = commandElems.get(FIELD_INDEX);
ByteArrayWrapper field = new ByteArrayWrapper(byteField);
boolean hasField = keyRegion.containsKey(field);
if (hasField)
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), EXISTS));
else
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_EXISTS));
}
use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class HGetAllExecutor method executeCommand.
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
List<byte[]> commandElems = command.getProcessedCommand();
if (commandElems.size() < 2) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.HGETALL));
return;
}
ByteArrayWrapper key = command.getKey();
checkDataType(key, RedisDataType.REDIS_HASH, context);
Region<ByteArrayWrapper, ByteArrayWrapper> keyRegion = getRegion(context, key);
if (keyRegion == null) {
command.setResponse(Coder.getEmptyArrayResponse(context.getByteBufAllocator()));
return;
}
Collection<Map.Entry<ByteArrayWrapper, ByteArrayWrapper>> entries = // This creates a CopyOnRead behavior
new ArrayList(keyRegion.entrySet());
if (entries.isEmpty()) {
command.setResponse(Coder.getEmptyArrayResponse(context.getByteBufAllocator()));
return;
}
command.setResponse(Coder.getKeyValArrayResponse(context.getByteBufAllocator(), entries));
}
Aggregations