Skip to content

Commit 0131fe4

Browse files
committed
Update Readme and Tweak Redis.makeConnection(...)
Motivation: The goal of the `Redis.makeConnection` factory method is to provide end users with a quick way to jump in and get started with Redis in Swift. Right now, users have to provide an `EventLoopGroup` instance, when a reasonable default is available for us to define. Modifications: - Add: `MultiThreadedEventLoopGroup` for 1 thread as a default argument to the `using:` label in `Redis.makeConnection` - Remove: The `with:` label for the password in `Redis.makeConnection` - Change: The project README to reflect the current state of the project Results: Users should be able to create `RedisConnections` by just defining an IP Address & Port to connect to - and possibly a password. In addition, the README should now properly direct users on how to use the latest version of the library.
1 parent c7a606d commit 0131fe4

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55

66
# NIORedis
77

8-
A non-blocking Swift driver for Redis built with [SwiftNIO](https://github.com/apple/swift-nio).
8+
A non-blocking Swift driver for [Redis](https://redis.io/) built with [SwiftNIO](https://github.com/apple/swift-nio).
99

1010
This package defines everything you need to work with Redis through the [**Re**dis **S**eralization **P**rotocol (RESP)](https://redis.io/topics/protocol).
1111

1212
* Pitch discussion: [Swift Server Forums](https://forums.swift.org/t/swiftnio-redis-client/19325)
13-
* Proposal: [SSWG-0004](https://github.com/swift-server/sswg/blob/56a26b50ade45d624b54abe13c7d1f88526f9bb1/proposals/0004-nio-redis.md)
13+
* Proposal: [SSWG-0004](https://github.com/swift-server/sswg/blob/d391da355718a8f396ef86b3563910089d5e5992/proposals/0004-nio-redis.md)
14+
* [Discussion Thread](https://forums.swift.org/t/discussion-nioredis-nio-based-redis-driver/22455/)
1415

1516
## Installation
1617

1718
To install `NIORedis`, just add the package as a dependency in your [**Package.swift**](https://github.com/apple/swift-package-manager/blob/master/Documentation/PackageDescriptionV4.md#dependencies)
1819

1920
```swift
2021
dependencies: [
21-
.package(url: "https://github.com/Mordil/nio-redis.git", .upToNextMinor(from: "0.2.0")
22+
.package(url: "https://github.com/Mordil/nio-redis.git", .upToNextMinor(from: "0.7.0")
2223
]
2324
```
2425

@@ -31,9 +32,10 @@ and run the following command: `swift package resolve`
3132
```swift
3233
import NIORedis
3334

34-
let driver = NIORedisDriver(ownershipModel: .internal(threadCount: 2))
35-
36-
let connection = try driver.makeConnection().wait()
35+
let connection = Redis.makeConnection(
36+
to: try .init(ipAddress: "127.0.0.1", port: 6379),
37+
password: "my_pass"
38+
).wait()
3739

3840
let result = try connection.set("my_key", to: "some value")
3941
.flatMap { return connection.get("my_key" }

Sources/NIORedis/Redis.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,30 @@ extension Redis {
4949
extension Redis {
5050
/// Makes a new connection to a Redis instance.
5151
///
52+
/// As soon as the connection has been opened on the host, an "AUTH" command will be sent to
53+
/// Redis to authorize use of additional commands on this new connection.
54+
///
55+
/// See [https://redis.io/commands/auth](https://redis.io/commands/auth)
56+
///
5257
/// Example:
5358
///
54-
/// let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
59+
/// let elg = MultiThreadedEventLoopGroup(numberOfThreads: 3)
5560
/// let connection = Redis.makeConnection(
5661
/// to: .init(ipAddress: "127.0.0.1", port: 6379),
57-
/// using: elg
62+
/// using: elg,
63+
/// password: "my_pass"
5864
/// )
5965
///
6066
/// - Parameters:
6167
/// - socket: The `SocketAddress` information of the Redis instance to connect to.
68+
/// - group: The `EventLoopGroup` to build the connection on. Default is a single threaded `EventLoopGroup`.
6269
/// - password: The optional password to authorize the client with.
63-
/// - eventLoopGroup: The `EventLoopGroup` to build the connection on.
6470
/// - logger: The `Logger` instance to log with.
6571
/// - Returns: A `RedisConnection` instance representing this new connection.
6672
public static func makeConnection(
6773
to socket: SocketAddress,
68-
using group: EventLoopGroup,
69-
with password: String? = nil,
74+
using group: EventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1),
75+
password: String? = nil,
7076
logger: Logger = Logger(label: "NIORedis.RedisConnection")
7177
) -> EventLoopFuture<RedisConnection> {
7278
let bootstrap = makeDefaultClientBootstrap(using: group)

Tests/NIORedisTests/Utilities/RedisConnection.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
extension Redis {
1818
static func makeConnection() throws -> EventLoopFuture<RedisConnection> {
19-
return Redis.makeConnection(
20-
to: try .init(ipAddress: "127.0.0.1", port: 6379),
21-
using: MultiThreadedEventLoopGroup(numberOfThreads: 1)
22-
)
19+
return Redis.makeConnection(to: try .init(ipAddress: "127.0.0.1", port: 6379))
2320
}
2421
}

0 commit comments

Comments
 (0)