Skip to content

Commit 4694322

Browse files
Docc pipelining article (#126)
* Rename Returns to Response in function headers to avoid docc warnings Signed-off-by: Adam Fowler <[email protected]> * Add pipelining article, update index and README Signed-off-by: Adam Fowler <[email protected]> * PR comment Signed-off-by: Adam Fowler <[email protected]> * Update Sources/Valkey/Documentation.docc/index.md Co-authored-by: Fabian Fett <[email protected]> Signed-off-by: Adam Fowler <[email protected]> * Add async let section Signed-off-by: Adam Fowler <[email protected]> --------- Signed-off-by: Adam Fowler <[email protected]> Co-authored-by: Fabian Fett <[email protected]>
1 parent 4c650a7 commit 4694322

23 files changed

+781
-726
lines changed

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# valkey-swift
22

3-
Valkey client
3+
A Swift client library for Valkey.
44

55
## Usage
66

@@ -19,30 +19,32 @@ try await withThrowingTaskgroup(of: Void.self) { group in
1919

2020
Or you can use ValkeyClient with [swift-service-lifecycle](https://github.com/swift-server/swift-service-lifecycle).
2121

22-
Once you have a valkey client setup and running you can create connections to your Valkey database using `ValkeyClient.withConnection()`.
22+
Once you have a valkey client setup and running you can call valkey commands directly from the `ValkeyClient`.
2323

2424
```swift
25-
try await valkeyClient.withConnection { connection in
26-
try await doValkeyStuff()
27-
}
25+
try await valkeyClient.set(key: "foo", value: "bar")
2826
```
29-
30-
All the Valkey commands are in the Commands folder of the Valkey target. These are generated from the model files Valkey supplies in [valkey](https://github.com/valkey-io/valkey/src/commands). In many cases where it was possible to ascertain the return type of a command these functions will return that expected type. In situations where this is not possible (or we are returning a String) a `RESPToken` is returned and you'll need to convert it manually.
27+
Or you can create a connection and run multiple commands from that connection using `ValkeyClient.withConnection()`.
3128

3229
```swift
33-
try await connection.set(key: "MyKey", value: "TestString")
34-
let value = try await connection.get(key: "MyKey").decode(as: String.self)
30+
try await valkeyClient.withConnection { connection in
31+
try await connection.set(key: "foo1", value: "bar")
32+
try await connection.set(key: "foo2", value: "baz")
33+
}
3534
```
3635

36+
All the Valkey commands are in the Commands folder of the Valkey target. These are generated from the model files Valkey supplies in [valkey](https://github.com/valkey-io/valkey/src/commands). In many cases where it was possible to ascertain the return type of a command these functions will return that expected type. In situations where this is not possible we have either added a custom return type or a `RESPToken` is returned and you'll need to convert it manually.
37+
3738
### Pipelining commands
3839

3940
In some cases it is desirable to send multiple commands at one time, without waiting for the response after each command. This is called pipelining. You can do this using the function `pipeline(_:)`. This takes a parameter pack of commands and returns a parameter pack with the responses once all the commands have executed.
4041

4142
```swift
42-
let (setResponse, getResponse) = try await connection.pipeline(
43+
let (setResponse, getResponse) = await connection.pipeline(
4344
SET(key: "MyKey", value: "TestString"),
4445
GET(key: "MyKey")
4546
)
47+
let value = try getResponse.get()
4648
```
4749

4850
## Redis compatibilty

Sources/Valkey/Commands/BitmapCommands.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -471,24 +471,24 @@ public struct SETBIT: ValkeyCommand {
471471
extension ValkeyConnectionProtocol {
472472
/// Counts the number of set bits (population counting) in a string.
473473
///
474-
/// - Documentation: [BITCOUNT](https:/valkey.io/commands/bitcount)
474+
/// - Documentation: [BITCOUNT](https://valkey.io/commands/bitcount)
475475
/// - Available: 2.6.0
476476
/// - History:
477477
/// * 7.0.0: Added the `BYTE|BIT` option.
478478
/// * 8.0.0: `end` made optional; when called without argument the command reports the last BYTE.
479479
/// - Complexity: O(N)
480-
/// - Returns: [Integer]: The number of bits set to 1.
480+
/// - Response: [Integer]: The number of bits set to 1.
481481
@inlinable
482482
public func bitcount(key: ValkeyKey, range: BITCOUNT.Range? = nil) async throws -> Int {
483483
try await send(command: BITCOUNT(key: key, range: range))
484484
}
485485

486486
/// Performs arbitrary bitfield integer operations on strings.
487487
///
488-
/// - Documentation: [BITFIELD](https:/valkey.io/commands/bitfield)
488+
/// - Documentation: [BITFIELD](https://valkey.io/commands/bitfield)
489489
/// - Available: 3.2.0
490490
/// - Complexity: O(1) for each subcommand specified
491-
/// - Returns: One of the following
491+
/// - Response: One of the following
492492
/// * [Array]: The result of the subcommand at the same position
493493
/// * [Array]: In case OVERFLOW FAIL was given and overflows or underflows detected
494494
@inlinable
@@ -498,34 +498,34 @@ extension ValkeyConnectionProtocol {
498498

499499
/// Performs arbitrary read-only bitfield integer operations on strings.
500500
///
501-
/// - Documentation: [BITFIELD_RO](https:/valkey.io/commands/bitfield_ro)
501+
/// - Documentation: [BITFIELD_RO](https://valkey.io/commands/bitfield_ro)
502502
/// - Available: 6.0.0
503503
/// - Complexity: O(1) for each subcommand specified
504-
/// - Returns: [Array]: The result of the subcommand at the same position
504+
/// - Response: [Array]: The result of the subcommand at the same position
505505
@inlinable
506506
public func bitfieldRo(key: ValkeyKey, getBlock: [BITFIELDRO.GetBlock] = []) async throws -> [Int] {
507507
try await send(command: BITFIELDRO(key: key, getBlock: getBlock))
508508
}
509509

510510
/// Performs bitwise operations on multiple strings, and stores the result.
511511
///
512-
/// - Documentation: [BITOP](https:/valkey.io/commands/bitop)
512+
/// - Documentation: [BITOP](https://valkey.io/commands/bitop)
513513
/// - Available: 2.6.0
514514
/// - Complexity: O(N)
515-
/// - Returns: [Integer]: The size of the string stored in the destination key, that is equal to the size of the longest input string.
515+
/// - Response: [Integer]: The size of the string stored in the destination key, that is equal to the size of the longest input string.
516516
@inlinable
517517
public func bitop(operation: BITOP.Operation, destkey: ValkeyKey, key: [ValkeyKey]) async throws -> Int {
518518
try await send(command: BITOP(operation: operation, destkey: destkey, key: key))
519519
}
520520

521521
/// Finds the first set (1) or clear (0) bit in a string.
522522
///
523-
/// - Documentation: [BITPOS](https:/valkey.io/commands/bitpos)
523+
/// - Documentation: [BITPOS](https://valkey.io/commands/bitpos)
524524
/// - Available: 2.8.7
525525
/// - History:
526526
/// * 7.0.0: Added the `BYTE|BIT` option.
527527
/// - Complexity: O(N)
528-
/// - Returns: One of the following
528+
/// - Response: One of the following
529529
/// * [Integer]: The position of the first bit set to 1 or 0 according to the request.
530530
/// * -1: In case the `bit` argument is 1 and the string is empty or composed of just zero bytes.
531531
@inlinable
@@ -535,21 +535,21 @@ extension ValkeyConnectionProtocol {
535535

536536
/// Returns a bit value by offset.
537537
///
538-
/// - Documentation: [GETBIT](https:/valkey.io/commands/getbit)
538+
/// - Documentation: [GETBIT](https://valkey.io/commands/getbit)
539539
/// - Available: 2.2.0
540540
/// - Complexity: O(1)
541-
/// - Returns: The bit value stored at offset.
541+
/// - Response: The bit value stored at offset.
542542
@inlinable
543543
public func getbit(key: ValkeyKey, offset: Int) async throws -> Int {
544544
try await send(command: GETBIT(key: key, offset: offset))
545545
}
546546

547547
/// Sets or clears the bit at offset of the string value. Creates the key if it doesn't exist.
548548
///
549-
/// - Documentation: [SETBIT](https:/valkey.io/commands/setbit)
549+
/// - Documentation: [SETBIT](https://valkey.io/commands/setbit)
550550
/// - Available: 2.2.0
551551
/// - Complexity: O(1)
552-
/// - Returns: The original bit value stored at offset.
552+
/// - Response: The original bit value stored at offset.
553553
@inlinable
554554
public func setbit(key: ValkeyKey, offset: Int, value: Int) async throws -> Int {
555555
try await send(command: SETBIT(key: key, offset: offset, value: value))

0 commit comments

Comments
 (0)