Skip to content

Commit 0facb90

Browse files
committed
Merge branch 'append' into 'master'
Adding append See merge request Mordil/swift-redis-nio-client!61
2 parents b581248 + b280af5 commit 0facb90

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

Sources/RedisNIO/Commands/StringCommands.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ extension RedisClient {
8989
.map { return $0 == 1 }
9090
}
9191

92+
/// Append a value to the end of an existing entry
93+
/// - Note: If the key does not exist it is created and set as an empty string, so APPEND will be similar to SET in this special case.
94+
///
95+
/// [https://redis.io/commands/append](https://redis.io/commands/append)
96+
/// - Parameters:
97+
/// - key: The key to use to uniquely identify this value.
98+
/// - value: The value to append the key to.
99+
/// - Returns: Integer with the new length of the value
100+
@inlinable
101+
public func append(_ key: String, to value: RESPValueConvertible) -> EventLoopFuture<Int> {
102+
return send(command: "APPEND", with: [key, value])
103+
.convertFromRESPValue()
104+
}
105+
92106
@usableFromInline
93107
func _mset(
94108
command: String,

Tests/RedisNIOTests/Commands/StringCommandsTests.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,21 @@ final class StringCommandsTests: XCTestCase {
5353
XCTAssertEqual(try connection.mget(["empty", #function]).wait().count, 2)
5454
}
5555

56-
func test_set() {
56+
func test_set() throws {
5757
XCTAssertNoThrow(try connection.set(#function, to: "value").wait())
58+
let val = try connection.get(#function).wait()
59+
XCTAssertEqual(val, "value")
5860
}
59-
61+
62+
func test_append() throws {
63+
let result = "value appended"
64+
XCTAssertNoThrow(try connection.append(#function, to: "value").wait())
65+
let length = try connection.append(#function, to: " appended").wait()
66+
XCTAssertEqual(length, result.count)
67+
let val = try connection.get(#function).wait()
68+
XCTAssertEqual(val, result)
69+
}
70+
6071
func test_mset() throws {
6172
let data = [
6273
"first": 1,
@@ -137,6 +148,7 @@ final class StringCommandsTests: XCTestCase {
137148
("test_get", test_get),
138149
("test_mget", test_mget),
139150
("test_set", test_set),
151+
("test_append", test_append),
140152
("test_mset", test_mset),
141153
("test_msetnx", test_msetnx),
142154
("test_increment", test_increment),

0 commit comments

Comments
 (0)