mirror of
https://github.com/swift-server/RediStack.git
synced 2026-06-02 07:37:33 +00:00
Make public factory method for "standard" NIORedis ClientBootstrap
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import Foundation
|
||||
import NIO
|
||||
|
||||
extension ClientBootstrap {
|
||||
/// Makes a new `ClientBootstrap` instance with a standard Redis `Channel` pipeline for sending and receiving
|
||||
/// messages in Redis Serialization Protocol (RESP) format.
|
||||
///
|
||||
/// See `RESPEncoder`, `RESPDecoder`, and `RedisCommadHandler`.
|
||||
/// - Parameter using: The `EventLoopGroup` to build the `ClientBootstrap` on.
|
||||
/// - Returns: A `ClientBootstrap` with the standard configuration of a `Channel` pipeline for RESP messages.
|
||||
public static func makeForRedis(using group: EventLoopGroup) -> ClientBootstrap {
|
||||
return ClientBootstrap(group: group)
|
||||
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.channelInitializer { channel in
|
||||
let handlers: [ChannelHandler] = [
|
||||
RESPEncoder(),
|
||||
ByteToMessageHandler(RESPDecoder()),
|
||||
RedisCommandHandler()
|
||||
]
|
||||
return EventLoopFuture<Void>.andAll(
|
||||
handlers.map { channel.pipeline.add(handler: $0) },
|
||||
eventLoop: group.next()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,15 +52,7 @@ public final class RedisDriver {
|
||||
port: Int = 6379,
|
||||
password: String? = nil
|
||||
) -> EventLoopFuture<RedisConnection> {
|
||||
let bootstrap = ClientBootstrap(group: eventLoopGroup)
|
||||
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
|
||||
.channelInitializer { channel in
|
||||
return channel.pipeline.addHandlers(
|
||||
RESPEncoder(),
|
||||
ByteToMessageHandler(RESPDecoder()),
|
||||
RedisCommandHandler()
|
||||
)
|
||||
}
|
||||
let bootstrap = ClientBootstrap.makeForRedis(using: eventLoopGroup)
|
||||
|
||||
return bootstrap.connect(host: hostname, port: port)
|
||||
.map { return RedisConnection(channel: $0) }
|
||||
|
||||
Reference in New Issue
Block a user