Skip to content

Commit 1af3b24

Browse files
committed
Cleanup and add convienence init for RedisData
1 parent b5db463 commit 1af3b24

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/NIORedis/Data/RedisData.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public enum RedisData {
1010
case error(RedisError)
1111
case integer(Int)
1212
case array([RedisData])
13+
14+
/// Initializes a `bulkString` by converting the provided string input.
15+
public init(bulk: String) {
16+
self = .bulkString(Data(bulk.utf8))
17+
}
1318
}
1419

1520
extension RedisData: ExpressibleByStringLiteral {
@@ -43,7 +48,8 @@ extension RedisData: ExpressibleByIntegerLiteral {
4348
// Internal convienence computed properties
4449

4550
extension RedisData {
46-
/// Extracts the basic/bulk string as a `String`.
51+
/// Extracts the simple/bulk string as a `String`.
52+
/// - Note: This attempts to convert a `bulkString` to a `String` using UTF-8 encoding and may return nil.
4753
var string: String? {
4854
switch self {
4955
case .simpleString(let string): return string

0 commit comments

Comments
 (0)