Commit b280af59 authored by Ondrej Rafaj's avatar Ondrej Rafaj Committed by Nathan Harris

Adding append

parent b5812484
......@@ -89,6 +89,20 @@ extension RedisClient {
.map { return $0 == 1 }
}
/// Append a value to the end of an existing entry
/// - 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.
///
/// [https://redis.io/commands/append](https://redis.io/commands/append)
/// - Parameters:
/// - key: The key to use to uniquely identify this value.
/// - value: The value to append the key to.
/// - Returns: Integer with the new length of the value
@inlinable
public func append(_ key: String, to value: RESPValueConvertible) -> EventLoopFuture<Int> {
return send(command: "APPEND", with: [key, value])
.convertFromRESPValue()
}
@usableFromInline
func _mset(
command: String,
......
......@@ -53,10 +53,21 @@ final class StringCommandsTests: XCTestCase {
XCTAssertEqual(try connection.mget(["empty", #function]).wait().count, 2)
}
func test_set() {
func test_set() throws {
XCTAssertNoThrow(try connection.set(#function, to: "value").wait())
let val = try connection.get(#function).wait()
XCTAssertEqual(val, "value")
}
func test_append() throws {
let result = "value appended"
XCTAssertNoThrow(try connection.append(#function, to: "value").wait())
let length = try connection.append(#function, to: " appended").wait()
XCTAssertEqual(length, result.count)
let val = try connection.get(#function).wait()
XCTAssertEqual(val, result)
}
func test_mset() throws {
let data = [
"first": 1,
......@@ -137,6 +148,7 @@ final class StringCommandsTests: XCTestCase {
("test_get", test_get),
("test_mget", test_mget),
("test_set", test_set),
("test_append", test_append),
("test_mset", test_mset),
("test_msetnx", test_msetnx),
("test_increment", test_increment),
......
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