Add static property for default RedisConnection port

Motivation:

The default port for Redis is well published to be 6379, and it is common to want to pass this value around or use it as a static default value in methods and initializers.

Modifications:

Add `RedisConnection.defaultPort` static property for all users to use, and update references of the `6379` literals to use new  the new property.

Result:

Users should have a reliable default defined to use everywhere to avoid bugs.
This commit is contained in:
Nathan Harris
2019-06-12 10:11:53 -07:00
parent 30733dea02
commit 73b3f5df32
4 changed files with 8 additions and 3 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ and run the following command: `swift package resolve`
import RedisNIO
let connection = Redis.makeConnection(
to: try .init(ipAddress: "127.0.0.1", port: 6379),
to: try .init(ipAddress: "127.0.0.1", port: RedisConnection.defaultPort),
password: "my_pass"
).wait()
+1 -1
View File
@@ -64,7 +64,7 @@ extension Redis {
///
/// let elg = MultiThreadedEventLoopGroup(numberOfThreads: 3)
/// let connection = Redis.makeConnection(
/// to: .init(ipAddress: "127.0.0.1", port: 6379),
/// to: .init(ipAddress: "127.0.0.1", port: RedisConnection.defaultPort),
/// using: elg,
/// password: "my_pass"
/// )
+2
View File
@@ -56,6 +56,8 @@ private let loggingKeyID = "RedisConnection"
///
/// See `RedisClient`
public final class RedisConnection: RedisClient {
public static let defaultPort = 6379
private enum ConnectionState {
case open
case closed
@@ -19,7 +19,10 @@ extension Redis {
static func makeConnection() throws -> EventLoopFuture<RedisConnection> {
let env = ProcessInfo.processInfo.environment
return Redis.makeConnection(
to: try .makeAddressResolvingHost(env["REDIS_URL"] ?? "127.0.0.1", port: 6379),
to: try .makeAddressResolvingHost(
env["REDIS_URL"] ?? "127.0.0.1",
port: RedisConnection.defaultPort
),
password: env["REDIS_PW"]
)
}