mirror of
https://github.com/swift-server/RediStack.git
synced 2026-06-02 07:37:33 +00:00
Adding append
This commit is contained in:
committed by
Nathan Harris
parent
b5812484e4
commit
b280af596d
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user