Valkey is an open source, in-memory data structure store, used as a database, cache, and message broker.
This is the Hummingbird interface to the valkey-swift library a Swift driver for Valkey/Redis. Currently HummingbirdValkey consists of driver for the Hummingbird persist framework.
import Hummingbird
import HummingbirdValkey
let valkey = ValkeyClient(.hostname(valkeyHostname, port: 6379), logger: Logger(label: "Valkey"))
let persist = ValkeyPersistDriver(client: valkeyClient)
// create router and add a GET /valkey/{key} and PUT /valkey/{key} routes
let router = Router()
router.get("valkey/{key}") { request, context -> String? in
let key = try context.parameters.require("key")
return try await persist.get(key: .init(key), as: String.self)
}
router.put("valkey/{key}") { request, context in
let key = try context.parameters.require("key")
let value = try request.uri.queryParameters.require("value")
try await persist.set(key: key, value: value)
return HTTPResponse.Status.ok
}
// create application using router
var app = Application(
router: router,
configuration: .init(address: .hostname("127.0.0.1", port: 8080))
)
app.addServices(valkey)
// run hummingbird application
try await app.runService()
Reference documentation for HummingbirdValkey can be found here