mirror of
https://github.com/swift-server/RediStack.git
synced 2026-05-03 07:32:28 +00:00
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:
@@ -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"]
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user