use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class HMGetExecutor 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.HMGET));
return;
}
ByteArrayWrapper key = command.getKey();
Region<ByteArrayWrapper, ByteArrayWrapper> keyRegion = getRegion(context, key);
checkDataType(key, RedisDataType.REDIS_HASH, context);
if (keyRegion == null) {
command.setResponse(Coder.getArrayOfNils(context.getByteBufAllocator(), commandElems.size() - 2));
return;
}
ArrayList<ByteArrayWrapper> fields = new ArrayList<ByteArrayWrapper>();
for (int i = 2; i < commandElems.size(); i++) {
byte[] fieldArray = commandElems.get(i);
ByteArrayWrapper field = new ByteArrayWrapper(fieldArray);
fields.add(field);
}
Map<ByteArrayWrapper, ByteArrayWrapper> results = keyRegion.getAll(fields);
ArrayList<ByteArrayWrapper> values = new ArrayList<ByteArrayWrapper>();
/*
* This is done to preserve order in the output
*/
for (ByteArrayWrapper field : fields) values.add(results.get(field));
command.setResponse(Coder.getBulkStringArrayResponse(context.getByteBufAllocator(), values));
}
use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class HScanExecutor method getIteration.
@SuppressWarnings("unchecked")
@Override
protected List<Object> getIteration(Collection<?> list, Pattern matchPattern, int count, int cursor) {
List<Object> returnList = new ArrayList<Object>();
int size = list.size();
int beforeCursor = 0;
int numElements = 0;
int i = -1;
for (Entry<ByteArrayWrapper, ByteArrayWrapper> entry : (Collection<Entry<ByteArrayWrapper, ByteArrayWrapper>>) list) {
ByteArrayWrapper key = entry.getKey();
ByteArrayWrapper value = entry.getValue();
i++;
if (beforeCursor < cursor) {
beforeCursor++;
continue;
} else if (numElements < count) {
if (matchPattern != null) {
if (matchPattern.matcher(key.toString()).matches()) {
returnList.add(key);
returnList.add(value);
numElements++;
}
} else {
returnList.add(key);
returnList.add(value);
numElements++;
}
} else
break;
}
if (i == size - 1)
returnList.add(0, String.valueOf(0));
else
returnList.add(0, String.valueOf(i));
return returnList;
}
use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class DelExecutor method executeCommand.
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
if (context.hasTransaction())
throw new UnsupportedOperationInTransactionException();
List<byte[]> commandElems = command.getProcessedCommand();
if (commandElems.size() < 2) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.DEL));
return;
}
int numRemoved = 0;
for (int i = 1; i < commandElems.size(); i++) {
byte[] byteKey = commandElems.get(i);
ByteArrayWrapper key = new ByteArrayWrapper(byteKey);
RedisDataType type = context.getRegionProvider().getRedisDataType(key);
if (removeEntry(key, type, context))
numRemoved++;
}
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), numRemoved));
}
use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class ExistsExecutor 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.EXISTS));
return;
}
ByteArrayWrapper key = command.getKey();
boolean exists = context.getRegionProvider().existsKey(key);
if (exists)
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 ExpireExecutor 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(), getArgsError()));
return;
}
ByteArrayWrapper wKey = command.getKey();
RegionProvider rC = context.getRegionProvider();
byte[] delayByteArray = commandElems.get(SECONDS_INDEX);
long delay;
try {
delay = Coder.bytesToLong(delayByteArray);
} catch (NumberFormatException e) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ERROR_SECONDS_NOT_USABLE));
return;
}
if (delay <= 0) {
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_SET));
return;
}
// If time unit given is not in millis convert to millis
if (!timeUnitMillis())
delay = delay * millisInSecond;
boolean expirationSet = false;
if (rC.hasExpiration(wKey))
expirationSet = rC.modifyExpiration(wKey, delay);
else
expirationSet = rC.setExpiration(wKey, delay);
if (expirationSet)
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), SET));
else
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_SET));
}
Aggregations