Skip to content

Commit 7758445

Browse files
authored
Valkey (#6)
1 parent bdf05d5 commit 7758445

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4433
-4449
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ concurrency:
1414
cancel-in-progress: true
1515

1616
env:
17-
REDIS_HOSTNAME: redis
17+
VALKEY_HOSTNAME: valkey
1818
jobs:
1919
linux:
2020
runs-on: ubuntu-latest
@@ -25,11 +25,11 @@ jobs:
2525
container:
2626
image: ${{ matrix.image }}
2727
services:
28-
redis:
29-
image: redis
28+
valkey:
29+
image: valkey/valkey:8.0
3030
ports:
3131
- 6379:6379
32-
options: --entrypoint redis-server
32+
options: --entrypoint valkey-server
3333
steps:
3434
- name: Checkout
3535
uses: actions/checkout@v4
@@ -39,7 +39,7 @@ jobs:
3939
- name: Convert coverage files
4040
run: |
4141
llvm-cov export -format="lcov" \
42-
.build/debug/swift-redisPackageTests.xctest \
42+
.build/debug/swift-valkeyPackageTests.xctest \
4343
-ignore-filename-regex="\/Tests\/" \
4444
-instr-profile .build/debug/codecov/default.profdata > info.lcov
4545
- name: Upload to codecov.io

Package.swift

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "swift-redis",
7+
name: "swift-valkey",
88
platforms: [.macOS(.v13)],
99
products: [
10-
.library(name: "Redis", targets: ["Redis"]),
11-
.library(name: "RedisCommands", targets: ["RedisCommands"]),
10+
.library(name: "Valkey", targets: ["Valkey"])
1211
],
1312
dependencies: [
1413
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
@@ -18,7 +17,7 @@ let package = Package(
1817
],
1918
targets: [
2019
.target(
21-
name: "Redis",
20+
name: "Valkey",
2221
dependencies: [
2322
.product(name: "Logging", package: "swift-log"),
2423
.product(name: "NIOCore", package: "swift-nio"),
@@ -27,25 +26,18 @@ let package = Package(
2726
.product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
2827
]
2928
),
30-
.target(
31-
name: "RedisCommands",
32-
dependencies: [
33-
"Redis",
34-
.product(name: "NIOCore", package: "swift-nio"),
35-
]
36-
),
3729
.executableTarget(
38-
name: "RedisCommandsBuilder",
30+
name: "ValkeyCommandsBuilder",
3931
resources: [.process("Resources")]
4032
),
4133
.testTarget(
42-
name: "RedisTests",
43-
dependencies: ["Redis", "RedisCommands"]
34+
name: "ValkeyTests",
35+
dependencies: ["Valkey"]
4436
),
4537
.testTarget(
4638
name: "RESPTests",
4739
dependencies: [
48-
"Redis",
40+
"Valkey",
4941
.product(name: "NIOTestUtils", package: "swift-nio"),
5042
]
5143
),

README.md

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,37 @@
1-
# Redis
1+
# Valkey
22

3-
Redis client.
3+
Valkey client.
44

55
This is currently in an unfinished state. It has no connection manager so there is no support for connection reuse.
66

77
## Usage
88

9-
To create a connection to Redis database you use `RedisClient.withConnection()`.
9+
To create a connection to Valkey database you use `ValkeyClient.withConnection()`.
1010

1111
```swift
12-
try await RedisClient.withConnection(.hostname("localhost", port: 6379), logger: logger) { connection, logger in
13-
try await doRedisStuff()
12+
try await ValkeyClient.withConnection(.hostname("localhost", port: 6379), logger: logger) { connection, logger in
13+
try await doValkeyStuff()
1414
}
1515
```
1616

17-
Swift-redis has three ways to send commands.
18-
19-
### Raw
20-
21-
You can send raw commands using `RedisConnection.send()`. This takes a parameter pack of types that conform to `RESPRenderable`. These includes `Int`, `String`, `Double`, `RedisKey` and then `Optional` and `Array` where the internal type is also `RedisRenderable`. For example to set a value you can call
22-
23-
```swift
24-
let key = RedisKey(rawValue: "MyKey")
25-
try await connection.send("SET", key, "TestString")
26-
```
27-
28-
A raw send will return a `RESPToken`. This can be converted to any value that conforms to `RESPTokenRepresentable`. As with `RESPRenderable` these covers many standard types. You can convert from a `RESPToken` to `RESPTokenRepresentable` type by either using the constructor `init(from: RESPToken)` or the function `converting(to:)`.
29-
30-
```swift
31-
let response = try await connection.send("GET", key)
32-
let value = try response.converting(to: String.self)
33-
// you could also use `let value = String(from: response)`
34-
```
35-
36-
### Using generated functions
37-
38-
Swift-redis includes a separate module `RedisCommands` that includes functions for all the redis commands. These are generated from the model files redis supplies in [redis-doc](https://github.com/redis/redis-doc). Instead of searching up in the documentation how a command is structured. You can just call a Swift function. In many cases where it is possible the return type from these functions is the set to the be the expected type. In situations where the type cannot be ascertained a `RESPToken` is returned and you'll need to convert the return type manually.
39-
40-
With the generated functions the code above becomes
17+
All the Valkey commands are in the Commands folder of the Valkey target. These are generated from the model files Valkey supplies in [valkey-doc](https://github.com/valkey-io/valkey-doc). 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 a `RESPToken` is returned and you'll need to convert the return type manually.
4118

4219
```swift
43-
let key = RedisKey(rawValue: "MyKey")
44-
try await connection.set(key, "TestString")
20+
try await connection.set("MyKey", "TestString")
4521
let value = try await connection.get(key)
4622
```
4723

48-
### Using generated RESPCommands and pipelining
24+
### Pipelining commands
4925

50-
In general you don't need to use this method as it has no advantages over using the generated functions. But `RESPCommands` has a function for each Redis command. Where the generated `RESPCommands` are useful is if you want to pipeline commands ie send multiple commands batched together and only wait for all of their responses in one place. You could pipeline the two commands above using
26+
In some cases it desirable to send multiple commands at one time, without waiting for each 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.
5127

5228
```swift
53-
let key = RedisKey(rawValue: "MyKey")
5429
let (setResponse, getResponse) = try await connection.pipeline(
55-
SET(key, "TestString"),
56-
GET(key)
30+
SET("MyKey", "TestString"),
31+
GET("MyKey")
5732
)
5833
```
34+
35+
## Redis compatibilty
36+
37+
As Valkey is a fork of Redis v7.2.4, swift-valkey is compatible with Redis databases up to v7.2.4. There is a chance the v7.2.4 features will still be compatible in later versions of Redis, but these are now considered two different projects and they will diverge. Swift-valkey uses the RESP3 protocol. It does not support RESP2.

0 commit comments

Comments
 (0)