Skip to content

Commit

Permalink
Update Readme and Tweak Redis.makeConnection(...)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mordil committed May 2, 2019
1 parent c7a606d commit 0131fe4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@

# 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

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)

```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")
]
```

Expand All @@ -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" }
Expand Down
16 changes: 11 additions & 5 deletions Sources/NIORedis/Redis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<RedisConnection> {
let bootstrap = makeDefaultClientBootstrap(using: group)
Expand Down
5 changes: 1 addition & 4 deletions Tests/NIORedisTests/Utilities/RedisConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

extension Redis {
static func makeConnection() throws -> EventLoopFuture<RedisConnection> {
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))
}
}

0 comments on commit 0131fe4

Please sign in to comment.