blob: 22f61fb4001e9d144b1d1fbf925f9eb7d902f15a [file] [log] [blame]
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 HGetExecutor extends HashExecutor {
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
List<byte[]> commandElems = command.getProcessedCommand();
if (commandElems.size() < 3) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.HGET));
return;
}
ByteArrayWrapper key = command.getKey();
checkDataType(key, RedisDataType.REDIS_HASH, context);
Region<ByteArrayWrapper, ByteArrayWrapper> keyRegion = getRegion(context, key);
if (keyRegion == null) {
command.setResponse(Coder.getNilResponse(context.getByteBufAllocator()));
return;
}
byte[] byteField = commandElems.get(FIELD_INDEX);
ByteArrayWrapper field = new ByteArrayWrapper(byteField);
ByteArrayWrapper valueWrapper = keyRegion.get(field);
if (valueWrapper != null) {
command.setResponse(Coder.getBulkStringResponse(context.getByteBufAllocator(), valueWrapper.toBytes()));
} else
command.setResponse(Coder.getNilResponse(context.getByteBufAllocator()));
}
}