Skip to content

Commit 1f2610b

Browse files
mp911dechristophstrobl
authored andcommitted
DATAREDIS-659 - Provide ReactiveServerCommands for basic server interaction.
Original Pull Request: #253
1 parent 772d412 commit 1f2610b

15 files changed

+1369
-59
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright 2017 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+
* http://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.util.Properties;
22+
23+
import org.springframework.data.redis.core.types.RedisClientInfo;
24+
25+
/**
26+
* @author Mark Paluch
27+
* @since 2.0
28+
*/
29+
public interface ReactiveClusterServerCommands extends ReactiveServerCommands {
30+
31+
/**
32+
* @param node must not be {@literal null}.
33+
* @see RedisServerCommands#bgReWriteAof()
34+
*/
35+
Mono<String> bgReWriteAof(RedisClusterNode node);
36+
37+
/**
38+
* @param node must not be {@literal null}.
39+
* @see RedisServerCommands#bgSave()
40+
*/
41+
Mono<String> bgSave(RedisClusterNode node);
42+
43+
/**
44+
* @param node must not be {@literal null}.
45+
* @return
46+
* @see RedisServerCommands#lastSave()
47+
*/
48+
Mono<Long> lastSave(RedisClusterNode node);
49+
50+
/**
51+
* @param node must not be {@literal null}.
52+
* @see RedisServerCommands#save()
53+
*/
54+
Mono<String> save(RedisClusterNode node);
55+
56+
/**
57+
* @param node must not be {@literal null}.
58+
* @return
59+
* @see RedisServerCommands#dbSize()
60+
*/
61+
Mono<Long> dbSize(RedisClusterNode node);
62+
63+
/**
64+
* @param node must not be {@literal null}.
65+
* @see RedisServerCommands#flushDb()
66+
*/
67+
Mono<String> flushDb(RedisClusterNode node);
68+
69+
/**
70+
* @param node must not be {@literal null}.
71+
* @see RedisServerCommands#flushAll()
72+
*/
73+
Mono<String> flushAll(RedisClusterNode node);
74+
75+
/**
76+
* @param node must not be {@literal null}.
77+
* @return
78+
* @see RedisServerCommands#info()
79+
*/
80+
Mono<Properties> info(RedisClusterNode node);
81+
82+
/**
83+
* @param node must not be {@literal null}.
84+
* @param section
85+
* @return
86+
* @see RedisServerCommands#info(String)
87+
*/
88+
Mono<Properties> info(RedisClusterNode node, String section);
89+
90+
/**
91+
* @param node must not be {@literal null}.
92+
* @param pattern
93+
* @return
94+
* @see RedisServerCommands#getConfig(String)
95+
*/
96+
Mono<Properties> getConfig(RedisClusterNode node, String pattern);
97+
98+
/**
99+
* @param node must not be {@literal null}.
100+
* @param param
101+
* @param value
102+
* @see RedisServerCommands#setConfig(String, String)
103+
*/
104+
Mono<String> setConfig(RedisClusterNode node, String param, String value);
105+
106+
/**
107+
* @param node must not be {@literal null}.
108+
* @see RedisServerCommands#resetConfigStats()
109+
*/
110+
Mono<String> resetConfigStats(RedisClusterNode node);
111+
112+
/**
113+
* @param node must not be {@literal null}.
114+
* @return
115+
* @see RedisServerCommands#time()
116+
*/
117+
Mono<Long> time(RedisClusterNode node);
118+
119+
/**
120+
* @param node must not be {@literal null}.
121+
* @return
122+
* @see RedisServerCommands#getClientList()
123+
*/
124+
Flux<RedisClientInfo> getClientList(RedisClusterNode node);
125+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@
1515
*/
1616
package org.springframework.data.redis.connection;
1717

18+
import reactor.core.publisher.Mono;
19+
1820
/**
1921
* @author Christoph Strobl
22+
* @author Mark Paluch
2023
* @since 2.0
2124
*/
2225
public interface ReactiveRedisClusterConnection extends ReactiveRedisConnection {
2326

27+
/**
28+
* @param node must not be {@literal null}.
29+
* @return
30+
* @see RedisConnectionCommands#ping()
31+
*/
32+
Mono<String> ping(RedisClusterNode node);
33+
2434
@Override
2535
ReactiveClusterKeyCommands keyCommands();
2636

@@ -47,4 +57,7 @@ public interface ReactiveRedisClusterConnection extends ReactiveRedisConnection
4757

4858
@Override
4959
ReactiveClusterHyperLogLogCommands hyperLogLogCommands();
60+
61+
@Override
62+
ReactiveClusterServerCommands serverCommands();
5063
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.data.redis.connection;
1717

1818
import lombok.Data;
19+
import reactor.core.publisher.Mono;
1920

2021
import java.io.Closeable;
2122
import java.nio.ByteBuffer;
@@ -114,6 +115,21 @@ public interface ReactiveRedisConnection extends Closeable {
114115
*/
115116
ReactiveHyperLogLogCommands hyperLogLogCommands();
116117

118+
/**
119+
* Get {@link ReactiveServerCommands}.
120+
*
121+
* @return never {@literal null}.
122+
*/
123+
ReactiveServerCommands serverCommands();
124+
125+
/**
126+
* Test connection.
127+
*
128+
* @return Server response message - usually {@literal PONG}.
129+
* @see <a href="http://redis.io/commands/ping">Redis Documentation: PING</a>
130+
*/
131+
Mono<String> ping();
132+
117133
/**
118134
* Base interface for Redis commands executed with a reactive infrastructure.
119135
*
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* Copyright 2017 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+
* http://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.util.List;
22+
import java.util.Properties;
23+
24+
import org.springframework.data.redis.core.types.RedisClientInfo;
25+
26+
/**
27+
* Redis Server commands executed using reactive infrastructure.
28+
*
29+
* @author Mark Paluch
30+
* @since 2.0
31+
*/
32+
public interface ReactiveServerCommands {
33+
34+
/**
35+
* Start an {@literal Append Only File} rewrite process on server.
36+
*
37+
* @see <a href="http://redis.io/commands/bgrewriteaof">Redis Documentation: BGREWRITEAOF</a>
38+
*/
39+
Mono<String> bgReWriteAof();
40+
41+
/**
42+
* Start background saving of db on server.
43+
*
44+
* @see <a href="http://redis.io/commands/bgsave">Redis Documentation: BGSAVE</a>
45+
*/
46+
Mono<String> bgSave();
47+
48+
/**
49+
* Get time of last {@link #bgSave()} operation in seconds.
50+
*
51+
* @return
52+
* @see <a href="http://redis.io/commands/lastsave">Redis Documentation: LASTSAVE</a>
53+
*/
54+
Mono<Long> lastSave();
55+
56+
/**
57+
* Synchronous save current db snapshot on server.
58+
*
59+
* @see <a href="http://redis.io/commands/save">Redis Documentation: SAVE</a>
60+
*/
61+
Mono<String> save();
62+
63+
/**
64+
* Get the total number of available keys in currently selected database.
65+
*
66+
* @return
67+
* @see <a href="http://redis.io/commands/dbsize">Redis Documentation: DBSIZE</a>
68+
*/
69+
Mono<Long> dbSize();
70+
71+
/**
72+
* Delete all keys of the currently selected database.
73+
*
74+
* @see <a href="http://redis.io/commands/flushdb">Redis Documentation: FLUSHDB</a>
75+
*/
76+
Mono<String> flushDb();
77+
78+
/**
79+
* Delete all <b>all keys</b> from <b>all databases</b>.
80+
*
81+
* @see <a href="http://redis.io/commands/flushall">Redis Documentation: FLUSHALL</a>
82+
*/
83+
Mono<String> flushAll();
84+
85+
/**
86+
* Load {@literal default} server information like
87+
* <ul>
88+
* <li>memory</li>
89+
* <li>cpu utilization</li>
90+
* <li>replication</li>
91+
* </ul>
92+
* <p>
93+
*
94+
* @return
95+
* @see <a href="http://redis.io/commands/info">Redis Documentation: INFO</a>
96+
*/
97+
Mono<Properties> info();
98+
99+
/**
100+
* Load server information for given {@code selection}.
101+
*
102+
* @param section
103+
* @return
104+
* @see <a href="http://redis.io/commands/info">Redis Documentation: INFO</a>
105+
*/
106+
Mono<Properties> info(String section);
107+
108+
/**
109+
* Load configuration parameters for given {@code pattern} from server.
110+
*
111+
* @param pattern
112+
* @return
113+
* @see <a href="http://redis.io/commands/config-get">Redis Documentation: CONFIG GET</a>
114+
*/
115+
Mono<Properties> getConfig(String pattern);
116+
117+
/**
118+
* Set server configuration for {@code param} to {@code value}.
119+
*
120+
* @param param
121+
* @param value
122+
* @see <a href="http://redis.io/commands/config-set">Redis Documentation: CONFIG SET</a>
123+
*/
124+
Mono<String> setConfig(String param, String value);
125+
126+
/**
127+
* Reset statistic counters on server. <br>
128+
* Counters can be retrieved using {@link #info()}.
129+
*
130+
* @see <a href="http://redis.io/commands/config-resetstat">Redis Documentation: CONFIG RESETSTAT</a>
131+
*/
132+
Mono<String> resetConfigStats();
133+
134+
/**
135+
* Request server timestamp using {@code TIME} command.
136+
*
137+
* @return current server time in milliseconds.
138+
* @see <a href="http://redis.io/commands/time">Redis Documentation: TIME</a>
139+
*/
140+
Mono<Long> time();
141+
142+
/**
143+
* Closes a given client connection identified by {@literal host:port}.
144+
*
145+
* @param host of connection to close.
146+
* @param port of connection to close
147+
* @see <a href="http://redis.io/commands/client-kill">Redis Documentation: CLIENT KILL</a>
148+
*/
149+
Mono<String> killClient(String host, int port);
150+
151+
/**
152+
* Assign given name to current connection.
153+
*
154+
* @param name
155+
* @see <a href="http://redis.io/commands/client-setname">Redis Documentation: CLIENT SETNAME</a>
156+
*/
157+
Mono<String> setClientName(String name);
158+
159+
/**
160+
* Returns the name of the current connection.
161+
*
162+
* @see <a href="http://redis.io/commands/client-getname">Redis Documentation: CLIENT GETNAME</a>
163+
* @return
164+
*/
165+
Mono<String> getClientName();
166+
167+
/**
168+
* Request information and statistics about connected clients.
169+
*
170+
* @return {@link List} of {@link RedisClientInfo} objects.
171+
* @see <a href="http://redis.io/commands/client-list">Redis Documentation: CLIENT LIST</a>
172+
*/
173+
Flux<RedisClientInfo> getClientList();
174+
}

0 commit comments

Comments
 (0)