Skip to content

Commit b96f64c

Browse files
committed
Update RedisClient.expire to no longer use deadline terminology.
Motivation: During proposal review, it was appropriately pointed out that `RedisClient.expire` incorrectly mixes 'deadline' and 'timeout' terminology. Modifications: - Change references of 'deadline' to 'timeout' to follow Redis' established semantics for 'EXPIRE' - Add additional unit test for `RedisClient.expire` Result: `RedisClient.expire` should now be more clear as to its semantics and not mix terminology incorrectly. This contributes to issue #47
1 parent c5241a4 commit b96f64c

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

Sources/RedisNIO/Commands/BasicCommands.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ extension RedisClient {
8484
/// [https://redis.io/commands/expire](https://redis.io/commands/expire)
8585
/// - Parameters:
8686
/// - key: The key to set the expiration on.
87-
/// - deadline: The time from now the key will expire at.
87+
/// - timeout: The time from now the key will expire at.
8888
/// - Returns: `true` if the expiration was set.
8989
@inlinable
90-
public func expire(_ key: String, after deadline: TimeAmount) -> EventLoopFuture<Bool> {
91-
let amount = deadline.nanoseconds / 1_000_000_000
90+
public func expire(_ key: String, after timeout: TimeAmount) -> EventLoopFuture<Bool> {
91+
let amount = timeout.nanoseconds / 1_000_000_000
9292
return send(command: "EXPIRE", with: [key, amount])
9393
.convertFromRESPValue(to: Int.self)
9494
.map { return $0 == 1 }

Tests/RedisNIOTests/Commands/BasicCommandsTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ final class BasicCommandsTests: XCTestCase {
6060

6161
func test_expire() throws {
6262
try connection.set(#function, to: "value").wait()
63-
let before = try connection.get(#function).wait()
64-
XCTAssertNotNil(before)
65-
66-
let result = try connection.expire(#function, after: .nanoseconds(1)).wait()
67-
XCTAssertEqual(result, true)
68-
69-
let after = try connection.get(#function).wait()
70-
XCTAssertNil(after)
63+
XCTAssertNotNil(try connection.get(#function).wait())
64+
XCTAssertTrue(try connection.expire(#function, after: .nanoseconds(1)).wait())
65+
XCTAssertNil(try connection.get(#function).wait())
66+
67+
try connection.set(#function, to: "new value").wait()
68+
XCTAssertNotNil(try connection.get(#function).wait())
69+
XCTAssertTrue(try connection.expire(#function, after: .seconds(10)).wait())
70+
XCTAssertNotNil(try connection.get(#function).wait())
7171
}
7272

7373
func test_ping() throws {

0 commit comments

Comments
 (0)