Search in sources :

Example 66 with ByteArrayWrapper

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));
}
Also used : ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper)

Example 67 with ByteArrayWrapper

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));
}
Also used : ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper) Struct(org.apache.geode.cache.query.Struct)

Example 68 with ByteArrayWrapper

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()));
}
Also used : RedisDataType(org.apache.geode.redis.internal.RedisDataType) ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper)

Example 69 with ByteArrayWrapper

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));
}
Also used : ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper)

Example 70 with ByteArrayWrapper

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));
}
Also used : ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper) ArrayList(java.util.ArrayList)

Aggregations

ByteArrayWrapper (org.apache.geode.redis.internal.ByteArrayWrapper)92 DoubleWrapper (org.apache.geode.redis.internal.DoubleWrapper)16 ArrayList (java.util.ArrayList)15 Region (org.apache.geode.cache.Region)14 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 RegionProvider (org.apache.geode.redis.internal.RegionProvider)6 Struct (org.apache.geode.cache.query.Struct)5 RedisDataType (org.apache.geode.redis.internal.RedisDataType)5 HyperLogLogPlus (org.apache.geode.internal.hll.HyperLogLogPlus)4 Collection (java.util.Collection)3 List (java.util.List)3 Pattern (java.util.regex.Pattern)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)3 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)3 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)3 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)3 Random (java.util.Random)2 Set (java.util.Set)2