Skip to content

Commit 2605763

Browse files
committed
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.
1 parent 04aa1f9 commit 2605763

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

Sources/RediStack/ChannelHandlers/RedisCommandHandler.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@ import NIO
1818

1919
/// The `NIO.ChannelOutboundHandler.OutboundIn` type for `RedisCommandHandler`.
2020
///
21-
/// This holds the command and its arguments stored as a single `RESPValue` to be sent to Redis,
22-
/// and an `NIO.EventLoopPromise` to be fulfilled when a response has been received.
21+
/// This holds the full command message to be sent to Redis, and an `NIO.EventLoopPromise` to be fulfilled when a response has been received.
2322
/// - Important: This struct has _reference semantics_ due to the retention of the `NIO.EventLoopPromise`.
2423
public struct RedisCommand {
25-
/// A command keyword and its arguments stored as a single `RESPValue.array`.
26-
public let command: RESPValue
27-
/// A promise to be fulfilled with the sent command's response from Redis.
24+
/// A message waiting to be sent to Redis. A full message contains a command keyword and its arguments stored as a single `RESPValue.array`.
25+
public let message: RESPValue
26+
/// A promise to be fulfilled with the sent message's response from Redis.
2827
public let responsePromise: EventLoopPromise<RESPValue>
2928

30-
public init(command: RESPValue, promise: EventLoopPromise<RESPValue>) {
31-
self.command = command
29+
public init(message: RESPValue, responsePromise promise: EventLoopPromise<RESPValue>) {
30+
self.message = message
3231
self.responsePromise = promise
3332
}
3433
}
@@ -130,7 +129,7 @@ extension RedisCommandHandler: ChannelOutboundHandler {
130129
let commandContext = self.unwrapOutboundIn(data)
131130
self.commandResponseQueue.append(commandContext.responsePromise)
132131
context.write(
133-
self.wrapOutboundOut(commandContext.command),
132+
self.wrapOutboundOut(commandContext.message),
134133
promise: promise
135134
)
136135
}

Sources/RediStack/RedisConnection.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ extension RedisConnection {
193193

194194
let promise = channel.eventLoop.makePromise(of: RESPValue.self)
195195
let command = RedisCommand(
196-
command: .array(message),
197-
promise: promise
196+
message: .array(message),
197+
responsePromise: promise
198198
)
199199

200200
let startTime = DispatchTime.now().uptimeNanoseconds
@@ -254,8 +254,8 @@ extension RedisConnection {
254254
private func sendQuitCommand() -> EventLoopFuture<Void> {
255255
let promise = channel.eventLoop.makePromise(of: RESPValue.self)
256256
let command = RedisCommand(
257-
command: .array([RESPValue(bulk: "QUIT")]),
258-
promise: promise
257+
message: .array([RESPValue(bulk: "QUIT")]),
258+
responsePromise: promise
259259
)
260260

261261
logger.debug("Sending QUIT command.")

0 commit comments

Comments
 (0)