Skip to content

Commit 55fbbcc

Browse files
committed
Reorganize code into related extensions
1 parent 5a35a91 commit 55fbbcc

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

Sources/NIORedis/Commands/BasicCommands.swift

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@ import Foundation
22
import NIO
33

44
extension RedisCommandExecutor {
5+
/// Echos the provided message through the Redis instance.
6+
///
7+
/// See [https://redis.io/commands/echo](https://redis.io/commands/echo)
8+
/// - Parameter message: The message to echo.
9+
/// - Returns: The message sent with the command.
10+
public func echo(_ message: String) -> EventLoopFuture<String> {
11+
return send(command: "ECHO", with: [message])
12+
.mapFromRESP()
13+
}
14+
15+
/// Pings the server, which will respond with a message.
16+
///
17+
/// See [https://redis.io/commands/ping](https://redis.io/commands/ping)
18+
/// - Parameter with: The optional message that the server should respond with.
19+
/// - Returns: The provided message or Redis' default response of `"PONG"`.
20+
public func ping(with message: String? = nil) -> EventLoopFuture<String> {
21+
let arg = message != nil ? [message] : []
22+
return send(command: "PING", with: arg)
23+
.mapFromRESP()
24+
}
25+
26+
/// Request for authentication in a password-protected Redis server.
27+
///
28+
/// [https://redis.io/commands/auth](https://redis.io/commands/auth)
29+
public func authorize(with password: String) -> EventLoopFuture<Void> {
30+
return send(command: "AUTH", with: [password])
31+
.map { _ in return () }
32+
}
33+
534
/// Select the Redis logical database having the specified zero-based numeric index.
635
/// New connections always use the database `0`.
736
///
@@ -11,14 +40,21 @@ extension RedisCommandExecutor {
1140
.map { _ in return () }
1241
}
1342

14-
/// Request for authentication in a password-protected Redis server.
43+
/// Swaps the data of two Redis database by their index ID.
1544
///
16-
/// [https://redis.io/commands/auth](https://redis.io/commands/auth)
17-
public func authorize(with password: String) -> EventLoopFuture<Void> {
18-
return send(command: "AUTH", with: [password])
19-
.map { _ in return () }
45+
/// See [https://redis.io/commands/swapdb](https://redis.io/commands/swapdb)
46+
/// - Parameters:
47+
/// - firstIndex: The index of the first database.
48+
/// - secondIndex: The index of the second database.
49+
/// - Returns: `true` if the swap was successful.
50+
public func swapdb(firstIndex: Int, secondIndex: Int) -> EventLoopFuture<Bool> {
51+
return send(command: "SWAPDB", with: [firstIndex, secondIndex])
52+
.mapFromRESP(to: String.self)
53+
.map { return $0 == "OK" }
2054
}
55+
}
2156

57+
extension RedisCommandExecutor {
2258
/// Removes the specified keys. A key is ignored if it does not exist.
2359
///
2460
/// [https://redis.io/commands/del](https://redis.io/commands/del)
@@ -60,38 +96,4 @@ extension RedisCommandExecutor {
6096
return send(command: "SET", with: [key, value])
6197
.map { _ in return () }
6298
}
63-
64-
/// Echos the provided message through the Redis instance.
65-
///
66-
/// See [https://redis.io/commands/echo](https://redis.io/commands/echo)
67-
/// - Parameter message: The message to echo.
68-
/// - Returns: The message sent with the command.
69-
public func echo(_ message: String) -> EventLoopFuture<String> {
70-
return send(command: "ECHO", with: [message])
71-
.mapFromRESP()
72-
}
73-
74-
/// Pings the server, which will respond with a message.
75-
///
76-
/// See [https://redis.io/commands/ping](https://redis.io/commands/ping)
77-
/// - Parameter with: The optional message that the server should respond with.
78-
/// - Returns: The provided message or Redis' default response of `"PONG"`.
79-
public func ping(with message: String? = nil) -> EventLoopFuture<String> {
80-
let arg = message != nil ? [message] : []
81-
return send(command: "PING", with: arg)
82-
.mapFromRESP()
83-
}
84-
85-
/// Swaps the data of two Redis database by their index ID.
86-
///
87-
/// See [https://redis.io/commands/swapdb](https://redis.io/commands/swapdb)
88-
/// - Parameters:
89-
/// - firstIndex: The index of the first database.
90-
/// - secondIndex: The index of the second database.
91-
/// - Returns: `true` if the swap was successful.
92-
public func swapdb(firstIndex: Int, secondIndex: Int) -> EventLoopFuture<Bool> {
93-
return send(command: "SWAPDB", with: [firstIndex, secondIndex])
94-
.mapFromRESP(to: String.self)
95-
.map { return $0 == "OK" }
96-
}
9799
}

0 commit comments

Comments
 (0)