All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.server.resp.commands.cluster.KEYSLOT Maven / Gradle / Ivy

There is a newer version: 15.1.4.Final
Show newest version
package org.infinispan.server.resp.commands.cluster;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import org.infinispan.AdvancedCache;
import org.infinispan.distribution.ch.KeyPartitioner;
import org.infinispan.distribution.ch.impl.HashFunctionPartitioner;
import org.infinispan.security.AuthorizationPermission;
import org.infinispan.security.actions.SecurityActions;
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 org.infinispan.server.resp.serialization.Resp3Response;

import io.netty.channel.ChannelHandlerContext;

/**
 * `CLUSTER KEYSLOT key` command.
 * 

* Returns the slot a key is mapped to. Useful for debugging. * * @since 15.0 * @see Redis Documentation */ public class KEYSLOT extends RespCommand implements Resp3Command { public KEYSLOT() { super(3, 0, 0,0); } @Override public CompletionStage perform(Resp3Handler handler, ChannelHandlerContext ctx, List arguments) { handler.checkPermission(AuthorizationPermission.ADMIN); AdvancedCache respCache = handler.cache(); KeyPartitioner partitioner = SecurityActions.getCacheComponentRegistry(respCache) .getComponent(KeyPartitioner.class); if (!(partitioner instanceof HashFunctionPartitioner)) { RespErrorUtil.customError("Key partitioner not configured properly", handler.allocator()); return handler.myStage(); } HashFunctionPartitioner hashPartitioner = (HashFunctionPartitioner) partitioner; byte[] key = arguments.get(1); int h = hashPartitioner.getHashForKey(key); CompletionStage cs = CompletableFuture.completedFuture(handler.respServer().segmentSlotRelation().hashToSlot(h)); return handler.stageToReturn(cs, ctx, Resp3Response.INTEGER); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy