-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
194 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Jimmy McDermott on 10/10/20. | ||
// | ||
|
||
import Foundation | ||
import Redis | ||
import NIO | ||
import Vapor | ||
|
||
struct SimpleRedisClient: RedisClient { | ||
let configuration: RedisConfiguration | ||
let eventLoopGroup: EventLoopGroup | ||
|
||
private struct PoolKey: StorageKey, LockKey { | ||
typealias Value = [EventLoop.Key: RedisConnectionPool] | ||
} | ||
|
||
// must be event loop from this app's elg | ||
internal func pool() -> RedisConnectionPool { | ||
let logger = Logger(label: "queues.progress.logger") | ||
return RedisConnectionPool( | ||
serverConnectionAddresses: configuration.serverAddresses, | ||
loop: eventLoop, | ||
maximumConnectionCount: configuration.pool.maximumConnectionCount, | ||
minimumConnectionCount: configuration.pool.minimumConnectionCount, | ||
connectionPassword: configuration.password, | ||
connectionLogger: logger, | ||
connectionTCPClient: nil, | ||
poolLogger: logger, | ||
connectionBackoffFactor: configuration.pool.connectionBackoffFactor, | ||
initialConnectionBackoffDelay: configuration.pool.initialConnectionBackoffDelay, | ||
connectionRetryTimeout: configuration.pool.connectionRetryTimeout | ||
) | ||
} | ||
|
||
func send(command: String, with arguments: [RESPValue]) -> EventLoopFuture<RESPValue> { | ||
self.pool().send(command: command, with: arguments) | ||
} | ||
|
||
public var eventLoop: EventLoop { | ||
self.eventLoopGroup.next() | ||
} | ||
|
||
public func logging(to logger: Logger) -> RedisClient { | ||
self | ||
} | ||
|
||
func unsubscribe(from channels: [RedisChannelName]) -> EventLoopFuture<Void> { | ||
eventLoop.future() | ||
} | ||
|
||
func punsubscribe(from patterns: [String]) -> EventLoopFuture<Void> { | ||
eventLoop.future() | ||
} | ||
} | ||
|
||
private extension EventLoop { | ||
typealias Key = ObjectIdentifier | ||
var key: Key { | ||
ObjectIdentifier(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
import Vapor | ||
import App | ||
import ConsoleKit | ||
import Foundation | ||
import NIO | ||
|
||
var env = try Environment.detect() | ||
try LoggingSystem.bootstrap(from: &env) | ||
let console: Console = Terminal() | ||
var input = CommandInput(arguments: CommandLine.arguments) | ||
var context = CommandContext(console: console, input: input) | ||
|
||
let app = Application(env) | ||
defer { app.shutdown() } | ||
app.commands.defaultCommand = ProgressCommand() | ||
app.commands.use(ProgressCommand(), as: "progress") | ||
try app.run() | ||
var commands = Commands(enableAutocomplete: false) | ||
commands.use(ProgressCommand(), as: "progress", isDefault: true) | ||
|
||
do { | ||
let group = commands.group(help: "A CLI for viewing data on your Redis queue jobs.") | ||
try console.run(group, input: input) | ||
} catch let error { | ||
console.error("\(error)") | ||
exit(1) | ||
} |