diff --git a/README.md b/README.md index 6b2dfd7..847c2e8 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,13 @@ # NIORedis -A non-blocking Swift driver for Redis built with [SwiftNIO](https://github.com/apple/swift-nio). +A non-blocking Swift driver for [Redis](https://redis.io/) built with [SwiftNIO](https://github.com/apple/swift-nio). This package defines everything you need to work with Redis through the [**Re**dis **S**eralization **P**rotocol (RESP)](https://redis.io/topics/protocol). * Pitch discussion: [Swift Server Forums](https://forums.swift.org/t/swiftnio-redis-client/19325) -* Proposal: [SSWG-0004](https://github.com/swift-server/sswg/blob/56a26b50ade45d624b54abe13c7d1f88526f9bb1/proposals/0004-nio-redis.md) +* Proposal: [SSWG-0004](https://github.com/swift-server/sswg/blob/d391da355718a8f396ef86b3563910089d5e5992/proposals/0004-nio-redis.md) + * [Discussion Thread](https://forums.swift.org/t/discussion-nioredis-nio-based-redis-driver/22455/) ## Installation @@ -18,7 +19,7 @@ To install `NIORedis`, just add the package as a dependency in your [**Package.s ```swift dependencies: [ - .package(url: "https://github.com/Mordil/nio-redis.git", .upToNextMinor(from: "0.2.0") + .package(url: "https://github.com/Mordil/nio-redis.git", .upToNextMinor(from: "0.7.0") ] ``` @@ -31,9 +32,10 @@ and run the following command: `swift package resolve` ```swift import NIORedis -let driver = NIORedisDriver(ownershipModel: .internal(threadCount: 2)) - -let connection = try driver.makeConnection().wait() +let connection = Redis.makeConnection( + to: try .init(ipAddress: "127.0.0.1", port: 6379), + password: "my_pass" +).wait() let result = try connection.set("my_key", to: "some value") .flatMap { return connection.get("my_key" } diff --git a/Sources/NIORedis/Redis.swift b/Sources/NIORedis/Redis.swift index df14922..2e1012e 100644 --- a/Sources/NIORedis/Redis.swift +++ b/Sources/NIORedis/Redis.swift @@ -49,24 +49,30 @@ extension Redis { extension Redis { /// Makes a new connection to a Redis instance. /// + /// As soon as the connection has been opened on the host, an "AUTH" command will be sent to + /// Redis to authorize use of additional commands on this new connection. + /// + /// See [https://redis.io/commands/auth](https://redis.io/commands/auth) + /// /// Example: /// - /// let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1) + /// let elg = MultiThreadedEventLoopGroup(numberOfThreads: 3) /// let connection = Redis.makeConnection( /// to: .init(ipAddress: "127.0.0.1", port: 6379), - /// using: elg + /// using: elg, + /// password: "my_pass" /// ) /// /// - Parameters: /// - socket: The `SocketAddress` information of the Redis instance to connect to. + /// - group: The `EventLoopGroup` to build the connection on. Default is a single threaded `EventLoopGroup`. /// - password: The optional password to authorize the client with. - /// - eventLoopGroup: The `EventLoopGroup` to build the connection on. /// - logger: The `Logger` instance to log with. /// - Returns: A `RedisConnection` instance representing this new connection. public static func makeConnection( to socket: SocketAddress, - using group: EventLoopGroup, - with password: String? = nil, + using group: EventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1), + password: String? = nil, logger: Logger = Logger(label: "NIORedis.RedisConnection") ) -> EventLoopFuture { let bootstrap = makeDefaultClientBootstrap(using: group) diff --git a/Tests/NIORedisTests/Utilities/RedisConnection.swift b/Tests/NIORedisTests/Utilities/RedisConnection.swift index 5cd0680..9e2c8fa 100644 --- a/Tests/NIORedisTests/Utilities/RedisConnection.swift +++ b/Tests/NIORedisTests/Utilities/RedisConnection.swift @@ -16,9 +16,6 @@ extension Redis { static func makeConnection() throws -> EventLoopFuture { - return Redis.makeConnection( - to: try .init(ipAddress: "127.0.0.1", port: 6379), - using: MultiThreadedEventLoopGroup(numberOfThreads: 1) - ) + return Redis.makeConnection(to: try .init(ipAddress: "127.0.0.1", port: 6379)) } }