blob: b887e7f855d7e122224b589a02cffe7d834a18ee [file] [log] [blame]
package com.gemstone.gemfire.internal.redis.executor.sortedset;
import java.util.List;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.internal.redis.ByteArrayWrapper;
import com.gemstone.gemfire.internal.redis.Coder;
import com.gemstone.gemfire.internal.redis.Command;
import com.gemstone.gemfire.internal.redis.DoubleWrapper;
import com.gemstone.gemfire.internal.redis.ExecutionHandlerContext;
import com.gemstone.gemfire.internal.redis.RedisConstants.ArityDef;
import com.gemstone.gemfire.internal.redis.RedisDataType;
public class ZScoreExecutor extends SortedSetExecutor {
@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
List<byte[]> commandElems = command.getProcessedCommand();
if (commandElems.size() < 3) {
command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), ArityDef.ZSCORE));
return;
}
ByteArrayWrapper key = command.getKey();
ByteArrayWrapper member = new ByteArrayWrapper(commandElems.get(2));
checkDataType(key, RedisDataType.REDIS_SORTEDSET, context);
Region<ByteArrayWrapper, DoubleWrapper> keyRegion = getRegion(context, key);
if (keyRegion == null) {
command.setResponse(Coder.getNilResponse(context.getByteBufAllocator()));
return;
}
DoubleWrapper score = keyRegion.get(member);
if (score == null) {
command.setResponse(Coder.getNilResponse(context.getByteBufAllocator()));
return;
}
command.setResponse(Coder.getBulkStringResponse(context.getByteBufAllocator(), score.toString()));
}
}