@@ -2,6 +2,35 @@ import Foundation
2
2
import NIO
3
3
4
4
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
+
5
34
/// Select the Redis logical database having the specified zero-based numeric index.
6
35
/// New connections always use the database `0`.
7
36
///
@@ -11,14 +40,21 @@ extension RedisCommandExecutor {
11
40
. map { _ in return ( ) }
12
41
}
13
42
14
- /// Request for authentication in a password-protected Redis server .
43
+ /// Swaps the data of two Redis database by their index ID .
15
44
///
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 " }
20
54
}
55
+ }
21
56
57
+ extension RedisCommandExecutor {
22
58
/// Removes the specified keys. A key is ignored if it does not exist.
23
59
///
24
60
/// [https://redis.io/commands/del](https://redis.io/commands/del)
@@ -60,38 +96,4 @@ extension RedisCommandExecutor {
60
96
return send ( command: " SET " , with: [ key, value] )
61
97
. map { _ in return ( ) }
62
98
}
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
- }
97
99
}
0 commit comments