use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class SIsMemberExecutor 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.SISMEMBER));
return;
}
ByteArrayWrapper key = command.getKey();
ByteArrayWrapper member = new ByteArrayWrapper(commandElems.get(2));
checkDataType(key, RedisDataType.REDIS_SET, context);
@SuppressWarnings("unchecked") Region<ByteArrayWrapper, Boolean> keyRegion = (Region<ByteArrayWrapper, Boolean>) context.getRegionProvider().getRegion(key);
if (keyRegion == null) {
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_EXISTS));
return;
}
if (keyRegion.containsKey(member))
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 SMembersExecutor 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.SMEMBERS));
return;
}
ByteArrayWrapper key = command.getKey();
checkDataType(key, RedisDataType.REDIS_SET, context);
@SuppressWarnings("unchecked") Region<ByteArrayWrapper, Boolean> keyRegion = (Region<ByteArrayWrapper, Boolean>) context.getRegionProvider().getRegion(key);
if (keyRegion == null) {
command.setResponse(Coder.getEmptyArrayResponse(context.getByteBufAllocator()));
return;
}
// Emulate copy on read
Set<ByteArrayWrapper> members = new HashSet(keyRegion.keySet());
command.setResponse(Coder.getBulkStringArrayResponse(context.getByteBufAllocator(), members));
}
use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class ZRemExecutor 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.ZREM));
return;
}
ByteArrayWrapper key = command.getKey();
checkDataType(key, RedisDataType.REDIS_SORTEDSET, context);
Region<ByteArrayWrapper, DoubleWrapper> keyRegion = getRegion(context, key);
if (keyRegion == null) {
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), 0));
return;
}
int numDeletedMembers = 0;
for (int i = 2; i < commandElems.size(); i++) {
byte[] memberArray = commandElems.get(i);
ByteArrayWrapper member = new ByteArrayWrapper(memberArray);
Object oldVal = keyRegion.remove(member);
if (oldVal != null)
numDeletedMembers++;
}
if (keyRegion.isEmpty())
context.getRegionProvider().removeKey(key);
command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), numDeletedMembers));
}
use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class ZRemRangeByLexExecutor method getRange.
private Collection<ByteArrayWrapper> getRange(ByteArrayWrapper key, Region<ByteArrayWrapper, DoubleWrapper> keyRegion, ExecutionHandlerContext context, ByteArrayWrapper start, ByteArrayWrapper stop, boolean startInclusive, boolean stopInclusive) throws Exception {
if (start.equals("-") && stop.equals("+"))
return new ArrayList<ByteArrayWrapper>(keyRegion.keySet());
else if (start.equals("+") || stop.equals("-"))
return null;
Query query;
Object[] params;
if (start.equals("-")) {
if (stopInclusive) {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXNINFI, context);
} else {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXNINF, context);
}
params = new Object[] { stop, INFINITY_LIMIT };
} else if (stop.equals("+")) {
if (startInclusive) {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXPINFI, context);
} else {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXPINF, context);
}
params = new Object[] { start, INFINITY_LIMIT };
} else {
if (startInclusive) {
if (stopInclusive) {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXSTISI, context);
} else {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXSTI, context);
}
} else {
if (stopInclusive) {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEXSI, context);
} else {
query = getQuery(key, SortedSetQuery.ZRANGEBYLEX, context);
}
}
params = new Object[] { start, stop, INFINITY_LIMIT };
}
@SuppressWarnings("unchecked") SelectResults<ByteArrayWrapper> results = (SelectResults<ByteArrayWrapper>) query.execute(params);
return results.asList();
}
use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.
the class BitOpExecutor method or.
private void or(ExecutionHandlerContext context, Region<ByteArrayWrapper, ByteArrayWrapper> r, ByteArrayWrapper destKey, byte[][] values, int max) {
byte[] dest = new byte[max];
for (int i = 0; i < max; i++) {
byte b = values[0][i];
for (int j = 1; j < values.length; j++) {
byte[] cA = values[j];
if (cA != null && i < cA.length)
b |= cA[i];
else
b |= 0;
}
dest[i] = b;
}
checkAndSetDataType(destKey, context);
r.put(destKey, new ByteArrayWrapper(dest));
}
Aggregations