| package com.gemstone.gemfire.internal.redis.executor.hash; |
| |
| import java.util.List; |
| |
| import com.gemstone.gemfire.cache.Region; |
| import com.gemstone.gemfire.internal.redis.ByteArrayWrapper; |
| import com.gemstone.gemfire.internal.redis.Command; |
| import com.gemstone.gemfire.internal.redis.ExecutionHandlerContext; |
| import com.gemstone.gemfire.internal.redis.RedisDataType; |
| import com.gemstone.gemfire.internal.redis.Coder; |
| import com.gemstone.gemfire.internal.redis.RedisConstants.ArityDef; |
| |
| public class HExistsExecutor extends HashExecutor { |
| |
| private final int NOT_EXISTS = 0; |
| |
| private final int EXISTS = 1; |
| |
| @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)); |
| |
| } |
| |
| } |