From 571d7bce0209c6606824b3d2fdbdd3ec2b295cbf Mon Sep 17 00:00:00 2001 From: Nathan Harris Date: Tue, 12 Mar 2019 14:42:11 -0700 Subject: [PATCH] Housekeeping of code - Move: `String.convertedToData()` to `NIORedisTests` as a test utility - Change: URLs in code comments to be Markdown links - Change: Code comments to be more correct --- Sources/NIORedis/Commands/BasicCommands.swift | 12 ++++++------ Sources/NIORedis/RESP/RESPDecoder.swift | 16 ++++++++++------ Sources/NIORedis/RESP/RESPEncoder.swift | 2 +- Sources/NIORedis/RESP/RESPValue.swift | 2 +- Sources/NIORedis/RESP/RESPValueConvertible.swift | 14 +++++++------- Sources/NIORedis/RedisConnection.swift | 2 +- Sources/NIORedis/RedisPipeline.swift | 4 ++-- .../NIORedisTests/Utilities}/String.swift | 0 8 files changed, 28 insertions(+), 24 deletions(-) rename {Sources/NIORedis/Extensions/Foundation => Tests/NIORedisTests/Utilities}/String.swift (100%) diff --git a/Sources/NIORedis/Commands/BasicCommands.swift b/Sources/NIORedis/Commands/BasicCommands.swift index dc2b40d..40c0f5b 100644 --- a/Sources/NIORedis/Commands/BasicCommands.swift +++ b/Sources/NIORedis/Commands/BasicCommands.swift @@ -5,7 +5,7 @@ extension RedisConnection { /// Select the Redis logical database having the specified zero-based numeric index. /// New connections always use the database 0. /// - /// https://redis.io/commands/select + /// [https://redis.io/commands/select](https://redis.io/commands/select) public func select(_ id: Int) -> EventLoopFuture { return command("SELECT", arguments: [RESPValue(bulk: id.description)]) .map { _ in return () } @@ -13,7 +13,7 @@ extension RedisConnection { /// Request for authentication in a password-protected Redis server. /// - /// https://redis.io/commands/auth + /// [https://redis.io/commands/auth](https://redis.io/commands/auth) public func authorize(with password: String) -> EventLoopFuture { return command("AUTH", arguments: [RESPValue(bulk: password)]) .map { _ in return () } @@ -21,7 +21,7 @@ extension RedisConnection { /// Removes the specified keys. A key is ignored if it does not exist. /// - /// https://redis.io/commands/del + /// [https://redis.io/commands/del](https://redis.io/commands/del) /// - Returns: A future number of keys that were removed. public func delete(_ keys: String...) -> EventLoopFuture { let keyArgs = keys.map { RESPValue(bulk: $0) } @@ -37,7 +37,7 @@ extension RedisConnection { /// Set a timeout on key. After the timeout has expired, the key will automatically be deleted. /// A key with an associated timeout is often said to be volatile in Redis terminology. /// - /// https://redis.io/commands/expire + /// [https://redis.io/commands/expire](https://redis.io/commands/expire) /// - Parameters: /// - after: The lifetime (in seconds) the key will expirate at. /// - Returns: A future bool indicating if the expiration was set or not. @@ -55,7 +55,7 @@ extension RedisConnection { /// If the key does not exist the value will be `nil`. /// An error is resolved if the value stored at key is not a string, because GET only handles string values. /// - /// https://redis.io/commands/get + /// [https://redis.io/commands/get](https://redis.io/commands/get) public func get(_ key: String) -> EventLoopFuture { return command("GET", arguments: [RESPValue(bulk: key)]) .map { return $0.string } @@ -65,7 +65,7 @@ extension RedisConnection { /// If key already holds a value, it is overwritten, regardless of its type. /// Any previous time to live associated with the key is discarded on successful SET operation. /// - /// https://redis.io/commands/set + /// [https://redis.io/commands/set](https://redis.io/commands/set) public func set(_ key: String, to value: String) -> EventLoopFuture { return command("SET", arguments: [RESPValue(bulk: key), RESPValue(bulk: value)]) .map { _ in return () } diff --git a/Sources/NIORedis/RESP/RESPDecoder.swift b/Sources/NIORedis/RESP/RESPDecoder.swift index 261446a..fec0377 100644 --- a/Sources/NIORedis/RESP/RESPDecoder.swift +++ b/Sources/NIORedis/RESP/RESPDecoder.swift @@ -28,7 +28,7 @@ private extension ByteBuffer { /// Handles incoming byte messages from Redis and decodes them according to the RESP protocol. /// -/// See: https://redis.io/topics/protocol +/// See: [https://redis.io/topics/protocol](https://redis.io/topics/protocol) public final class RESPDecoder { /// Representation of a `RESPDecoder.parse(at:from:) result, with either a decoded `RESPValue` or an indicator /// that the buffer contains an incomplete RESP message from the position provided. @@ -41,7 +41,7 @@ public final class RESPDecoder { /// Attempts to parse the `ByteBuffer`, starting at the specified position, following the RESP specification. /// - /// See https://redis.io/topics/protocol + /// See [https://redis.io/topics/protocol](https://redis.io/topics/protocol) /// - Parameters: /// - at: The index of the buffer that should be considered the "front" to begin message parsing. /// - from: The buffer that contains the bytes that need to be decoded. @@ -76,8 +76,12 @@ public final class RESPDecoder { ) } } +} - /// See https://redis.io/topics/protocol#resp-simple-strings +// Parsing + +extension RESPDecoder { + /// See [https://redis.io/topics/protocol#resp-simple-strings](https://redis.io/topics/protocol#resp-simple-strings) func _parseSimpleString(at position: inout Int, from buffer: inout ByteBuffer) throws -> String? { let byteCount = buffer.readableBytes - position guard @@ -108,7 +112,7 @@ public final class RESPDecoder { return String(bytes: bytes[ ..<(expectedNewlinePosition - 1) ], encoding: .utf8) } - /// See https://redis.io/topics/protocol#resp-integers + /// See [https://redis.io/topics/protocol#resp-integers](https://redis.io/topics/protocol#resp-integers) func _parseInteger(at position: inout Int, from buffer: inout ByteBuffer) throws -> Int? { guard let string = try _parseSimpleString(at: &position, from: &buffer) else { return nil } @@ -122,7 +126,7 @@ public final class RESPDecoder { return number } - /// See https://redis.io/topics/protocol#resp-bulk-strings + /// See [https://redis.io/topics/protocol#resp-bulk-strings](https://redis.io/topics/protocol#resp-bulk-strings) func _parseBulkString(at position: inout Int, from buffer: inout ByteBuffer) throws -> ParsingState { guard let size = try _parseInteger(at: &position, from: &buffer) else { return .notYetParsed } @@ -155,7 +159,7 @@ public final class RESPDecoder { ) } - /// See https://redis.io/topics/protocol#resp-arrays + /// See [https://redis.io/topics/protocol#resp-arrays](https://redis.io/topics/protocol#resp-arrays) func _parseArray(at position: inout Int, from buffer: inout ByteBuffer) throws -> ParsingState { guard let arraySize = try _parseInteger(at: &position, from: &buffer) else { return .notYetParsed } guard arraySize > -1 else { return .parsed(.null) } diff --git a/Sources/NIORedis/RESP/RESPEncoder.swift b/Sources/NIORedis/RESP/RESPEncoder.swift index 442a89f..8603ba7 100644 --- a/Sources/NIORedis/RESP/RESPEncoder.swift +++ b/Sources/NIORedis/RESP/RESPEncoder.swift @@ -6,7 +6,7 @@ public final class RESPEncoder { /// Encodes the `RedisValue` to bytes, following the RESP specification. /// - /// See https://redis.io/topics/protocol + /// See [https://redis.io/topics/protocol](https://redis.io/topics/protocol) /// - Parameter value: The `RESPValue` to encode. /// - Returns: The encoded value as a collection of bytes. public func encode(_ value: RESPValue, into buffer: inout ByteBuffer) { diff --git a/Sources/NIORedis/RESP/RESPValue.swift b/Sources/NIORedis/RESP/RESPValue.swift index 1745a52..f120c6b 100644 --- a/Sources/NIORedis/RESP/RESPValue.swift +++ b/Sources/NIORedis/RESP/RESPValue.swift @@ -2,7 +2,7 @@ import Foundation /// A representation of a Redis Serialization Protocol (RESP) primitive value. /// -/// See: https://redis.io/topics/protocol +/// See: [https://redis.io/topics/protocol](https://redis.io/topics/protocol) public enum RESPValue { case null case simpleString(String) diff --git a/Sources/NIORedis/RESP/RESPValueConvertible.swift b/Sources/NIORedis/RESP/RESPValueConvertible.swift index 600f399..323a7cc 100644 --- a/Sources/NIORedis/RESP/RESPValueConvertible.swift +++ b/Sources/NIORedis/RESP/RESPValueConvertible.swift @@ -13,7 +13,7 @@ extension RESPValue: RESPValueConvertible { self = value } - /// See `RESPValueConvertible` + /// See `RESPValueConvertible.convertedToRESPValue()` public func convertedToRESPValue() -> RESPValue { return self } @@ -37,7 +37,7 @@ extension String: RESPValueConvertible { self = string } - /// See `RESPValueConvertible`. + /// See `RESPValueConvertible.convertedToRESPValue()` public func convertedToRESPValue() -> RESPValue { return .bulkString(Data(self.utf8)) } @@ -54,7 +54,7 @@ extension FixedWidthInteger { } } - /// See `convertedToRESP`. + /// See `RESPValueConvertible.convertedToRESPValue()` public func convertedToRESPValue() -> RESPValue { return .bulkString(Data(self.description.utf8)) } @@ -78,7 +78,7 @@ extension Double: RESPValueConvertible { self = float } - /// See `RESPValueConvertible`. + /// See `RESPValueConvertible.convertedToRESPValue()` public func convertedToRESPValue() -> RESPValue { return .bulkString(Data(self.description.utf8)) } @@ -91,7 +91,7 @@ extension Float: RESPValueConvertible { self = float } - /// See `RESPValueConvertible`. + /// See `RESPValueConvertible.convertedToRESPValue()` public func convertedToRESPValue() -> RESPValue { return .bulkString(Data(self.description.utf8)) } @@ -103,7 +103,7 @@ extension Data: RESPValueConvertible { self = data } - /// See `RESPValueConvertible`. + /// See `RESPValueConvertible.convertedToRESPValue()` public func convertedToRESPValue() -> RESPValue { return .bulkString(self) } @@ -115,7 +115,7 @@ extension Array: RESPValueConvertible where Element: RESPValueConvertible { self = array.compactMap { Element($0) } } - /// See `RESPValueConvertible`. + /// See `RESPValueConvertible.convertedToRESPValue()` public func convertedToRESPValue() -> RESPValue { let elements = map { $0.convertedToRESPValue() } return RESPValue.array(elements) diff --git a/Sources/NIORedis/RedisConnection.swift b/Sources/NIORedis/RedisConnection.swift index 416d43e..4b866f5 100644 --- a/Sources/NIORedis/RedisConnection.swift +++ b/Sources/NIORedis/RedisConnection.swift @@ -6,7 +6,7 @@ import NIOConcurrencyHelpers /// let result = connection.send(command: "GET", arguments: ["my_key"] /// // result == EventLoopFuture /// -/// See https://redis.io/commands +/// See [https://redis.io/commands](https://redis.io/commands) public final class RedisConnection { /// The `Channel` this connection is associated with. public let channel: Channel diff --git a/Sources/NIORedis/RedisPipeline.swift b/Sources/NIORedis/RedisPipeline.swift index d7ed544..a989227 100644 --- a/Sources/NIORedis/RedisPipeline.swift +++ b/Sources/NIORedis/RedisPipeline.swift @@ -11,7 +11,7 @@ import Foundation /// // results[0].string == Optional("OK") /// // results[1].int == Optional(4) /// -/// See https://redis.io/topics/pipelining#redis-pipelining +/// See [https://redis.io/topics/pipelining#redis-pipelining](https://redis.io/topics/pipelining#redis-pipelining) /// - Important: The larger the pipeline queue, the more memory both NIORedis and Redis will use. public final class RedisPipeline { /// The number of commands in the pipeline. @@ -34,7 +34,7 @@ public final class RedisPipeline { /// Queues the provided command and arguments to be executed when `execute()` is invoked. /// - Parameters: - /// - command: The command to execute. See https://redis.io/commands + /// - command: The command to execute. See [https://redis.io/commands](https://redis.io/commands) /// - arguments: The arguments, if any, to send with the command. /// - Returns: A self-reference for chaining commands. @discardableResult diff --git a/Sources/NIORedis/Extensions/Foundation/String.swift b/Tests/NIORedisTests/Utilities/String.swift similarity index 100% rename from Sources/NIORedis/Extensions/Foundation/String.swift rename to Tests/NIORedisTests/Utilities/String.swift