Search in sources :

Example 61 with ByteArrayWrapper

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

Example 62 with ByteArrayWrapper

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

Example 63 with ByteArrayWrapper

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

Example 64 with ByteArrayWrapper

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

Example 65 with ByteArrayWrapper

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

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