Search in sources :

Example 16 with ByteArrayWrapper

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

Example 17 with ByteArrayWrapper

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

Example 18 with ByteArrayWrapper

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

Example 19 with ByteArrayWrapper

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

Example 20 with ByteArrayWrapper

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

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