Skip to content

Commit 26e3ac2

Browse files
committed
Rename usage of RedisData to RESPValue or just RESP where it makes sense
1 parent 473bdcb commit 26e3ac2

19 files changed

+276
-277
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ print(result) // Optional("some value")
7979

8080
// raw commands
8181

82-
let keyCount = try connection.command("DEL", [RedisData(bulk: "my_key")])
82+
let keyCount = try connection.command("DEL", [RESPValue(bulk: "my_key")])
8383
.thenThrowing { res in
8484
guard case let .integer(count) else {
8585
// throw Error
@@ -95,12 +95,12 @@ try redis.terminate()
9595
try elg.syncShutdownGracefully()
9696
```
9797

98-
### RedisData & RedisDataConvertible
98+
### RESPValue & RESPValueConvertible
9999
This is a 1:1 mapping enum of the `RESP` types: `Simple String`, `Bulk String`, `Array`, `Integer` and `Error`.
100100

101-
Conforming to `RedisDataConvertible` allows Swift types to more easily convert between `RedisData` and native types.
101+
Conforming to `RESPValueConvertible` allows Swift types to more easily convert between `RESPValue` and native types.
102102

103-
`Array`, `Data`, `Float`, `Double`, `FixedWidthInteger`, `String`, and of course `RedisData` all conform in this package.
103+
`Array`, `Data`, `Float`, `Double`, `FixedWidthInteger`, `String`, and of course `RESPValue` all conform in this package.
104104

105105
A `ByteToMessageDecoder` and `MessageToByteEncoder` are used for the conversion process on connections.
106106

@@ -110,10 +110,10 @@ This class uses a `ChannelInboundHandler` that handles the actual process of sen
110110
While it does handle a queue of messages, so as to not be blocking, pipelining is implemented with `NIORedisPipeline`.
111111

112112
### NIORedisPipeline
113-
A `NIORedisPipeline` is a quick abstraction that buffers an array of complete messages as `RedisData`, and executing them in sequence after a
113+
A `NIORedisPipeline` is a quick abstraction that buffers an array of complete messages as `RESPValue`, and executing them in sequence after a
114114
user has invoked `execute()`.
115115

116-
It returns an `EventLoopFuture<[RedisData]>` with the results of all commands executed - unless one errors.
116+
It returns an `EventLoopFuture<[RESPValue]>` with the results of all commands executed - unless one errors.
117117

118118
## Redis
119119

Sources/DispatchRedis/RedisPipeline.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ public final class RedisPipeline {
3232
/// - arguments: The arguments, if any, to send with the command.
3333
/// - Returns: A self-reference to this `RedisPipeline` instance for chaining commands.
3434
@discardableResult
35-
public func enqueue(command: String, arguments: [RedisDataConvertible] = []) throws -> RedisPipeline {
35+
public func enqueue(command: String, arguments: [RESPConvertible] = []) throws -> RedisPipeline {
3636
try _driverPipeline.enqueue(command: command, arguments: arguments)
3737
return self
3838
}
3939

4040
/// Flushes the queue, sending all of the commands to Redis in the same order as they were enqueued.
4141
/// - Important: If any of the commands fail, the remaining commands will not execute and the callback will receive a failure.
4242
/// - Parameter callback: The callback to receive the results of the pipeline of commands, or an error if thrown.
43-
public func execute(_ callback: @escaping (Result<[RedisData], Error>) -> Void) {
43+
public func execute(_ callback: @escaping (Result<[RESPValue], Error>) -> Void) {
4444
_driverPipeline.execute()
4545
.map { results in
4646
self.queue.async { callback(.success(results)) }

Sources/NIORedis/Coders/RedisDataDecoder.swift renamed to Sources/NIORedis/ChannelHandlers/RESPDecoder.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import NIO
44
/// Handles incoming byte messages from Redis and decodes them according to the RESP protocol.
55
///
66
/// See: https://redis.io/topics/protocol
7-
internal final class RedisDataDecoder: ByteToMessageDecoder {
7+
internal final class RESPDecoder: ByteToMessageDecoder {
88
/// `ByteToMessageDecoder`
9-
public typealias InboundOut = RedisData
9+
public typealias InboundOut = RESPValue
1010

1111
/// See `ByteToMessageDecoder.decode(ctx:buffer:)`
1212
func decode(ctx: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState {
@@ -16,8 +16,8 @@ internal final class RedisDataDecoder: ByteToMessageDecoder {
1616
case .notYetParsed:
1717
return .needMoreData
1818

19-
case .parsed(let redisData):
20-
ctx.fireChannelRead(wrapInboundOut(redisData))
19+
case .parsed(let RESPValue):
20+
ctx.fireChannelRead(wrapInboundOut(RESPValue))
2121
buffer.moveReaderIndex(forwardBy: position)
2222
return .continue
2323
}
@@ -36,13 +36,13 @@ extension UInt8 {
3636
static let colon: UInt8 = 0x3A
3737
}
3838

39-
extension RedisDataDecoder {
40-
enum _RedisDataDecodingState {
39+
extension RESPDecoder {
40+
enum _RESPValueDecodingState {
4141
case notYetParsed
42-
case parsed(RedisData)
42+
case parsed(RESPValue)
4343
}
4444

45-
func _parse(at position: inout Int, from buffer: inout ByteBuffer) throws -> _RedisDataDecodingState {
45+
func _parse(at position: inout Int, from buffer: inout ByteBuffer) throws -> _RESPValueDecodingState {
4646
guard let token = buffer.copyBytes(at: position, length: 1)?.first else { return .notYetParsed }
4747

4848
position += 1
@@ -120,7 +120,7 @@ extension RedisDataDecoder {
120120
}
121121

122122
/// See https://redis.io/topics/protocol#resp-bulk-strings
123-
func _parseBulkString(at position: inout Int, from buffer: inout ByteBuffer) throws -> _RedisDataDecodingState {
123+
func _parseBulkString(at position: inout Int, from buffer: inout ByteBuffer) throws -> _RESPValueDecodingState {
124124
guard let size = try _parseInteger(at: &position, from: &buffer) else { return .notYetParsed }
125125

126126
// Redis sends '-1' to represent a null string
@@ -153,12 +153,12 @@ extension RedisDataDecoder {
153153
}
154154

155155
/// See https://redis.io/topics/protocol#resp-arrays
156-
func _parseArray(at position: inout Int, from buffer: inout ByteBuffer) throws -> _RedisDataDecodingState {
156+
func _parseArray(at position: inout Int, from buffer: inout ByteBuffer) throws -> _RESPValueDecodingState {
157157
guard let arraySize = try _parseInteger(at: &position, from: &buffer) else { return .notYetParsed }
158158
guard arraySize > -1 else { return .parsed(.null) }
159159
guard arraySize > 0 else { return .parsed(.array([])) }
160160

161-
var array = [_RedisDataDecodingState](repeating: .notYetParsed, count: arraySize)
161+
var array = [_RESPValueDecodingState](repeating: .notYetParsed, count: arraySize)
162162
for index in 0..<arraySize {
163163
guard buffer.readableBytes - position > 0 else { return .notYetParsed }
164164

@@ -171,7 +171,7 @@ extension RedisDataDecoder {
171171
}
172172
}
173173

174-
let values = try array.map { state -> RedisData in
174+
let values = try array.map { state -> RESPValue in
175175
guard case .parsed(let value) = state else {
176176
throw RedisError(
177177
identifier: "parseArray",

Sources/NIORedis/Coders/RedisDataEncoder.swift renamed to Sources/NIORedis/ChannelHandlers/RESPEncoder.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import Foundation
22
import NIO
33

4-
/// Handles outgoing `RedisData` on the wire by encoding it to the Redis RESP protocol.
4+
/// Handles outgoing `RESPValue` on the wire by encoding it to the Redis RESP protocol.
55
///
66
/// See: https://redis.io/topics/protocol
7-
internal final class RedisDataEncoder: MessageToByteEncoder {
7+
internal final class RESPEncoder: MessageToByteEncoder {
88
/// See `MessageToByteEncoder.OutboundIn`
9-
typealias OutboundIn = RedisData
9+
typealias OutboundIn = RESPValue
1010

11-
/// See `RedisDataEncoder.encode(ctx:data:out:)`
12-
func encode(ctx: ChannelHandlerContext, data: RedisData, out: inout ByteBuffer) throws {
11+
/// See `RESPEncoder.encode(ctx:data:out:)`
12+
func encode(ctx: ChannelHandlerContext, data: RESPValue, out: inout ByteBuffer) throws {
1313
out.write(bytes: _encode(data: data))
1414
}
1515

16-
func _encode(data: RedisData) -> Data {
16+
func _encode(data: RESPValue) -> Data {
1717
switch data {
1818
case .simpleString(let string):
1919
return "+\(string)\r\n".convertedToData()

Sources/NIORedis/Channel/RedisMessenger.swift renamed to Sources/NIORedis/ChannelHandlers/RedisMessenger.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ internal final class RedisMessenger {
99
private var channelContext: ChannelHandlerContext?
1010

1111
/// Queue of promises waiting to receive an incoming response value from an outgoing message.
12-
private var waitingResponseQueue: [EventLoopPromise<RedisData>]
12+
private var waitingResponseQueue: [EventLoopPromise<RESPValue>]
1313
/// Queue of unset outgoing messages, with the oldest messages at the end of the array.
14-
private var outgoingMessageQueue: [RedisData]
14+
private var outgoingMessageQueue: [RESPValue]
1515

1616
/// Creates a new handler that works on the specified `EventLoop`.
1717
init(on eventLoop: EventLoop) {
@@ -20,9 +20,9 @@ internal final class RedisMessenger {
2020
self.eventLoop = eventLoop
2121
}
2222

23-
/// Adds a complete message encoded as `RedisData` to the queue and returns an `EventLoopFuture` that resolves
23+
/// Adds a complete message encoded as `RESPValue` to the queue and returns an `EventLoopFuture` that resolves
2424
/// the response from Redis.
25-
func enqueue(_ output: RedisData) -> EventLoopFuture<RedisData> {
25+
func enqueue(_ output: RESPValue) -> EventLoopFuture<RESPValue> {
2626
// ensure that we are on the event loop before modifying our data
2727
guard eventLoop.inEventLoop else {
2828
return eventLoop.submit({}).then { return self.enqueue(output) }
@@ -33,7 +33,7 @@ internal final class RedisMessenger {
3333

3434
// every outgoing message is expected to receive some form of response, so create a promise that we'll resolve
3535
// with the response
36-
let promise = eventLoop.makePromise(of: RedisData.self)
36+
let promise = eventLoop.makePromise(of: RESPValue.self)
3737
waitingResponseQueue.insert(promise, at: 0)
3838

3939
// if we have a context for writing, flush the outgoing queue
@@ -59,10 +59,10 @@ internal final class RedisMessenger {
5959

6060
extension RedisMessenger: ChannelInboundHandler {
6161
/// See `ChannelInboundHandler.InboundIn`
62-
public typealias InboundIn = RedisData
62+
public typealias InboundIn = RESPValue
6363

6464
/// See `ChannelInboundHandler.OutboundOut`
65-
public typealias OutboundOut = RedisData
65+
public typealias OutboundOut = RESPValue
6666

6767
/// Invoked by NIO when the channel for this handler has become active, receiving a context that is ready to
6868
/// send messages.
@@ -85,7 +85,7 @@ extension RedisMessenger: ChannelInboundHandler {
8585
}
8686

8787
/// Invoked by NIO when a read has been fired from earlier in the response chain. This forwards the unwrapped
88-
/// `RedisData` to the response at the front of the queue.
88+
/// `RESPValue` to the response at the front of the queue.
8989
/// See `ChannelInboundHandler.channelRead(ctx:data:)`
9090
public func channelRead(ctx: ChannelHandlerContext, data: NIOAny) {
9191
let input = unwrapInboundIn(data)

Sources/NIORedis/Commands/BasicCommands.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ extension NIORedisConnection {
77
///
88
/// https://redis.io/commands/select
99
public func select(_ id: Int) -> EventLoopFuture<Void> {
10-
return command("SELECT", [RedisData(bulk: id.description)])
10+
return command("SELECT", [RESPValue(bulk: id.description)])
1111
.map { _ in return () }
1212
}
1313

1414
/// Request for authentication in a password-protected Redis server.
1515
///
1616
/// https://redis.io/commands/auth
1717
public func authorize(with password: String) -> EventLoopFuture<Void> {
18-
return command("AUTH", [RedisData(bulk: password)]).map { _ in return () }
18+
return command("AUTH", [RESPValue(bulk: password)]).map { _ in return () }
1919
}
2020

2121
/// Removes the specified keys. A key is ignored if it does not exist.
2222
///
2323
/// https://redis.io/commands/del
2424
/// - Returns: A future number of keys that were removed.
2525
public func delete(_ keys: String...) -> EventLoopFuture<Int> {
26-
let keyArgs = keys.map { RedisData(bulk: $0) }
26+
let keyArgs = keys.map { RESPValue(bulk: $0) }
2727
return command("DEL", keyArgs)
2828
.thenThrowing { res in
2929
guard let count = res.int else {
@@ -41,7 +41,7 @@ extension NIORedisConnection {
4141
/// - after: The lifetime (in seconds) the key will expirate at.
4242
/// - Returns: A future bool indicating if the expiration was set or not.
4343
public func expire(_ key: String, after deadline: Int) -> EventLoopFuture<Bool> {
44-
return command("EXPIRE", [RedisData(bulk: key), RedisData(bulk: deadline.description)])
44+
return command("EXPIRE", [RESPValue(bulk: key), RESPValue(bulk: deadline.description)])
4545
.thenThrowing { res in
4646
guard let value = res.int else {
4747
throw RedisError(identifier: "expire", reason: "Unexpected response: \(res)")
@@ -56,7 +56,7 @@ extension NIORedisConnection {
5656
///
5757
/// https://redis.io/commands/get
5858
public func get(_ key: String) -> EventLoopFuture<String?> {
59-
return command("GET", [RedisData(bulk: key)])
59+
return command("GET", [RESPValue(bulk: key)])
6060
.map { return $0.string }
6161
}
6262

@@ -66,7 +66,7 @@ extension NIORedisConnection {
6666
///
6767
/// https://redis.io/commands/set
6868
public func set(_ key: String, to value: String) -> EventLoopFuture<Void> {
69-
return command("SET", [RedisData(bulk: key), RedisData(bulk: value)])
69+
return command("SET", [RESPValue(bulk: key), RESPValue(bulk: value)])
7070
.map { _ in return () }
7171
}
7272
}

0 commit comments

Comments
 (0)