Skip to content

DATAREDIS-1150 - Add ReactiveRedisClusterCommands #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.4.0-SNAPSHOT</version>
<version>2.4.0-DATAREDIS-1150-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
* Copyright 2015-2020 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
*
* https://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 reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Map;

import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;

/**
* Interface for the {@literal cluster} commands supported by Redis executed using reactive infrastructure.. 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 Mark Paluch
* @since 2.3.1
*/
public interface ReactiveClusterCommands {

/**
* Retrieve cluster node information such as {@literal id}, {@literal host}, {@literal port} and {@literal slots}.
*
* @return never {@literal null}.
* @see <a href="https://redis.io/commands/cluster-nodes">Redis Documentation: CLUSTER NODES</a>
*/
Flux<RedisClusterNode> clusterGetNodes();

/**
* Retrieve information about connected slaves for given master node.
*
* @param master must not be {@literal null}.
* @return never {@literal null}.
* @see <a href="https://redis.io/commands/cluster-slaves">Redis Documentation: CLUSTER SLAVES</a>
*/
Flux<RedisClusterNode> clusterGetSlaves(RedisClusterNode master);

/**
* Retrieve information about masters and their connected slaves.
*
* @return never {@literal null}.
* @see <a href="https://redis.io/commands/cluster-slaves">Redis Documentation: CLUSTER SLAVES</a>
*/
Mono<Map<RedisClusterNode, Collection<RedisClusterNode>>> clusterGetMasterSlaveMap();

/**
* Find the slot for a given {@code key}.
*
* @param key must not be {@literal null}.
* @return
* @see <a href="https://redis.io/commands/cluster-keyslot">Redis Documentation: CLUSTER KEYSLOT</a>
*/
Mono<Integer> clusterGetSlotForKey(ByteBuffer key);

/**
* Find the {@link RedisClusterNode} serving given {@literal slot}.
*
* @param slot
* @return
*/
Mono<RedisClusterNode> clusterGetNodeForSlot(int slot);

/**
* Find the {@link RedisClusterNode} serving given {@literal key}.
*
* @param key must not be {@literal null}.
* @return
*/
Mono<RedisClusterNode> clusterGetNodeForKey(ByteBuffer key);

/**
* Get cluster information.
*
* @return
* @see <a href="https://redis.io/commands/cluster-info">Redis Documentation: CLUSTER INFO</a>
*/
Mono<ClusterInfo> clusterGetClusterInfo();

/**
* Assign slots to given {@link RedisClusterNode}.
*
* @param node must not be {@literal null}.
* @param slots
* @see <a href="https://redis.io/commands/cluster-addslots">Redis Documentation: CLUSTER ADDSLOTS</a>
*/
Mono<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 <a href="https://redis.io/commands/cluster-addslots">Redis Documentation: CLUSTER ADDSLOTS</a>
*/
Mono<Void> clusterAddSlots(RedisClusterNode node, SlotRange range);

/**
* Count the number of keys assigned to one {@literal slot}.
*
* @param slot
* @return
* @see <a href="https://redis.io/commands/cluster-countkeysinslot">Redis Documentation: CLUSTER COUNTKEYSINSLOT</a>
*/
Mono<Long> clusterCountKeysInSlot(int slot);

/**
* Remove slots from {@link RedisClusterNode}.
*
* @param node must not be {@literal null}.
* @param slots
* @see <a href="https://redis.io/commands/cluster-delslots">Redis Documentation: CLUSTER DELSLOTS</a>
*/
Mono<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 <a href="https://redis.io/commands/cluster-delslots">Redis Documentation: CLUSTER DELSLOTS</a>
*/
Mono<Void> clusterDeleteSlotsInRange(RedisClusterNode node, SlotRange range);

/**
* Remove given {@literal node} from cluster.
*
* @param node must not be {@literal null}.
* @see <a href="https://redis.io/commands/cluster-forget">Redis Documentation: CLUSTER FORGET</a>
*/
Mono<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 <a href="https://redis.io/commands/cluster-meet">Redis Documentation: CLUSTER MEET</a>
*/
Mono<Void> clusterMeet(RedisClusterNode node);

/**
* @param node must not be {@literal null}.
* @param slot
* @param mode must not be{@literal null}.
* @see <a href="https://redis.io/commands/cluster-setslot">Redis Documentation: CLUSTER SETSLOT</a>
*/
Mono<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 <a href="https://redis.io/commands/cluster-getkeysinslot">Redis Documentation: CLUSTER GETKEYSINSLOT</a>
*/
Flux<ByteBuffer> clusterGetKeysInSlot(int slot, int count);

/**
* Assign a {@literal slave} to given {@literal master}.
*
* @param master must not be {@literal null}.
* @param replica must not be {@literal null}.
* @see <a href="https://redis.io/commands/cluster-replicate">Redis Documentation: CLUSTER REPLICATE</a>
*/
Mono<Void> clusterReplicate(RedisClusterNode master, RedisClusterNode replica);

enum AddSlots {
MIGRATING, IMPORTING, STABLE, NODE
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @author Mark Paluch
* @since 2.0
*/
public interface ReactiveRedisClusterConnection extends ReactiveRedisConnection {
public interface ReactiveRedisClusterConnection extends ReactiveRedisConnection, ReactiveClusterCommands {

@Override
ReactiveClusterKeyCommands keyCommands();
Expand Down
Loading