Skip to content

Commit eaab8d7

Browse files
authored
Merge pull request #4 from scuml/username-auth
Adds AUTH by username and redis.disconnect()
2 parents f0618d2 + 0592ca3 commit eaab8d7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Sources/SwiftRedis/Redis.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public class Redis {
4848
callback(nil)
4949
}
5050
}
51+
52+
public func disconnect(){
53+
respHandle?.disconnect()
54+
}
5155

5256
/// Authenticate against the server
5357
///
@@ -61,7 +65,18 @@ public class Redis {
6165
callback(error)
6266
}
6367
}
64-
68+
69+
public func auth(_ username: String, _ pswd: String, callback: (NSError?) -> Void) {
70+
if username == "" {
71+
return auth(pswd, callback: callback)
72+
}
73+
issueCommand("AUTH", username, pswd) {(response: RedisResponse) in
74+
let (_, error) = self.redisOkResponseHandler(response, nilOk: false)
75+
callback(error)
76+
}
77+
}
78+
79+
6580
/// Select the database to use
6681
///
6782
/// - Parameter db: numeric index for the database.

Sources/SwiftRedis/RedisResp.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public class RedisResp {
4646
try? socket?.connect(to: host, port: port)
4747
}
4848

49+
func disconnect(){
50+
socket?.close()
51+
}
52+
4953
func issueCommand(_ stringArgs: [String], callback: (RedisResponse) -> Void) {
5054
guard let socket = socket else { return }
5155

0 commit comments

Comments
 (0)