Skip to content
Open
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
25 changes: 25 additions & 0 deletions Sources/Valkey/Commands/Custom/GenericCustomCommands.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// This source file is part of the valkey-swift project
// Copyright (c) 2025 the valkey-swift project authors
//
// See LICENSE.txt for license information
// SPDX-License-Identifier: Apache-2.0
//
import NIOCore

extension SCAN {
public struct Response: RESPTokenDecodable, Sendable {
public let cursor: Int
public let keys: [ValkeyKey]

public init(fromRESP token: RESPToken) throws {
let (cursor, keys) = try token.decodeArrayElements(as: (Int, [ValkeyKey]).self)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use (self.cursor, self.keys) = .... You don't need the temporary variables.

self.cursor = cursor
self.keys = keys
}
}
}

extension KEYS {
public typealias Response = [ValkeyKey]
}
8 changes: 2 additions & 6 deletions Sources/Valkey/Commands/GenericCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@ public struct EXPIRETIME: ValkeyCommand {
/// Returns all key names that match a pattern.
@_documentation(visibility: internal)
public struct KEYS: ValkeyCommand {
public typealias Response = RESPToken.Array

@inlinable public static var name: String { "KEYS" }

public var pattern: String
Expand Down Expand Up @@ -740,8 +738,6 @@ public struct RESTORE<SerializedValue: RESPStringRenderable>: ValkeyCommand {
/// Iterates over the key names in the database.
@_documentation(visibility: internal)
public struct SCAN: ValkeyCommand {
public typealias Response = RESPToken.Array

@inlinable public static var name: String { "SCAN" }

public var cursor: Int
Expand Down Expand Up @@ -1168,7 +1164,7 @@ extension ValkeyClientProtocol {
/// - Complexity: O(N) with N being the number of keys in the database, under the assumption that the key names in the database and the given pattern have limited length.
/// - Response: [Array]: List of keys matching pattern.
@inlinable
public func keys(pattern: String) async throws -> RESPToken.Array {
public func keys(pattern: String) async throws -> KEYS.Response {
try await execute(KEYS(pattern: pattern))
}

Expand Down Expand Up @@ -1433,7 +1429,7 @@ extension ValkeyClientProtocol {
/// - Complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection.
/// - Response: [Array]: Cursor and scan response in array form.
@inlinable
public func scan(cursor: Int, pattern: String? = nil, count: Int? = nil, type: String? = nil) async throws -> RESPToken.Array {
public func scan(cursor: Int, pattern: String? = nil, count: Int? = nil, type: String? = nil) async throws -> SCAN.Response {
try await execute(SCAN(cursor: cursor, pattern: pattern, count: count, type: type))
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Valkey/Documentation.docc/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ You can use the `add-dependency` command:

```bash
swift package add-dependency \
https://github.com/valkey-io/valkey-swift --from: 0.1.0
https://github.com/valkey-io/valkey-swift --from: 0.3.0
```

or edit Package.swift directly:
```swift
dependencies: [
.package(url: "https://github.com/valkey-io/valkey-swift",
from: "0.1.0"),
from: "0.3.0"),
]
```

Expand Down Expand Up @@ -58,7 +58,7 @@ You can either run them using a Task group, for example:

```swift
let valkeyClient = ValkeyClient(.hostname("localhost", port: 6379), logger: logger)
try await withThrowingTaskgroup(of: Void.self) { group in
try await withThrowingTaskGroup(of: Void.self) { group in
group.addTask {
// run connection pool in the background
await valkeyClient.run()
Expand Down
6 changes: 5 additions & 1 deletion Sources/_ValkeyCommandsBuilder/ValkeyCommandsRender.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ private let disableResponseCalculationCommands: Set<String> = [
"GEODIST",
"GEOPOS",
"GEOSEARCH",
"ROLE",
"KEYS",
"LMOVE",
"LMPOP",
"ROLE",
"SCAN",
"SSCAN",
"XAUTOCLAIM",
"XCLAIM",
Expand All @@ -36,6 +38,7 @@ private let disableResponseCalculationCommands: Set<String> = [
"ZPOPMAX",
"ZPOPMIN",
]

/// List of subscribe commands, which have their own implementation in code
let subscribeFunctions: Set<String> = [
"SUBSCRIBE",
Expand All @@ -45,6 +48,7 @@ let subscribeFunctions: Set<String> = [
"PUNSUBSCRIBE",
"SUNSUBSCRIBE",
]

/// List of commands that should only be available from ValkeyConnection
let connectionOnlyFunctionNames: Set<String> = [
"MULTI",
Expand Down
Loading