Skip to content

Commit b449334

Browse files
Daniel RamtekeMordil
authored andcommitted
[Commands] Add STRLEN
1 parent 8ff8b03 commit b449334

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Sources/RediStack/Commands/StringCommands.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ extension RedisCommand {
222222
]
223223
return .init(keyword: "SETNX", arguments: args)
224224
}
225+
226+
///[STRLEN](https://redis.io/commands/strln)
227+
/// - Parameter key: The key to fetch the length of.
228+
public static func strln(_ key: RedisKey) -> RedisCommand<Int> {
229+
.init(keyword: "STRLEN", arguments: [.init(from: key)])
230+
}
225231
}
226232

227233
// MARK: -

Tests/RediStackIntegrationTests/Commands/StringCommandsTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,10 @@ final class StringCommandsTests: RediStackIntegrationTestCase {
229229
result = try connection.send(.decrby(#function, by: 0)).wait()
230230
XCTAssertEqual(result, 7)
231231
}
232+
233+
func test_strlen() throws {
234+
XCTAssertNoThrow(try connection.set(#function, to: "value").wait())
235+
let val = try connection.send(.strln(#function)).wait()
236+
XCTAssertEqual(val, 5)
237+
}
232238
}

0 commit comments

Comments
 (0)