File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change
1
+ import Foundation
2
+ import NIO
3
+
4
+ extension ClientBootstrap {
5
+ /// Makes a new `ClientBootstrap` instance with a standard Redis `Channel` pipeline for sending and receiving
6
+ /// messages in Redis Serialization Protocol (RESP) format.
7
+ ///
8
+ /// See `RESPEncoder`, `RESPDecoder`, and `RedisCommadHandler`.
9
+ /// - Parameter using: The `EventLoopGroup` to build the `ClientBootstrap` on.
10
+ /// - Returns: A `ClientBootstrap` with the standard configuration of a `Channel` pipeline for RESP messages.
11
+ public static func makeForRedis( using group: EventLoopGroup ) -> ClientBootstrap {
12
+ return ClientBootstrap ( group: group)
13
+ . channelOption ( ChannelOptions . socket ( SocketOptionLevel ( SOL_SOCKET) , SO_REUSEADDR) , value: 1 )
14
+ . channelInitializer { channel in
15
+ let handlers : [ ChannelHandler ] = [
16
+ RESPEncoder ( ) ,
17
+ ByteToMessageHandler ( RESPDecoder ( ) ) ,
18
+ RedisCommandHandler ( )
19
+ ]
20
+ return EventLoopFuture< Void> . andAll(
21
+ handlers. map { channel. pipeline. add ( handler: $0) } ,
22
+ eventLoop: group. next ( )
23
+ )
24
+ }
25
+ }
26
+ }
Original file line number Diff line number Diff line change @@ -52,15 +52,7 @@ public final class RedisDriver {
52
52
port: Int = 6379 ,
53
53
password: String ? = nil
54
54
) -> EventLoopFuture < RedisConnection > {
55
- let bootstrap = ClientBootstrap ( group: eventLoopGroup)
56
- . channelOption ( ChannelOptions . socket ( SocketOptionLevel ( SOL_SOCKET) , SO_REUSEADDR) , value: 1 )
57
- . channelInitializer { channel in
58
- return channel. pipeline. addHandlers (
59
- RESPEncoder ( ) ,
60
- ByteToMessageHandler ( RESPDecoder ( ) ) ,
61
- RedisCommandHandler ( )
62
- )
63
- }
55
+ let bootstrap = ClientBootstrap . makeForRedis ( using: eventLoopGroup)
64
56
65
57
return bootstrap. connect ( host: hostname, port: port)
66
58
. map { return RedisConnection ( channel: $0) }
You can’t perform that action at this time.
0 commit comments