Compatibility
- 0.1.0 and master5.35.25.15.04.2
- 0.1.0 and masteriOSmacOS(Intel)macOS(ARM)LinuxtvOSwatchOS
📮 Non-blocking, event-driven Swift client for Disque, a distributed job queue.
A non-blocking, event-driven Swift client for Disque, shamelessly copied built on Vapor's Redis client. Disque is a distributed job queue created by Salvatore Sanfilippo (@antirez) "forked" off of Redis.
GETJOB
command. Disque will search for jobs from the defined queues starting first with the left-most queue simulating job priority.1. Start a Disque container using Docker or follow Disque's installation instructions.
docker run -d --rm -p 7711:7711 --name disque efrecon/disque:1.0-rc1
2 Add the dependency to Package.swift.
.package(url: "https://github.com/johnbona/disque", from: "0.1.0")
3. Register the provider and config in configure.swift
.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services ) throws {
// ...
try services.register(DisqueProvider())
var databases = DatabasesConfig()
let disqueConfig = DisqueDatabase(config: DisqueClientConfig())
databases.add(database: disqueConfig, as: .disque)
services.register(databases)
}
4. Fetch a connection from the connection pool and use the Disque client.
return req.withPooledConnection(to: .disque) { disque -> Future<[Job<TestJob>]> in
return disque.get(count: 1, from: ["test-queue"], as: TestJob.self)
}
All of Disque's commands (except for HELLO
, QPEEK
, QSCAN
, JSCAN
) are implemented in Swift with job bodies conforming to Codable
.
return req.withPooledConnection(to: .disque) { disque -> Future<[Job<TestJob>]> in
return disque.get(count: 1, from: ["test-queue"], as: TestJob.self)
}
return req.withPooledConnection(to: .disque) { disque -> Future<[Job<TestJob>]> in
return disque.get(count: 1, from: ["high-priority", "low-priority"], as: TestJob.self)
}
req.withPooledConnection(to: .disque) { disque -> Future<String> in
return try disque.add(job: TestJob(), to: "test-queue")
}
req.withPooledConnection(to: .disque) { disque -> Future<Int> in
return try disque.ack(jobIDs: ["D-00000000-000000000000000000000000-0000"])
}
Disque is released under the MIT License.