Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions Sources/Valkey/Commands/Custom/ClusterCustomCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public struct ValkeyClusterDescription: Hashable, Sendable, RESPTokenDecodable {

/// Creates a cluster description from the response token you provide.
/// - Parameter respToken: The response token.
public init(fromRESP respToken: RESPToken) throws {
public init(_ respToken: RESPToken) throws {
self = try Self.makeClusterDescription(respToken: respToken)
}

Expand Down Expand Up @@ -264,7 +264,7 @@ public struct ValkeyClusterLink: Hashable, Sendable, RESPTokenDecodable {

/// Creates a cluster link from the response token you provide.
/// - Parameter respToken: The response token.
public init(fromRESP respToken: RESPToken) throws {
public init(_ respToken: RESPToken) throws {
self = try Self.makeClusterLink(respToken: respToken)
}

Expand All @@ -275,7 +275,7 @@ public struct ValkeyClusterLink: Hashable, Sendable, RESPTokenDecodable {

case .map(let map):
let mapped = map.lazy.compactMap { (keyNode, value) -> (String, RESPToken)? in
if let key = try? String(fromRESP: keyNode) {
if let key = try? String(keyNode) {
return (key, value)
} else {
return nil
Expand All @@ -302,27 +302,27 @@ public struct ValkeyClusterLink: Hashable, Sendable, RESPTokenDecodable {
for (key, value) in sequence {
switch key {
case "direction":
guard let directionString = try? String(fromRESP: value),
guard let directionString = try? String(value),
let directionValue = ValkeyClusterLink.Direction(rawValue: directionString)
else {
throw RESPDecodeError.missingToken(key: "direction", token: respToken)
}
direction = directionValue

case "node":
node = try? String(fromRESP: value)
node = try? String(value)

case "create-time":
createTime = try? Int64(fromRESP: value)
createTime = try? Int64(value)

case "events":
events = try? String(fromRESP: value)
events = try? String(value)

case "send-buffer-allocated":
sendBufferAllocated = try? Int64(fromRESP: value)
sendBufferAllocated = try? Int64(value)

case "send-buffer-used":
sendBufferUsed = try? Int64(fromRESP: value)
sendBufferUsed = try? Int64(value)

default:
// ignore unexpected keys for forward compatibility
Expand Down Expand Up @@ -379,7 +379,7 @@ public struct ValkeyClusterSlotStats: Hashable, Sendable, RESPTokenDecodable {

/// Creates a cluster slot stats from the response token you provide.
/// - Parameter respToken: The response token.
public init(fromRESP respToken: RESPToken) throws {
public init(_ respToken: RESPToken) throws {
self = try Self.makeClusterSlotStats(respToken: respToken)
}

Expand Down Expand Up @@ -419,7 +419,7 @@ public struct ValkeyClusterSlotStats: Hashable, Sendable, RESPTokenDecodable {
case .map(let map):
// For RESP3, handle RESPToken stats as map
let mapped = map.lazy.compactMap { (keyNode, value) -> (String, RESPToken)? in
if let key = try? String(fromRESP: keyNode) {
if let key = try? String(keyNode) {
return (key, value)
} else {
return nil
Expand All @@ -428,16 +428,16 @@ public struct ValkeyClusterSlotStats: Hashable, Sendable, RESPTokenDecodable {
for (key, value) in mapped {
switch key {
case "key-count":
keyCount = try? Int64(fromRESP: value)
keyCount = try? Int64(value)

case "cpu-usec":
cpuUsec = try? Int64(fromRESP: value)
cpuUsec = try? Int64(value)

case "network-bytes-in":
networkBytesIn = try? Int64(fromRESP: value)
networkBytesIn = try? Int64(value)

case "network-bytes-out":
networkBytesOut = try? Int64(fromRESP: value)
networkBytesOut = try? Int64(value)

default:
// ignore unexpected keys for forward compatibility
Expand All @@ -451,16 +451,16 @@ public struct ValkeyClusterSlotStats: Hashable, Sendable, RESPTokenDecodable {
for (key, valueToken) in mapArray {
switch key {
case "key-count":
keyCount = try? Int64(fromRESP: valueToken)
keyCount = try? Int64(valueToken)

case "cpu-usec":
cpuUsec = try? Int64(fromRESP: valueToken)
cpuUsec = try? Int64(valueToken)

case "network-bytes-in":
networkBytesIn = try? Int64(fromRESP: valueToken)
networkBytesIn = try? Int64(valueToken)

case "network-bytes-out":
networkBytesOut = try? Int64(fromRESP: valueToken)
networkBytesOut = try? Int64(valueToken)

default:
// ignore unexpected keys for forward compatibility
Expand Down Expand Up @@ -536,7 +536,7 @@ public struct ValkeyClusterSlotRange: Hashable, Sendable, RESPTokenDecodable {

/// Creates a cluster slot range from the response token you provide.
/// - Parameter respToken: The response token.
public init(fromRESP respToken: RESPToken) throws {
public init(_ respToken: RESPToken) throws {
self = try Self.makeClusterSlotRange(respToken: respToken)
}

Expand Down Expand Up @@ -639,7 +639,7 @@ extension ValkeyClusterDescription.Shard {

case .map(let map):
let mapped = map.lazy.compactMap { (keyNode, value) -> (String, RESPToken)? in
if let key = try? String(fromRESP: keyNode) {
if let key = try? String(keyNode) {
return (key, value)
} else {
return nil
Expand Down Expand Up @@ -692,7 +692,7 @@ extension ValkeyClusterDescription.Node {

case .map(let map):
let mapped = map.lazy.compactMap { (keyNode, value) -> (String, RESPToken)? in
if let key = try? String(fromRESP: keyNode) {
if let key = try? String(keyNode) {
return (key, value)
} else {
return nil
Expand Down Expand Up @@ -736,27 +736,27 @@ extension ValkeyClusterDescription.Node {
while let (key, nodeVal) = nodeIterator.next() {
switch key {
case "id":
id = try? String(fromRESP: nodeVal)
id = try? String(nodeVal)
case "port":
port = try? Int64(fromRESP: nodeVal)
port = try? Int64(nodeVal)
case "tls-port":
tlsPort = try? Int64(fromRESP: nodeVal)
tlsPort = try? Int64(nodeVal)
case "ip":
ip = try? String(fromRESP: nodeVal)
ip = try? String(nodeVal)
case "hostname":
hostname = try? String(fromRESP: nodeVal)
hostname = try? String(nodeVal)
case "endpoint":
endpoint = try? String(fromRESP: nodeVal)
endpoint = try? String(nodeVal)
case "role":
guard let roleString = try? String(fromRESP: nodeVal), let roleValue = ValkeyClusterDescription.Node.Role(rawValue: roleString) else {
guard let roleString = try? String(nodeVal), let roleValue = ValkeyClusterDescription.Node.Role(rawValue: roleString) else {
throw .decodeError(RESPDecodeError(.unexpectedToken, token: nodeVal, message: "Invalid Role String"))
}
role = roleValue

case "replication-offset":
replicationOffset = try? Int64(fromRESP: nodeVal)
replicationOffset = try? Int64(nodeVal)
case "health":
guard let healthString = try? String(fromRESP: nodeVal),
guard let healthString = try? String(nodeVal),
let healthValue = ValkeyClusterDescription.Node.Health(rawValue: healthString)
else {
throw .decodeError(RESPDecodeError(.unexpectedToken, token: nodeVal, message: "Invalid Node Health String"))
Expand Down Expand Up @@ -808,7 +808,7 @@ extension ValkeyClusterSlotRange.Node {

// First element: IP address
guard let ipToken = iterator.next(),
let ip = try? String(fromRESP: ipToken)
let ip = try? String(ipToken)
else {
throw RESPDecodeError.missingToken(key: "ip", token: respToken)
}
Expand All @@ -823,7 +823,7 @@ extension ValkeyClusterSlotRange.Node {

// Third element: node ID
guard let nodeIdToken = iterator.next(),
let nodeId = try? String(fromRESP: nodeIdToken)
let nodeId = try? String(nodeIdToken)
else {
throw RESPDecodeError.missingToken(key: "node id", token: respToken)
}
Expand All @@ -836,8 +836,8 @@ extension ValkeyClusterSlotRange.Node {
case .map(let map):
// Handle metadata as a map
for (keyToken, valueToken) in map {
if let key = try? String(fromRESP: keyToken),
let value = try? String(fromRESP: valueToken)
if let key = try? String(keyToken),
let value = try? String(valueToken)
{
metadata[key] = value
}
Expand All @@ -849,7 +849,7 @@ extension ValkeyClusterSlotRange.Node {
// Handle metadata as key-value pairs in array format (using MapStyleArray)
let mapArray = MapStyleArray(underlying: array)
for (key, valueToken) in mapArray {
if let value = try? String(fromRESP: valueToken) {
if let value = try? String(valueToken) {
metadata[key] = value
}
}
Expand Down Expand Up @@ -879,7 +879,7 @@ struct MapStyleArray: Sequence {

mutating func next() -> (String, RESPToken)? {
guard let nodeKey = self.underlying.next(),
let key = try? String(fromRESP: nodeKey),
let key = try? String(nodeKey),
let nodeVal = self.underlying.next()
else {
return nil
Expand Down
2 changes: 1 addition & 1 deletion Sources/Valkey/Commands/Custom/GenericCustomCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension SCAN {
public let cursor: Int
public let keys: RESPToken.Array

public init(fromRESP token: RESPToken) throws {
public init(_ token: RESPToken) throws {
(self.cursor, self.keys) = try token.decodeArrayElements(as: (Int, RESPToken.Array).self)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Valkey/Commands/Custom/GeoCustomCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct GeoCoordinates: RESPTokenDecodable, Sendable {
public let longitude: Double
public let latitude: Double

public init(fromRESP token: RESPToken) throws {
public init(_ token: RESPToken) throws {
(self.longitude, self.latitude) = try token.decodeArrayElements()
}
}
Expand Down Expand Up @@ -41,14 +41,14 @@ extension GEOSEARCH {
public let member: String
public let attributes: [RESPToken]

public init(fromRESP token: RESPToken) throws {
public init(_ token: RESPToken) throws {
switch token.value {
case .array(let array):
var arrayIterator = array.makeIterator()
guard let member = arrayIterator.next() else {
throw RESPDecodeError.invalidArraySize(array, expectedSize: 1)
}
self.member = try String(fromRESP: member)
self.member = try String(member)
self.attributes = array.dropFirst().map { $0 }

case .bulkString(let buffer):
Expand Down
22 changes: 11 additions & 11 deletions Sources/Valkey/Commands/Custom/HashCustomCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct HashEntry: RESPTokenDecodable, Sendable {
self.value = value
}

public init(fromRESP token: RESPToken) throws {
public init(_ token: RESPToken) throws {
switch token.value {
case .array(let array):
(self.field, self.value) = try array.decodeElements()
Expand All @@ -34,7 +34,7 @@ extension HSCAN {
/// List of members and possibly scores.
public let elements: RESPToken.Array

public init(fromRESP token: RESPToken) throws {
public init(_ token: RESPToken) throws {
self.elements = try token.decode(as: RESPToken.Array.self)
}

Expand All @@ -49,8 +49,8 @@ extension HSCAN {
public func withValues() throws -> [HashEntry] {
var array: [HashEntry] = []
for respElement in try self.elements.asMap() {
let field = try RESPBulkString(fromRESP: respElement.key)
let value = try RESPBulkString(fromRESP: respElement.value)
let field = try RESPBulkString(respElement.key)
let value = try RESPBulkString(respElement.value)
array.append(.init(field: field, value: value))
}
return array
Expand All @@ -61,7 +61,7 @@ extension HSCAN {
/// Sorted set members
public let members: Members

public init(fromRESP token: RESPToken) throws {
public init(_ token: RESPToken) throws {
(self.cursor, self.members) = try token.decodeArrayElements()
}
}
Expand All @@ -73,7 +73,7 @@ extension HRANDFIELD {
/// The raw RESP token containing the response
public let token: RESPToken

public init(fromRESP token: RESPToken) throws {
public init(_ token: RESPToken) throws {
self.token = token
}

Expand All @@ -85,15 +85,15 @@ extension HRANDFIELD {
if token.value == .null {
return nil
}
return try RESPBulkString(fromRESP: token)
return try RESPBulkString(token)
}

/// Get multiple random fields when HRANDFIELD was called with COUNT but without WITHVALUES
/// - Returns: Array of field names as RESPBulkString, or empty array if key doesn't exist
/// - Throws: RESPDecodeError if response format is unexpected
@inlinable
public func multipleFields() throws -> [RESPBulkString]? {
try [RESPBulkString]?(fromRESP: token)
try [RESPBulkString]?(token)
}

/// Get multiple random field-value pairs when HRANDFIELD was called with COUNT and WITHVALUES
Expand All @@ -116,7 +116,7 @@ extension HRANDFIELD {
switch firstElement.value {
case .array:
// Array of arrays format - can use HashEntry decode
return try [HashEntry]?(fromRESP: token)
return try [HashEntry]?(token)
default:
// Flat array format - handle manually
return try _decodeFlatArrayFormat(array)
Expand All @@ -141,8 +141,8 @@ extension HRANDFIELD {
// Iterate over pairs
var iterator = array.makeIterator()
while let field = iterator.next(), let value = iterator.next() {
let fieldBuffer = try RESPBulkString(fromRESP: field)
let valueBuffer = try RESPBulkString(fromRESP: value)
let fieldBuffer = try RESPBulkString(field)
let valueBuffer = try RESPBulkString(value)
entries.append(HashEntry(field: fieldBuffer, value: valueBuffer))
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Valkey/Commands/Custom/ListCustomCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct ListEntry: RESPTokenDecodable, Sendable {
public let key: ValkeyKey
public let value: RESPBulkString

public init(fromRESP token: RESPToken) throws {
public init(_ token: RESPToken) throws {
(self.key, self.value) = try token.decodeArrayElements()
}
}
Expand All @@ -31,7 +31,7 @@ extension LMPOP {
public let key: ValkeyKey
public let values: RESPToken.Array

public init(fromRESP token: RESPToken) throws {
public init(_ token: RESPToken) throws {
switch token.value {
case .array(let array):
(self.key, self.values) = try array.decodeElements()
Expand Down
Loading
Loading