org.springframework.data.redis.connection.RedisClusterCommands Maven / Gradle / Ivy
/*
* Copyright 2015-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
/**
* Interface for the {@literal cluster} commands supported by Redis. A {@link RedisClusterNode} can be obtained from
* {@link #clusterGetNodes()} or it can be constructed using either {@link RedisClusterNode#getHost() host} and
* {@link RedisClusterNode#getPort()} or the {@link RedisClusterNode#getId() node Id}.
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 1.7
*/
public interface RedisClusterCommands {
/**
* Retrieve cluster node information such as {@literal id}, {@literal host}, {@literal port} and {@literal slots}.
*
* @return never {@literal null}.
* @see Redis Documentation: CLUSTER NODES
*/
Iterable clusterGetNodes();
/**
* Retrieve information about connected slaves for given master node.
*
* @param master must not be {@literal null}.
* @return never {@literal null}.
* @see Redis Documentation: CLUSTER SLAVES
*/
Collection clusterGetSlaves(RedisClusterNode master);
/**
* Retrieve information about masters and their connected slaves.
*
* @return never {@literal null}.
* @see Redis Documentation: CLUSTER SLAVES
*/
Map> clusterGetMasterSlaveMap();
/**
* Find the slot for a given {@code key}.
*
* @param key must not be {@literal null}.
* @return
* @see Redis Documentation: CLUSTER KEYSLOT
*/
Integer clusterGetSlotForKey(byte[] key);
/**
* Find the {@link RedisClusterNode} serving given {@literal slot}.
*
* @param slot
* @return
*/
RedisClusterNode clusterGetNodeForSlot(int slot);
/**
* Find the {@link RedisClusterNode} serving given {@literal key}.
*
* @param key must not be {@literal null}.
* @return
*/
RedisClusterNode clusterGetNodeForKey(byte[] key);
/**
* Get cluster information.
*
* @return
* @see Redis Documentation: CLUSTER INFO
*/
ClusterInfo clusterGetClusterInfo();
/**
* Assign slots to given {@link RedisClusterNode}.
*
* @param node must not be {@literal null}.
* @param slots
* @see Redis Documentation: CLUSTER ADDSLOTS
*/
void clusterAddSlots(RedisClusterNode node, int... slots);
/**
* Assign {@link SlotRange#getSlotsArray()} to given {@link RedisClusterNode}.
*
* @param node must not be {@literal null}.
* @param range must not be {@literal null}.
* @see Redis Documentation: CLUSTER ADDSLOTS
*/
void clusterAddSlots(RedisClusterNode node, SlotRange range);
/**
* Count the number of keys assigned to one {@literal slot}.
*
* @param slot
* @return
* @see Redis Documentation: CLUSTER COUNTKEYSINSLOT
*/
Long clusterCountKeysInSlot(int slot);
/**
* Remove slots from {@link RedisClusterNode}.
*
* @param node must not be {@literal null}.
* @param slots
* @see Redis Documentation: CLUSTER DELSLOTS
*/
void clusterDeleteSlots(RedisClusterNode node, int... slots);
/**
* Removes {@link SlotRange#getSlotsArray()} from given {@link RedisClusterNode}.
*
* @param node must not be {@literal null}.
* @param range must not be {@literal null}.
* @see Redis Documentation: CLUSTER DELSLOTS
*/
void clusterDeleteSlotsInRange(RedisClusterNode node, SlotRange range);
/**
* Remove given {@literal node} from cluster.
*
* @param node must not be {@literal null}.
* @see Redis Documentation: CLUSTER FORGET
*/
void clusterForget(RedisClusterNode node);
/**
* Add given {@literal node} to cluster.
*
* @param node must contain {@link RedisClusterNode#getHost() host} and {@link RedisClusterNode#getPort()} and must
* not be {@literal null}.
* @see Redis Documentation: CLUSTER MEET
*/
void clusterMeet(RedisClusterNode node);
/**
* @param node must not be {@literal null}.
* @param slot
* @param mode must not be{@literal null}.
* @see Redis Documentation: CLUSTER SETSLOT
*/
void clusterSetSlot(RedisClusterNode node, int slot, AddSlots mode);
/**
* Get {@literal keys} served by slot.
*
* @param slot
* @param count must not be {@literal null}.
* @return
* @see Redis Documentation: CLUSTER GETKEYSINSLOT
*/
List clusterGetKeysInSlot(int slot, Integer count);
/**
* Assign a {@literal slave} to given {@literal master}.
*
* @param master must not be {@literal null}.
* @param replica must not be {@literal null}.
* @see Redis Documentation: CLUSTER REPLICATE
*/
void clusterReplicate(RedisClusterNode master, RedisClusterNode replica);
enum AddSlots {
MIGRATING, IMPORTING, STABLE, NODE
}
}