Search in sources :

Example 51 with ByteArrayWrapper

use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.

the class HIncrByFloatExecutor 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.HINCRBYFLOAT));
        return;
    }
    byte[] incrArray = commandElems.get(INCREMENT_INDEX);
    Double increment;
    try {
        increment = Coder.bytesToDouble(incrArray);
    } catch (NumberFormatException e) {
        command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ERROR_INCREMENT_NOT_USABLE));
        return;
    }
    ByteArrayWrapper key = command.getKey();
    Region<ByteArrayWrapper, ByteArrayWrapper> keyRegion = getOrCreateRegion(context, key, RedisDataType.REDIS_HASH);
    byte[] byteField = commandElems.get(FIELD_INDEX);
    ByteArrayWrapper field = new ByteArrayWrapper(byteField);
    /*
     * Put incrememnt as value if field doesn't exist
     */
    ByteArrayWrapper oldValue = keyRegion.get(field);
    if (oldValue == null) {
        keyRegion.put(field, new ByteArrayWrapper(incrArray));
        command.setResponse(Coder.getBulkStringResponse(context.getByteBufAllocator(), increment));
        return;
    }
    /*
     * If the field did exist then increment the field
     */
    String valueS = oldValue.toString();
    if (valueS.contains(" ")) {
        command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ERROR_FIELD_NOT_USABLE));
        return;
    }
    Double value;
    try {
        value = Coder.stringToDouble(valueS);
    } catch (NumberFormatException e) {
        command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ERROR_FIELD_NOT_USABLE));
        return;
    }
    value += increment;
    keyRegion.put(field, new ByteArrayWrapper(Coder.doubleToBytes(value)));
    command.setResponse(Coder.getBulkStringResponse(context.getByteBufAllocator(), value));
}
Also used : ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper)

Example 52 with ByteArrayWrapper

use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.

the class PersistExecutor 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.PERSIST));
        return;
    }
    ByteArrayWrapper key = command.getKey();
    boolean canceled = context.getRegionProvider().cancelKeyExpiration(key);
    if (canceled)
        command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), TIMEOUT_REMOVED));
    else
        command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), KEY_NOT_EXIST_OR_NO_TIMEOUT));
}
Also used : ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper)

Example 53 with ByteArrayWrapper

use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.

the class TTLExecutor 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(), getArgsError()));
        return;
    }
    ByteArrayWrapper key = command.getKey();
    RegionProvider rC = context.getRegionProvider();
    boolean exists = false;
    RedisDataType val = rC.getRedisDataType(key);
    if (val != null)
        exists = true;
    if (!exists) {
        command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_EXISTS));
        return;
    }
    long ttl = rC.getExpirationDelayMillis(key);
    if (ttl == 0L) {
        command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NO_TIMEOUT));
        return;
    }
    if (!timeUnitMillis())
        ttl = ttl / millisInSecond;
    command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), ttl));
}
Also used : RedisDataType(org.apache.geode.redis.internal.RedisDataType) ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper) RegionProvider(org.apache.geode.redis.internal.RegionProvider)

Example 54 with ByteArrayWrapper

use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.

the class ExpireAtExecutor 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;
    }
    RegionProvider rC = context.getRegionProvider();
    ByteArrayWrapper wKey = command.getKey();
    byte[] timestampByteArray = commandElems.get(TIMESTAMP_INDEX);
    long timestamp;
    try {
        timestamp = Coder.bytesToLong(timestampByteArray);
    } catch (NumberFormatException e) {
        command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ERROR_TIMESTAMP_NOT_USABLE));
        return;
    }
    if (!timeUnitMillis())
        timestamp = timestamp * millisInSecond;
    long currentTimeMillis = System.currentTimeMillis();
    if (timestamp <= currentTimeMillis) {
        command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_SET));
        return;
    }
    long delayMillis = timestamp - currentTimeMillis;
    boolean expirationSet = false;
    if (rC.hasExpiration(wKey))
        expirationSet = rC.modifyExpiration(wKey, delayMillis);
    else
        expirationSet = rC.setExpiration(wKey, delayMillis);
    if (expirationSet)
        command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), SET));
    else
        command.setResponse(Coder.getIntegerResponse(context.getByteBufAllocator(), NOT_SET));
}
Also used : RegionProvider(org.apache.geode.redis.internal.RegionProvider) ByteArrayWrapper(org.apache.geode.redis.internal.ByteArrayWrapper)

Example 55 with ByteArrayWrapper

use of org.apache.geode.redis.internal.ByteArrayWrapper in project geode by apache.

the class HValsExecutor 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.HVALS));
        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<ByteArrayWrapper> vals = new ArrayList(keyRegion.values());
    if (vals.isEmpty()) {
        command.setResponse(Coder.getEmptyArrayResponse(context.getByteBufAllocator()));
        return;
    }
    command.setResponse(Coder.getBulkStringArrayResponse(context.getByteBufAllocator(), vals));
}
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