Skip to content

Commit e7d6909

Browse files
mp911dechristophstrobl
authored andcommitted
DATAREDIS-1150 - Add ReactiveRedisClusterCommands.
We now provide Redis Cluster commands (CLUSTER INFO, CLUSTER NODES, …) exposed through a reactive API. Original Pull Request: #533
1 parent d18c9c6 commit e7d6909

File tree

4 files changed

+580
-8
lines changed

4 files changed

+580
-8
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/*
2+
* Copyright 2015-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.redis.connection;
17+
18+
import reactor.core.publisher.Flux;
19+
import reactor.core.publisher.Mono;
20+
21+
import java.nio.ByteBuffer;
22+
import java.util.Collection;
23+
import java.util.Map;
24+
25+
import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
26+
27+
/**
28+
* Interface for the {@literal cluster} commands supported by Redis executed using reactive infrastructure.. A
29+
* {@link RedisClusterNode} can be obtained from {@link #clusterGetNodes()} or it can be constructed using either
30+
* {@link RedisClusterNode#getHost() host} and {@link RedisClusterNode#getPort()} or the {@link RedisClusterNode#getId()
31+
* node Id}.
32+
*
33+
* @author Mark Paluch
34+
* @since 2.3.1
35+
*/
36+
public interface ReactiveClusterCommands {
37+
38+
/**
39+
* Retrieve cluster node information such as {@literal id}, {@literal host}, {@literal port} and {@literal slots}.
40+
*
41+
* @return never {@literal null}.
42+
* @see <a href="https://redis.io/commands/cluster-nodes">Redis Documentation: CLUSTER NODES</a>
43+
*/
44+
Flux<RedisClusterNode> clusterGetNodes();
45+
46+
/**
47+
* Retrieve information about connected slaves for given master node.
48+
*
49+
* @param master must not be {@literal null}.
50+
* @return never {@literal null}.
51+
* @see <a href="https://redis.io/commands/cluster-slaves">Redis Documentation: CLUSTER SLAVES</a>
52+
*/
53+
Flux<RedisClusterNode> clusterGetSlaves(RedisClusterNode master);
54+
55+
/**
56+
* Retrieve information about masters and their connected slaves.
57+
*
58+
* @return never {@literal null}.
59+
* @see <a href="https://redis.io/commands/cluster-slaves">Redis Documentation: CLUSTER SLAVES</a>
60+
*/
61+
Mono<Map<RedisClusterNode, Collection<RedisClusterNode>>> clusterGetMasterSlaveMap();
62+
63+
/**
64+
* Find the slot for a given {@code key}.
65+
*
66+
* @param key must not be {@literal null}.
67+
* @return
68+
* @see <a href="https://redis.io/commands/cluster-keyslot">Redis Documentation: CLUSTER KEYSLOT</a>
69+
*/
70+
Mono<Integer> clusterGetSlotForKey(ByteBuffer key);
71+
72+
/**
73+
* Find the {@link RedisClusterNode} serving given {@literal slot}.
74+
*
75+
* @param slot
76+
* @return
77+
*/
78+
Mono<RedisClusterNode> clusterGetNodeForSlot(int slot);
79+
80+
/**
81+
* Find the {@link RedisClusterNode} serving given {@literal key}.
82+
*
83+
* @param key must not be {@literal null}.
84+
* @return
85+
*/
86+
Mono<RedisClusterNode> clusterGetNodeForKey(ByteBuffer key);
87+
88+
/**
89+
* Get cluster information.
90+
*
91+
* @return
92+
* @see <a href="https://redis.io/commands/cluster-info">Redis Documentation: CLUSTER INFO</a>
93+
*/
94+
Mono<ClusterInfo> clusterGetClusterInfo();
95+
96+
/**
97+
* Assign slots to given {@link RedisClusterNode}.
98+
*
99+
* @param node must not be {@literal null}.
100+
* @param slots
101+
* @see <a href="https://redis.io/commands/cluster-addslots">Redis Documentation: CLUSTER ADDSLOTS</a>
102+
*/
103+
Mono<Void> clusterAddSlots(RedisClusterNode node, int... slots);
104+
105+
/**
106+
* Assign {@link SlotRange#getSlotsArray()} to given {@link RedisClusterNode}.
107+
*
108+
* @param node must not be {@literal null}.
109+
* @param range must not be {@literal null}.
110+
* @see <a href="https://redis.io/commands/cluster-addslots">Redis Documentation: CLUSTER ADDSLOTS</a>
111+
*/
112+
Mono<Void> clusterAddSlots(RedisClusterNode node, SlotRange range);
113+
114+
/**
115+
* Count the number of keys assigned to one {@literal slot}.
116+
*
117+
* @param slot
118+
* @return
119+
* @see <a href="https://redis.io/commands/cluster-countkeysinslot">Redis Documentation: CLUSTER COUNTKEYSINSLOT</a>
120+
*/
121+
Mono<Long> clusterCountKeysInSlot(int slot);
122+
123+
/**
124+
* Remove slots from {@link RedisClusterNode}.
125+
*
126+
* @param node must not be {@literal null}.
127+
* @param slots
128+
* @see <a href="https://redis.io/commands/cluster-delslots">Redis Documentation: CLUSTER DELSLOTS</a>
129+
*/
130+
Mono<Void> clusterDeleteSlots(RedisClusterNode node, int... slots);
131+
132+
/**
133+
* Removes {@link SlotRange#getSlotsArray()} from given {@link RedisClusterNode}.
134+
*
135+
* @param node must not be {@literal null}.
136+
* @param range must not be {@literal null}.
137+
* @see <a href="https://redis.io/commands/cluster-delslots">Redis Documentation: CLUSTER DELSLOTS</a>
138+
*/
139+
Mono<Void> clusterDeleteSlotsInRange(RedisClusterNode node, SlotRange range);
140+
141+
/**
142+
* Remove given {@literal node} from cluster.
143+
*
144+
* @param node must not be {@literal null}.
145+
* @see <a href="https://redis.io/commands/cluster-forget">Redis Documentation: CLUSTER FORGET</a>
146+
*/
147+
Mono<Void> clusterForget(RedisClusterNode node);
148+
149+
/**
150+
* Add given {@literal node} to cluster.
151+
*
152+
* @param node must contain {@link RedisClusterNode#getHost() host} and {@link RedisClusterNode#getPort()} and must
153+
* not be {@literal null}.
154+
* @see <a href="https://redis.io/commands/cluster-meet">Redis Documentation: CLUSTER MEET</a>
155+
*/
156+
Mono<Void> clusterMeet(RedisClusterNode node);
157+
158+
/**
159+
* @param node must not be {@literal null}.
160+
* @param slot
161+
* @param mode must not be{@literal null}.
162+
* @see <a href="https://redis.io/commands/cluster-setslot">Redis Documentation: CLUSTER SETSLOT</a>
163+
*/
164+
Mono<Void> clusterSetSlot(RedisClusterNode node, int slot, AddSlots mode);
165+
166+
/**
167+
* Get {@literal keys} served by slot.
168+
*
169+
* @param slot
170+
* @param count must not be {@literal null}.
171+
* @return
172+
* @see <a href="https://redis.io/commands/cluster-getkeysinslot">Redis Documentation: CLUSTER GETKEYSINSLOT</a>
173+
*/
174+
Flux<ByteBuffer> clusterGetKeysInSlot(int slot, int count);
175+
176+
/**
177+
* Assign a {@literal slave} to given {@literal master}.
178+
*
179+
* @param master must not be {@literal null}.
180+
* @param replica must not be {@literal null}.
181+
* @see <a href="https://redis.io/commands/cluster-replicate">Redis Documentation: CLUSTER REPLICATE</a>
182+
*/
183+
Mono<Void> clusterReplicate(RedisClusterNode master, RedisClusterNode replica);
184+
185+
enum AddSlots {
186+
MIGRATING, IMPORTING, STABLE, NODE
187+
}
188+
189+
}

src/main/java/org/springframework/data/redis/connection/ReactiveRedisClusterConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @author Mark Paluch
2323
* @since 2.0
2424
*/
25-
public interface ReactiveRedisClusterConnection extends ReactiveRedisConnection {
25+
public interface ReactiveRedisClusterConnection extends ReactiveRedisConnection, ReactiveClusterCommands {
2626

2727
@Override
2828
ReactiveClusterKeyCommands keyCommands();

0 commit comments

Comments
 (0)