Commit 73b3f5df authored by Nathan Harris's avatar Nathan Harris

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.
parent 30733dea
Pipeline #65918148 passed with stages
in 6 minutes and 30 seconds
......@@ -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()
......
......@@ -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"
/// )
......
......@@ -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"]
)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment