Commit b5812484 authored by Nathan Harris's avatar Nathan Harris

Merge branch '50-rename-map' into 'master'

50 -- Rename `EventLoopFuture.mapFromRESP` to `convertFromRESPValue`

Closes #50

See merge request Mordil/swift-redis-nio-client!60
parents e0e5a689 c010e13b
Pipeline #67836491 failed with stages
in 4 minutes and 19 seconds
......@@ -23,7 +23,7 @@ extension RedisClient {
@inlinable
public func echo(_ message: String) -> EventLoopFuture<String> {
return send(command: "ECHO", with: [message])
.mapFromRESP()
.convertFromRESPValue()
}
/// Pings the server, which will respond with a message.
......@@ -35,7 +35,7 @@ extension RedisClient {
public func ping(with message: String? = nil) -> EventLoopFuture<String> {
let arg = message != nil ? [message] : []
return send(command: "PING", with: arg)
.mapFromRESP()
.convertFromRESPValue()
}
/// Select the Redis logical database having the specified zero-based numeric index.
......@@ -61,7 +61,7 @@ extension RedisClient {
public func swapDatabase(_ first: Int, with second: Int) -> EventLoopFuture<Bool> {
/// connection.swapDatabase(index: 0, withIndex: 10)
return send(command: "SWAPDB", with: [first, second])
.mapFromRESP(to: String.self)
.convertFromRESPValue(to: String.self)
.map { return $0 == "OK" }
}
......@@ -75,7 +75,7 @@ extension RedisClient {
guard keys.count > 0 else { return self.eventLoop.makeSucceededFuture(0) }
return send(command: "DEL", with: keys)
.mapFromRESP()
.convertFromRESPValue()
}
/// Sets a timeout on key. After the timeout has expired, the key will automatically be deleted.
......@@ -90,7 +90,7 @@ extension RedisClient {
public func expire(_ key: String, after deadline: TimeAmount) -> EventLoopFuture<Bool> {
let amount = deadline.nanoseconds / 1_000_000_000
return send(command: "EXPIRE", with: [key, amount])
.mapFromRESP(to: Int.self)
.convertFromRESPValue(to: Int.self)
.map { return $0 == 1 }
}
}
......@@ -142,7 +142,7 @@ extension RedisClient {
args.append(c)
}
let response = send(command: command, with: args).mapFromRESP(to: [RESPValue].self)
let response = send(command: command, with: args).convertFromRESPValue(to: [RESPValue].self)
let position = response.flatMapThrowing { result -> Int in
guard
let value = result[0].string,
......@@ -154,7 +154,7 @@ extension RedisClient {
}
let elements = response
.map { return $0[1] }
.mapFromRESP(to: resultType)
.convertFromRESPValue(to: resultType)
return position.and(elements)
}
......
......@@ -50,7 +50,7 @@ extension RedisClient {
guard fields.count > 0 else { return self.eventLoop.makeSucceededFuture(0) }
return send(command: "HDEL", with: [key] + fields)
.mapFromRESP()
.convertFromRESPValue()
}
/// Checks if a hash contains the field specified.
......@@ -63,7 +63,7 @@ extension RedisClient {
@inlinable
public func hexists(_ field: String, in key: String) -> EventLoopFuture<Bool> {
return send(command: "HEXISTS", with: [key, field])
.mapFromRESP(to: Int.self)
.convertFromRESPValue(to: Int.self)
.map { return $0 == 1 }
}
......@@ -75,7 +75,7 @@ extension RedisClient {
@inlinable
public func hlen(of key: String) -> EventLoopFuture<Int> {
return send(command: "HLEN", with: [key])
.mapFromRESP()
.convertFromRESPValue()
}
/// Gets the string length of a hash field's value.
......@@ -88,7 +88,7 @@ extension RedisClient {
@inlinable
public func hstrlen(of field: String, in key: String) -> EventLoopFuture<Int> {
return send(command: "HSTRLEN", with: [key, field])
.mapFromRESP()
.convertFromRESPValue()
}
/// Gets all field names in a hash.
......@@ -99,7 +99,7 @@ extension RedisClient {
@inlinable
public func hkeys(in key: String) -> EventLoopFuture<[String]> {
return send(command: "HKEYS", with: [key])
.mapFromRESP()
.convertFromRESPValue()
}
/// Gets all values stored in a hash.
......@@ -110,7 +110,7 @@ extension RedisClient {
@inlinable
public func hvals(in key: String) -> EventLoopFuture<[RESPValue]> {
return send(command: "HVALS", with: [key])
.mapFromRESP()
.convertFromRESPValue()
}
/// Incrementally iterates over all fields in a hash.
......@@ -156,7 +156,7 @@ extension RedisClient {
in key: String
) -> EventLoopFuture<Bool> {
return send(command: "HSET", with: [key, field, value])
.mapFromRESP(to: Int.self)
.convertFromRESPValue(to: Int.self)
.map { return $0 == 1 }
}
......@@ -176,7 +176,7 @@ extension RedisClient {
in key: String
) -> EventLoopFuture<Bool> {
return send(command: "HSETNX", with: [key, field, value])
.mapFromRESP(to: Int.self)
.convertFromRESPValue(to: Int.self)
.map { return $0 == 1 }
}
......@@ -232,7 +232,7 @@ extension RedisClient {
guard fields.count > 0 else { return self.eventLoop.makeSucceededFuture([]) }
return send(command: "HMGET", with: [key] + fields)
.mapFromRESP(to: [RESPValue].self)
.convertFromRESPValue(to: [RESPValue].self)
.map { return $0.map(String.init) }
}
......@@ -244,7 +244,7 @@ extension RedisClient {
@inlinable
public func hgetall(from key: String) -> EventLoopFuture<[String: String]> {
return send(command: "HGETALL", with: [key])
.mapFromRESP(to: [String].self)
.convertFromRESPValue(to: [String].self)
.map(Self._mapHashResponse)
}
}
......@@ -264,7 +264,7 @@ extension RedisClient {
public func hincrby(_ amount: Int, field: String, in key: String) -> EventLoopFuture<Int> {
/// connection.hincrby(20, field: "foo", in: "key")
return send(command: "HINCRBY", with: [key, field, amount])
.mapFromRESP()
.convertFromRESPValue()
}
/// Increments a hash field's value and returns the new value.
......@@ -282,6 +282,6 @@ extension RedisClient {
T: RESPValueConvertible
{
return send(command: "HINCRBYFLOAT", with: [key, field, amount])
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -25,7 +25,7 @@ extension RedisClient {
@inlinable
public func llen(of key: String) -> EventLoopFuture<Int> {
return send(command: "LLEN", with: [key])
.mapFromRESP()
.convertFromRESPValue()
}
/// Gets the element from a list stored at the provided index position.
......@@ -73,7 +73,7 @@ extension RedisClient {
count: Int = 0
) -> EventLoopFuture<Int> {
return send(command: "LREM", with: [key, count, value])
.mapFromRESP()
.convertFromRESPValue()
}
/// Trims a list to only contain elements within the specified inclusive bounds of 0-based indices.
......@@ -103,7 +103,7 @@ extension RedisClient {
from key: String
) -> EventLoopFuture<[RESPValue]> {
return send(command: "LRANGE", with: [key, range.startIndex, range.endIndex])
.mapFromRESP()
.convertFromRESPValue()
}
/// Pops the last element from a source list and pushes it to a destination list.
......@@ -187,7 +187,7 @@ extension RedisClient {
_ pivot: RESPValueConvertible
) -> EventLoopFuture<Int> {
return send(command: "LINSERT", with: [key, pivotKeyword, pivot, element])
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -217,7 +217,7 @@ extension RedisClient {
assert(elements.count > 0, "At least 1 element should be provided.")
return send(command: "LPUSH", with: [key] + elements)
.mapFromRESP()
.convertFromRESPValue()
}
/// Pushes an element into a list, but only if the key exists and holds a list.
......@@ -231,7 +231,7 @@ extension RedisClient {
@inlinable
public func lpushx(_ element: RESPValueConvertible, into key: String) -> EventLoopFuture<Int> {
return send(command: "LPUSHX", with: [key, element])
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -260,7 +260,7 @@ extension RedisClient {
assert(elements.count > 0, "At least 1 element should be provided.")
return send(command: "RPUSH", with: [key] + elements)
.mapFromRESP()
.convertFromRESPValue()
}
/// Pushes an element into a list, but only if the key exists and holds a list.
......@@ -274,7 +274,7 @@ extension RedisClient {
@inlinable
public func rpushx(_ element: RESPValueConvertible, into key: String) -> EventLoopFuture<Int> {
return send(command: "RPUSHX", with: [key, element])
.mapFromRESP()
.convertFromRESPValue()
}
}
......
......@@ -28,7 +28,7 @@ extension RedisClient {
@inlinable
public func smembers(of key: String) -> EventLoopFuture<[RESPValue]> {
return send(command: "SMEMBERS", with: [key])
.mapFromRESP()
.convertFromRESPValue()
}
/// Checks if the element is included in a set.
......@@ -41,7 +41,7 @@ extension RedisClient {
@inlinable
public func sismember(_ element: RESPValueConvertible, of key: String) -> EventLoopFuture<Bool> {
return send(command: "SISMEMBER", with: [key, element])
.mapFromRESP(to: Int.self)
.convertFromRESPValue(to: Int.self)
.map { return $0 == 1 }
}
......@@ -53,7 +53,7 @@ extension RedisClient {
@inlinable
public func scard(of key: String) -> EventLoopFuture<Int> {
return send(command: "SCARD", with: [key])
.mapFromRESP()
.convertFromRESPValue()
}
/// Adds elements to a set.
......@@ -68,7 +68,7 @@ extension RedisClient {
guard elements.count > 0 else { return self.eventLoop.makeSucceededFuture(0) }
return send(command: "SADD", with: [key] + elements)
.mapFromRESP()
.convertFromRESPValue()
}
/// Removes elements from a set.
......@@ -83,7 +83,7 @@ extension RedisClient {
guard elements.count > 0 else { return self.eventLoop.makeSucceededFuture(0) }
return send(command: "SREM", with: [key] + elements)
.mapFromRESP()
.convertFromRESPValue()
}
/// Randomly selects and removes one or more elements in a set.
......@@ -100,7 +100,7 @@ extension RedisClient {
guard count > 0 else { return self.eventLoop.makeSucceededFuture([]) }
return send(command: "SPOP", with: [key, count])
.mapFromRESP()
.convertFromRESPValue()
}
/// Randomly selects one or more elements in a set.
......@@ -119,7 +119,7 @@ extension RedisClient {
guard count != 0 else { return self.eventLoop.makeSucceededFuture([]) }
return send(command: "SRANDMEMBER", with: [key, count])
.mapFromRESP()
.convertFromRESPValue()
}
/// Moves an element from one set to another.
......@@ -139,7 +139,7 @@ extension RedisClient {
guard sourceKey != destKey else { return self.eventLoop.makeSucceededFuture(true) }
return send(command: "SMOVE", with: [sourceKey, destKey, element])
.mapFromRESP()
.convertFromRESPValue()
.map { return $0 == 1 }
}
......@@ -176,7 +176,7 @@ extension RedisClient {
guard keys.count > 0 else { return self.eventLoop.makeSucceededFuture([]) }
return send(command: "SDIFF", with: keys)
.mapFromRESP()
.convertFromRESPValue()
}
/// Calculates the difference between two or more sets and stores the result.
......@@ -192,7 +192,7 @@ extension RedisClient {
assert(keys.count > 0, "At least 1 key should be provided.")
return send(command: "SDIFFSTORE", with: [destination] + keys)
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -209,7 +209,7 @@ extension RedisClient {
guard keys.count > 0 else { return self.eventLoop.makeSucceededFuture([]) }
return send(command: "SINTER", with: keys)
.mapFromRESP()
.convertFromRESPValue()
}
/// Calculates the intersetion of two or more sets and stores the result.
......@@ -225,7 +225,7 @@ extension RedisClient {
assert(keys.count > 0, "At least 1 key should be provided.")
return send(command: "SINTERSTORE", with: [destination] + keys)
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -242,7 +242,7 @@ extension RedisClient {
guard keys.count > 0 else { return self.eventLoop.makeSucceededFuture([]) }
return send(command: "SUNION", with: keys)
.mapFromRESP()
.convertFromRESPValue()
}
/// Calculates the union of two or more sets and stores the result.
......@@ -258,6 +258,6 @@ extension RedisClient {
assert(keys.count > 0, "At least 1 key should be provided.")
return send(command: "SUNIONSTORE", with: [destination] + keys)
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -83,7 +83,7 @@ extension RedisClient {
}
return send(command: "ZADD", with: args)
.mapFromRESP()
.convertFromRESPValue()
}
/// Adds an element to a sorted set, assigning their score to the value provided.
......@@ -112,7 +112,7 @@ extension RedisClient {
@inlinable
public func zcard(of key: String) -> EventLoopFuture<Int> {
return send(command: "ZCARD", with: [key])
.mapFromRESP()
.convertFromRESPValue()
}
/// Gets the score of the specified element in a stored set.
......@@ -167,7 +167,7 @@ extension RedisClient {
@inlinable
public func zrank(of element: RESPValueConvertible, in key: String) -> EventLoopFuture<Int?> {
return send(command: "ZRANK", with: [key, element])
.mapFromRESP()
.convertFromRESPValue()
}
/// Returns the rank (index) of the specified element in a sorted set.
......@@ -182,7 +182,7 @@ extension RedisClient {
@inlinable
public func zrevrank(of element: RESPValueConvertible, in key: String) -> EventLoopFuture<Int?> {
return send(command: "ZREVRANK", with: [key, element])
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -202,7 +202,7 @@ extension RedisClient {
within range: (min: String, max: String)
) -> EventLoopFuture<Int> {
return send(command: "ZCOUNT", with: [key, range.min, range.max])
.mapFromRESP()
.convertFromRESPValue()
}
/// Returns the number of elements in a sorted set whose lexiographical values are between the range specified.
......@@ -219,7 +219,7 @@ extension RedisClient {
within range: (min: String, max: String)
) -> EventLoopFuture<Int> {
return send(command: "ZLEXCOUNT", with: [key, range.min, range.max])
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -287,7 +287,7 @@ extension RedisClient {
}
return send(command: command, with: args)
.mapFromRESP(to: [RESPValue].self)
.convertFromRESPValue(to: [RESPValue].self)
.flatMapThrowing { return try Self._mapSortedSetResponse($0, scoreIsFirst: true) }
}
}
......@@ -453,7 +453,7 @@ extension RedisClient {
in key: String
) -> EventLoopFuture<Double> {
return send(command: "ZINCRBY", with: [key, amount, element])
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -528,7 +528,7 @@ extension RedisClient {
}
return send(command: command, with: args)
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -588,7 +588,7 @@ extension RedisClient {
if withScores { args.append("WITHSCORES") }
return send(command: command, with: args)
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -657,7 +657,7 @@ extension RedisClient {
}
return send(command: command, with: args)
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -721,7 +721,7 @@ extension RedisClient {
}
return send(command: command, with: args)
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -740,7 +740,7 @@ extension RedisClient {
guard elements.count > 0 else { return self.eventLoop.makeSucceededFuture(0) }
return send(command: "ZREM", with: [key] + elements)
.mapFromRESP()
.convertFromRESPValue()
}
/// Removes elements from a sorted set whose lexiographical values are between the range specified.
......@@ -757,7 +757,7 @@ extension RedisClient {
from key: String
) -> EventLoopFuture<Int> {
return send(command: "ZREMRANGEBYLEX", with: [key, range.min, range.max])
.mapFromRESP()
.convertFromRESPValue()
}
/// Removes elements from a sorted set whose index is between the provided range.
......@@ -773,7 +773,7 @@ extension RedisClient {
from key: String
) -> EventLoopFuture<Int> {
return send(command: "ZREMRANGEBYRANK", with: [key, range.start, range.stop])
.mapFromRESP()
.convertFromRESPValue()
}
/// Removes elements from a sorted set whose score is within the range specified.
......@@ -789,6 +789,6 @@ extension RedisClient {
from key: String
) -> EventLoopFuture<Int> {
return send(command: "ZREMRANGEBYSCORE", with: [key, range.min, range.max])
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -40,7 +40,7 @@ extension RedisClient {
guard keys.count > 0 else { return self.eventLoop.makeSucceededFuture([]) }
return send(command: "MGET", with: keys)
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -85,7 +85,7 @@ extension RedisClient {
@inlinable
public func msetnx(_ operations: [String: RESPValueConvertible]) -> EventLoopFuture<Bool> {
return _mset(command: "MSETNX", operations)
.mapFromRESP(to: Int.self)
.convertFromRESPValue(to: Int.self)
.map { return $0 == 1 }
}
......@@ -116,7 +116,7 @@ extension RedisClient {
@inlinable
public func increment(_ key: String) -> EventLoopFuture<Int> {
return send(command: "INCR", with: [key])
.mapFromRESP()
.convertFromRESPValue()
}
/// Increments the stored value by the amount desired .
......@@ -129,7 +129,7 @@ extension RedisClient {
@inlinable
public func increment(_ key: String, by count: Int) -> EventLoopFuture<Int> {
return send(command: "INCRBY", with: [key, count])
.mapFromRESP()
.convertFromRESPValue()
}
/// Increments the stored value by the amount desired.
......@@ -144,7 +144,7 @@ extension RedisClient {
where T: RESPValueConvertible
{
return send(command: "INCRBYFLOAT", with: [key, count])
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -159,7 +159,7 @@ extension RedisClient {
@inlinable
public func decrement(_ key: String) -> EventLoopFuture<Int> {
return send(command: "DECR", with: [key])
.mapFromRESP()
.convertFromRESPValue()
}
/// Decrements the stored valye by the amount desired.
......@@ -171,6 +171,6 @@ extension RedisClient {
/// - Returns: The new value after the operation.
public func decrement(_ key: String, by count: Int) -> EventLoopFuture<Int> {
return send(command: "DECRBY", with: [key, count])
.mapFromRESP()
.convertFromRESPValue()
}
}
......@@ -20,7 +20,7 @@ extension EventLoopFuture where Value == RESPValue {
/// - Parameter to: The desired type to convert to.
/// - Returns: An `EventLoopFuture` that resolves a value of the desired type.
@inlinable
public func mapFromRESP<T>(
public func convertFromRESPValue<T>(
to type: T.Type = T.self,
file: StaticString = #function,
function: StaticString = #function,
......
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