Commit 26057638 authored by Nathan Harris's avatar Nathan Harris

Rename `RedisCommand` properties to avoid overloading terms and being more specific.

Motivation:

There are several cases where "command" could refer to a command keyword, or an entire message (keyword + args). This made working with `RedisCommand` and it's documentation ambiguous.

Modifications:

- Rename `RedisCommand.command` to `message`
- Rename initializer labels to `message` and `responsePromise`

Result:

When encountering a `RedisCommand` everyone should know that they are dealing with a message that should be sent to Redis as soon as possible.
parent 04aa1f93
Pipeline #70021734 passed with stages
in 6 minutes and 41 seconds
......@@ -18,17 +18,16 @@ import NIO
/// The `NIO.ChannelOutboundHandler.OutboundIn` type for `RedisCommandHandler`.
///
/// This holds the command and its arguments stored as a single `RESPValue` to be sent to Redis,
/// and an `NIO.EventLoopPromise` to be fulfilled when a response has been received.
/// This holds the full command message to be sent to Redis, and an `NIO.EventLoopPromise` to be fulfilled when a response has been received.
/// - Important: This struct has _reference semantics_ due to the retention of the `NIO.EventLoopPromise`.
public struct RedisCommand {
/// A command keyword and its arguments stored as a single `RESPValue.array`.
public let command: RESPValue
/// A promise to be fulfilled with the sent command's response from Redis.
/// A message waiting to be sent to Redis. A full message contains a command keyword and its arguments stored as a single `RESPValue.array`.
public let message: RESPValue
/// A promise to be fulfilled with the sent message's response from Redis.
public let responsePromise: EventLoopPromise<RESPValue>
public init(command: RESPValue, promise: EventLoopPromise<RESPValue>) {
self.command = command
public init(message: RESPValue, responsePromise promise: EventLoopPromise<RESPValue>) {
self.message = message
self.responsePromise = promise
}
}
......@@ -130,7 +129,7 @@ extension RedisCommandHandler: ChannelOutboundHandler {
let commandContext = self.unwrapOutboundIn(data)
self.commandResponseQueue.append(commandContext.responsePromise)
context.write(
self.wrapOutboundOut(commandContext.command),
self.wrapOutboundOut(commandContext.message),
promise: promise
)
}
......
......@@ -193,8 +193,8 @@ extension RedisConnection {
let promise = channel.eventLoop.makePromise(of: RESPValue.self)
let command = RedisCommand(
command: .array(message),
promise: promise
message: .array(message),
responsePromise: promise
)
let startTime = DispatchTime.now().uptimeNanoseconds
......@@ -254,8 +254,8 @@ extension RedisConnection {
private func sendQuitCommand() -> EventLoopFuture<Void> {
let promise = channel.eventLoop.makePromise(of: RESPValue.self)
let command = RedisCommand(
command: .array([RESPValue(bulk: "QUIT")]),
promise: promise
message: .array([RESPValue(bulk: "QUIT")]),
responsePromise: promise
)
logger.debug("Sending QUIT command.")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment