org.infinispan.server.resp.commands.hash.HMSET Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of infinispan-server-resp Show documentation
Show all versions of infinispan-server-resp Show documentation
Infinispan Resp Protocol Server
The newest version!
package org.infinispan.server.resp.commands.hash;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionStage;
import org.infinispan.multimap.impl.EmbeddedMultimapPairCache;
import org.infinispan.server.resp.Consumers;
import org.infinispan.server.resp.Resp3Handler;
import org.infinispan.server.resp.RespCommand;
import org.infinispan.server.resp.RespErrorUtil;
import org.infinispan.server.resp.RespRequestHandler;
import org.infinispan.server.resp.commands.Resp3Command;
import io.netty.channel.ChannelHandlerContext;
/**
* Executes the `HMSET key field value [field value ...]
` command.
*
* Sets the specified `field
`-`value
` pairs in the hash stored at the given `key
`.
*
*
* Note this command is deprecated since Redis 4.0 in favor of {@link HSET}.
*
* @since 15.0
* @see Redis Documentation
*/
public class HMSET extends RespCommand implements Resp3Command {
public HMSET() {
super(-4, 1, 1, 1);
}
@Override
public CompletionStage perform(Resp3Handler handler, ChannelHandlerContext ctx, List arguments) {
// Arguments are the hash map key and N key-value pairs.
if ((arguments.size() & 1) == 0) {
RespErrorUtil.wrongArgumentNumber(this, handler.allocator());
return handler.myStage();
}
return handler.stageToReturn(setEntries(handler, arguments), ctx, Consumers.OK_BICONSUMER);
}
protected CompletionStage setEntries(Resp3Handler handler, List arguments) {
byte[] key = arguments.get(0);
EmbeddedMultimapPairCache hashMap = handler.getHashMapMultimap();
Map.Entry[] entries = new Map.Entry[(arguments.size() - 1) >> 1];
for (int i = 1; i < arguments.size(); i++) {
entries[i / 2] = Map.entry(arguments.get(i), arguments.get(++i));
}
return hashMap.set(key, entries);
}
}