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
This commit is contained in:
Nathan Harris
2019-03-12 14:42:11 -07:00
parent a17bfff3ff
commit 571d7bce02
8 changed files with 28 additions and 24 deletions
@@ -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<Void> {
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<Void> {
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<Int> {
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<String?> {
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<Void> {
return command("SET", arguments: [RESPValue(bulk: key), RESPValue(bulk: value)])
.map { _ in return () }
+10 -6
View File
@@ -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) }
+1 -1
View File
@@ -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) {
+1 -1
View File
@@ -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)
@@ -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)
+1 -1
View File
@@ -6,7 +6,7 @@ import NIOConcurrencyHelpers
/// let result = connection.send(command: "GET", arguments: ["my_key"]
/// // result == EventLoopFuture<RESPValue>
///
/// 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
+2 -2
View File
@@ -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