RedisClient
public protocol RedisClient
An object capable of sending commands and receiving responses.
let client = ...
let result = client.send(command: "GET", arguments: ["my_key"])
// result == EventLoopFuture<RESPValue>
For the full list of available commands, see https://redis.io/commands
-
The
NIO.EventLoop
that this client operates on.Declaration
Swift
var eventLoop: EventLoop { get }
-
Sends the desired command with the specified arguments.
Declaration
Parameters
command
The command to execute.
arguments
The arguments, if any, to be sent with the command.
Return Value
A
NIO.EventLoopFuture
that will resolve with the Redis command response. -
Temporarily overrides the default logger for command logs to the provided instance.
Declaration
Swift
func logging(to logger: Logger) -> RedisClient
Parameters
logger
The
Logging.Logger
instance to use for command logs.Return Value
A RedisClient with the temporary override for command logging.
-
subscribe(to:messageReceiver:onSubscribe:onUnsubscribe:)
Default implementationSubscribes the client to the specified Redis channels, invoking the provided message receiver each time a message is published.
See SUBSCRIBE
Important
This will establish the client in a “PubSub mode” where only a specific list of commands are allowed to be executed.
Commands issued with this client outside of that list will resolve with failures.
See the PubSub specification
Default Implementation
Declaration
Swift
func subscribe( to channels: [RedisChannelName], messageReceiver receiver: @escaping RedisSubscriptionMessageReceiver, onSubscribe subscribeHandler: RedisSubscriptionChangeHandler?, onUnsubscribe unsubscribeHandler: RedisSubscriptionChangeHandler? ) -> EventLoopFuture<Void>
Parameters
channels
The names of channels to subscribe to.
receiver
A closure which will be invoked each time a channel with a name in
channels
publishes a message.subscribeHandler
An optional closure to be invoked when the subscription becomes active.
unsubscribeHandler
An optional closure to be invoked when the subscription becomes inactive.
Return Value
A notification
NIO.EventLoopFuture
that resolves once the subscription has been registered with Redis. -
psubscribe(to:messageReceiver:onSubscribe:onUnsubscribe:)
Default implementationSubscribes the client to the specified Redis channel name patterns, invoking the provided message receiver each time a message is published to a matching channel.
Note
If the client is also subscribed to a channel directly by name which also matches a pattern, both subscription message receivers will be invoked.See PSUBSCRIBE
Important
This will establish the client in a “PubSub mode” where only a specific list of commands are allowed to be executed.
Commands issues with this client outside of that list will resolve with failures.
See the PubSub specification
Default Implementation
Declaration
Swift
func psubscribe( to patterns: [String], messageReceiver receiver: @escaping RedisSubscriptionMessageReceiver, onSubscribe subscribeHandler: RedisSubscriptionChangeHandler?, onUnsubscribe unsubscribeHandler: RedisSubscriptionChangeHandler? ) -> EventLoopFuture<Void>
Parameters
patterns
A list of glob patterns used for matching against PubSub channel names to subscribe to.
receiver
A closure which will be invoked each time a channel with a name matching the specified pattern(s) publishes a message.
subscribeHandler
An optional closure to be invoked when the subscription becomes active.
unsubscribeHandler
An optional closure to be invoked when the subscription becomes inactive.
Return Value
A notification
NIO.EventLoopFuture
that resolves once the subscription has been registered with Redis. -
unsubscribe(from:)
Default implementationUnsubscribes the client from a specific Redis channel from receiving any future published messages.
See UNSUBSCRIBE
Note
If the channel was not subscribed to withsubscribe(to:messageReceiver:onSubscribe:onUnsubscribe:)
, then this method has no effect.Important
If no more subscriptions (pattern or channel) are active on the client, the client will be taken out of its “PubSub mode”.
It will then be allowed to use any command like normal.
See the PubSub specification
Default Implementation
Declaration
Swift
func unsubscribe(from channels: [RedisChannelName]) -> EventLoopFuture<Void>
Parameters
channels
A list of channel names to be unsubscribed from.
Return Value
A notification
NIO.EventLoopFuture
that resolves once the subscription(s) have been removed from Redis. -
punsubscribe(from:)
Default implementationUnsubscribes the client from a pattern of Redis channel names from receiving any future published messages.
See PUNSUBSCRIBE
Note
This method does not unsubscribe subscriptions made withsubscribe(to:messageReceiver:onSubscribe:onUnsubscribe:)
.Important
If no more subscriptions (pattern or channel) are active on the client, the client will be taken out of its “PubSub mode”.
It will then be allowed to use any command like normal.
See the PubSub specification
Default Implementation
Declaration
Swift
func punsubscribe(from patterns: [String]) -> EventLoopFuture<Void>
Parameters
patterns
A list of glob patterns to be unsubscribed from.
Return Value
A notification
NIO.EventLoopFuture
that resolves once the subscription(s) have been removed from Redis. -
echo(_:)
Extension methodEchos the provided message through the Redis instance.
Declaration
Swift
public func echo(_ message: String) -> EventLoopFuture<String>
Parameters
message
The message to echo.
Return Value
The message sent with the command.
-
ping(with:)
Extension methodPings the server, which will respond with a message.
Declaration
Swift
public func ping(with message: String? = nil) -> EventLoopFuture<String>
Parameters
message
The optional message that the server should respond with.
Return Value
The provided message or Redis’ default response of
"PONG"
. -
select(database:)
Extension methodSelect the Redis logical database having the specified zero-based numeric index.
Note
New connections always use the database0
.Declaration
Swift
public func select(database index: Int) -> EventLoopFuture<Void>
Parameters
index
The 0-based index of the database that will receive later commands.
Return Value
An
EventLoopFuture
that resolves when the operation has succeeded, or fails with aRedisError
. -
swapDatabase(_:with:)
Extension methodSwaps the data of two Redis databases by their index IDs.
Declaration
Swift
public func swapDatabase(_ first: Int, with second: Int) -> EventLoopFuture<Bool>
Parameters
first
The index of the first database.
second
The index of the second database.
Return Value
true
if the swap was successful. -
authorize(with:)
Extension methodRequests the client to authenticate with Redis to allow other commands to be executed.
Declaration
Swift
public func authorize(with password: String) -> EventLoopFuture<Void>
Parameters
password
The password to authenticate with.
Return Value
A
NIO.EventLoopFuture
that resolves if the password was accepted, otherwise it fails. -
delete(_:)
Extension methodRemoves the specified keys. A key is ignored if it does not exist.
Declaration
Swift
public func delete(_ keys: [RedisKey]) -> EventLoopFuture<Int>
Parameters
keys
A list of keys to delete from the database.
Return Value
The number of keys deleted from the database.
-
delete(_:)
Extension methodRemoves the specified keys. A key is ignored if it does not exist.
Declaration
Swift
public func delete(_ keys: RedisKey...) -> EventLoopFuture<Int>
Parameters
keys
A list of keys to delete from the database.
Return Value
The number of keys deleted from the database.
-
exists(_:)
Extension methodChecks the existence of the provided keys in the database.
Declaration
Swift
public func exists(_ keys: [RedisKey]) -> EventLoopFuture<Int>
Parameters
keys
A list of keys whose existence will be checked for in the database.
Return Value
The number of provided keys which exist in the database.
-
exists(_:)
Extension methodChecks the existence of the provided keys in the database.
Declaration
Swift
public func exists(_ keys: RedisKey...) -> EventLoopFuture<Int>
Parameters
keys
A list of keys whose existence will be checked for in the database.
Return Value
The number of provided keys which exist in the database.
-
expire(_:after:)
Extension methodSets a timeout on key. After the timeout has expired, the key will automatically be deleted.
Note
A key with an associated timeout is often said to be “volatile” in Redis terminology.Declaration
Swift
public func expire(_ key: RedisKey, after timeout: TimeAmount) -> EventLoopFuture<Bool>
Parameters
key
The key to set the expiration on.
timeout
The time from now the key will expire at.
Return Value
true
if the expiration was set.
-
ttl(_:)
Extension methodReturns the remaining time-to-live (in seconds) of the provided key.
Parameters
key
The key to check the time-to-live on.
Return Value
The number of seconds before the given key will expire.
-
pttl(_:)
Extension methodReturns the remaining time-to-live (in milliseconds) of the provided key.
Parameters
key
The key to check the time-to-live on.
Return Value
The number of milliseconds before the given key will expire.
-
scan(startingFrom:matching:count:)
Extension methodIncrementally iterates over all keys in the currently selected database.
Declaration
Swift
public func scan( startingFrom position: Int = 0, matching match: String? = nil, count: Int? = nil ) -> EventLoopFuture<(Int, [String])>
Parameters
position
The cursor position to start from.
match
A glob-style pattern to filter values to be selected from the result set.
count
The number of elements to advance by. Redis default is 10.
Return Value
A cursor position for additional invocations with a limited collection of keys found in the database.
-
hdel(_:from:)
Extension methodRemoves the specified fields from a hash.
Declaration
Swift
public func hdel(_ fields: [String], from key: RedisKey) -> EventLoopFuture<Int>
Parameters
fields
The list of field names that should be removed from the hash.
key
The key of the hash to delete from.
Return Value
The number of fields that were deleted.
-
hdel(_:from:)
Extension methodRemoves the specified fields from a hash.
Declaration
Swift
public func hdel(_ fields: String..., from key: RedisKey) -> EventLoopFuture<Int>
Parameters
fields
The list of field names that should be removed from the hash.
key
The key of the hash to delete from.
Return Value
The number of fields that were deleted.
-
hexists(_:in:)
Extension methodChecks if a hash contains the field specified.
Declaration
Swift
public func hexists(_ field: String, in key: RedisKey) -> EventLoopFuture<Bool>
Parameters
field
The field name to look for.
key
The key of the hash to look within.
Return Value
true
if the hash contains the field,false
if either the key or field do not exist. -
hlen(of:)
Extension methodGets the number of fields contained in a hash.
Declaration
Swift
public func hlen(of key: RedisKey) -> EventLoopFuture<Int>
Parameters
key
The key of the hash to get field count of.
Return Value
The number of fields in the hash, or
0
if the key doesn’t exist. -
hstrlen(of:in:)
Extension methodGets the string length of a hash field’s value.
Declaration
Swift
public func hstrlen(of field: String, in key: RedisKey) -> EventLoopFuture<Int>
Parameters
field
The field name whose value is being accessed.
key
The key of the hash.
Return Value
The string length of the hash field’s value, or
0
if the field or hash do not exist. -
hkeys(in:)
Extension methodGets all field names in a hash.
Declaration
Swift
public func hkeys(in key: RedisKey) -> EventLoopFuture<[String]>
Parameters
key
The key of the hash.
Return Value
A list of field names stored within the hash.
-
hvals(in:)
Extension methodGets all values stored in a hash.
Parameters
key
The key of the hash.
Return Value
A list of all values stored in a hash.
-
hvals(in:as:)
Extension methodGets all values stored in a hash.
Declaration
Swift
@inlinable public func hvals<Value>(in key: RedisKey, as type: Value.Type) -> EventLoopFuture<[Value?]> where Value : RESPValueConvertible
Parameters
key
The key of the hash.
type
The type to convert the values to.
Return Value
A list of all values stored in a hash.
-
hscan(_:startingFrom:matching:count:valueType:)
Extension methodIncrementally iterates over all fields in a hash.
Declaration
Swift
@inlinable public func hscan<Value: RESPValueConvertible>( _ key: RedisKey, startingFrom position: Int = 0, matching match: String? = nil, count: Int? = nil, valueType: Value.Type ) -> EventLoopFuture<(Int, [String: Value?])>
Parameters
key
The key of the hash.
position
The position to start the scan from.
match
A glob-style pattern to filter values to be selected from the result set.
count
The number of elements to advance by. Redis default is 10.
valueType
The type to cast all values to.
Return Value
A cursor position for additional invocations with a limited collection of found fields and their values.
-
hscan(_:startingFrom:matching:count:)
Extension methodIncrementally iterates over all fields in a hash.
Declaration
Parameters
key
The key of the hash.
position
The position to start the scan from.
match
A glob-style pattern to filter values to be selected from the result set.
count
The number of elements to advance by. Redis default is 10.
Return Value
A cursor position for additional invocations with a limited collection of found fields and their values.
-
hset(_:to:in:)
Extension methodSets a hash field to the value specified.
Note
If you do not want to overwrite existing values, usehsetnx(_:field:to:)
.Declaration
Swift
@inlinable public func hset<Value: RESPValueConvertible>( _ field: String, to value: Value, in key: RedisKey ) -> EventLoopFuture<Bool>
Parameters
field
The name of the field in the hash being set.
value
The value the hash field should be set to.
key
The key that holds the hash.
Return Value
true
if the hash was created,false
if it was updated. -
hsetnx(_:to:in:)
Extension methodSets a hash field to the value specified only if the field does not currently exist.
Note
If you do not care about overwriting existing values, usehset(_:field:to:)
.Declaration
Swift
@inlinable public func hsetnx<Value: RESPValueConvertible>( _ field: String, to value: Value, in key: RedisKey ) -> EventLoopFuture<Bool>
Parameters
field
The name of the field in the hash being set.
value
The value the hash field should be set to.
key
The key that holds the hash.
Return Value
true
if the hash was created. -
hmset(_:in:)
Extension methodSets the fields in a hash to the respective values provided.
Declaration
Swift
@inlinable public func hmset<Value: RESPValueConvertible>( _ fields: [String: Value], in key: RedisKey ) -> EventLoopFuture<Void>
Parameters
fields
The key-value pair of field names and their respective values to set.
key
The key that holds the hash.
Return Value
An
EventLoopFuture
that resolves when the operation has succeeded, or fails with aRedisError
.
-
hget(_:from:)
Extension methodGets a hash field’s value.
Declaration
Parameters
field
The name of the field whose value is being accessed.
key
The key of the hash being accessed.
Return Value
The value of the hash field. If the key or field does not exist, it will be
.null
. -
hget(_:from:as:)
Extension methodGets a hash field’s value as the desired type.
Declaration
Swift
@inlinable public func hget<Value: RESPValueConvertible>( _ field: String, from key: RedisKey, as type: Value.Type ) -> EventLoopFuture<Value?>
Parameters
field
The name of the field whose value is being accessed.
key
The key of the hash being accessed.
type
The type to convert the value to.
Return Value
The value of the hash field, or
nil
if theRESPValue
conversion fails or either the key or field does not exist. -
hmget(_:from:)
Extension methodGets the values of a hash for the fields specified.
Declaration
Parameters
fields
A list of field names to get values for.
key
The key of the hash being accessed.
Return Value
A list of values in the same order as the
fields
argument. Non-existent fields return.null
values. -
hmget(_:from:as:)
Extension methodGets the values of a hash for the fields specified as a specific type.
Declaration
Swift
@inlinable public func hmget<Value: RESPValueConvertible>( _ fields: [String], from key: RedisKey, as type: Value.Type ) -> EventLoopFuture<[Value?]>
Parameters
fields
A list of field names to get values for.
key
The key of the hash being accessed.
type
The type to convert the values to.
Return Value
A list of values in the same order as the
fields
argument. Non-existent fields and elements that fail theRESPValue
conversion returnnil
values. -
hmget(_:from:)
Extension methodGets the values of a hash for the fields specified.
Declaration
Parameters
fields
A list of field names to get values for.
key
The key of the hash being accessed.
Return Value
A list of values in the same order as the
fields
argument. Non-existent fields return.null
values. -
hmget(_:from:as:)
Extension methodGets the values of a hash for the fields specified.
Declaration
Swift
@inlinable public func hmget<Value: RESPValueConvertible>( _ fields: String..., from key: RedisKey, as type: Value.Type ) -> EventLoopFuture<[Value?]>
Parameters
fields
A list of field names to get values for.
key
The key of the hash being accessed.
type
The type to convert the values to.
Return Value
A list of values in the same order as the
fields
argument. Non-existent fields and elements that fail theRESPValue
conversion returnnil
values. -
hgetall(from:)
Extension methodReturns all the fields and values stored in a hash.
Parameters
key
The key of the hash to pull from.
Return Value
A key-value pair list of fields and their values.
-
hgetall(from:as:)
Extension methodReturns all the fields and values stored in a hash.
Declaration
Swift
@inlinable public func hgetall<Value: RESPValueConvertible>( from key: RedisKey, as type: Value.Type ) -> EventLoopFuture<[String: Value?]>
Parameters
key
The key of the hash to pull from.
type
The type to convert the values to.
Return Value
A key-value pair list of fields and their values. Elements that fail the
RESPValue
conversion will benil
.
-
hincrby(_:field:in:)
Extension methodIncrements a hash field’s value and returns the new value.
Declaration
Swift
@inlinable public func hincrby<Value: FixedWidthInteger & RESPValueConvertible>( _ amount: Value, field: String, in key: RedisKey ) -> EventLoopFuture<Value>
Parameters
amount
The amount to increment the value stored in the field by.
field
The name of the field whose value should be incremented.
key
The key of the hash the field is stored in.
Return Value
The new value of the hash field.
-
hincrbyfloat(_:field:in:)
Extension methodIncrements a hash field’s value and returns the new value.
Declaration
Swift
@inlinable public func hincrbyfloat<Value: BinaryFloatingPoint & RESPValueConvertible>( _ amount: Value, field: String, in key: RedisKey ) -> EventLoopFuture<Value>
Parameters
amount
The amount to increment the value stored in the field by.
field
The name of the field whose value should be incremented.
key
The key of the hash the field is stored in.
Return Value
The new value of the hash field.
-
llen(of:)
Extension methodGets the length of a list.
Declaration
Swift
public func llen(of key: RedisKey) -> EventLoopFuture<Int>
Parameters
key
The key of the list.
Return Value
The number of elements in the list.
-
lindex(_:from:)
Extension methodGets the element from a list stored at the provided index position.
Declaration
Parameters
index
The 0-based index of the element to get.
key
The key of the list.
Return Value
The element stored at index, or
.null
if out of bounds. -
lindex(_:from:as:)
Extension methodGets the element from a list stored at the provided index position.
Declaration
Swift
@inlinable public func lindex<Value: RESPValueConvertible>( _ index: Int, from key: RedisKey, as type: Value.Type ) -> EventLoopFuture<Value?>
Parameters
index
The 0-based index of the element to get.
key
The key of the list.
type
The type to convert the value to.
Return Value
The element stored at index. If the value fails the
RESPValue
conversion or if the index is out of bounds, the returned value will benil
. -
lset(index:to:in:)
Extension methodSets the value of an element in a list at the provided index position.
Declaration
Swift
@inlinable public func lset<Value: RESPValueConvertible>( index: Int, to value: Value, in key: RedisKey ) -> EventLoopFuture<Void>
Parameters
index
The 0-based index of the element to set.
value
The new value the element should be.
key
The key of the list to update.
Return Value
An
EventLoopFuture
that resolves when the operation has succeeded, or fails with aRedisError
. -
lrem(_:from:count:)
Extension methodRemoves elements from a list matching the value provided.
Declaration
Swift
@inlinable public func lrem<Value: RESPValueConvertible>( _ value: Value, from key: RedisKey, count: Int = 0 ) -> EventLoopFuture<Int>
Parameters
value
The value to delete from the list.
key
The key of the list to remove from.
count
The max number of elements to remove matching the value. See Redis’ documentation for more info.
Return Value
The number of elements removed from the list.
-
ltrim(_:before:after:)
Extension methodTrims a List to only contain elements within the specified inclusive bounds of 0-based indices.
Declaration
Swift
public func ltrim(_ key: RedisKey, before start: Int, after stop: Int) -> EventLoopFuture<Void>
Parameters
key
The key of the List to trim.
start
The index of the first element to keep.
stop
The index of the last element to keep.
Return Value
A
NIO.EventLoopFuture
that resolves when the operation has succeeded, or fails with aRedisError
. -
ltrim(_:keepingIndices:)
Extension methodTrims a List to only contain elements within the specified inclusive bounds of 0-based indices.
To keep elements 4 through 7:
client.ltrim("myList", keepingIndices: 3...6)
To keep the last 4 through 7 elements:
client.ltrim("myList", keepingIndices: (-7)...(-4))
To keep the first and last 4 elements:
client.ltrim("myList", keepingIndices: (-4)...3)
See https://redis.io/commands/ltrim
Warning
A
ClosedRange
cannot be created whereupperBound
is less thanlowerBound
; so while Redis may support0...-1
,ClosedRange
will trigger a precondition failure.If you need such a range, use
ltrim(_:before:after:)
instead.Declaration
Swift
public func ltrim(_ key: RedisKey, keepingIndices range: ClosedRange<Int>) -> EventLoopFuture<Void>
Parameters
key
The key of the List to trim.
range
The range of indices that should be kept in the List.
Return Value
A
NIO.EventLoopFuture
that resolves when the operation has succeeded, or fails with aRedisError
. -
ltrim(_:keepingIndices:)
Extension methodTrims a List to only contain elements starting from the specified index.
To keep all but the first 3 elements:
client.ltrim("myList", keepingIndices: 3...)
To keep the last 4 elements:
client.ltrim("myList", keepingIndices: (-4)...)
Declaration
Swift
public func ltrim(_ key: RedisKey, keepingIndices range: PartialRangeFrom<Int>) -> EventLoopFuture<Void>
Parameters
key
The key of the List to trim.
range
The range of indices that should be kept in the List.
Return Value
A
NIO.EventLoopFuture
that resolves when the operation has succeeded, or fails with aRedisError
. -
ltrim(_:keepingIndices:)
Extension methodTrims a List to only contain elements before the specified index.
To keep the first 3 elements:
client.ltrim("myList", keepingIndices: ..<3)
To keep all but the last 4 elements:
client.ltrim("myList", keepingIndices: ..<(-4))
Declaration
Swift
public func ltrim(_ key: RedisKey, keepingIndices range: PartialRangeUpTo<Int>) -> EventLoopFuture<Void>
Parameters
key
The key of the List to trim.
range
The range of indices that should be kept in the List.
Return Value
A
NIO.EventLoopFuture
that resolves when the operation has succeeded, or fails with aRedisError
. -
ltrim(_:keepingIndices:)
Extension methodTrims a List to only contain elements up to the specified index.
To keep the first 4 elements:
client.ltrim("myList", keepingIndices: ...3)
To keep all but the last 3 elements:
client.ltrim("myList", keepingIndices: ...(-4))
Declaration
Swift
public func ltrim(_ key: RedisKey, keepingIndices range: PartialRangeThrough<Int>) -> EventLoopFuture<Void>
Parameters
key
The key of the List to trim.
range
The range of indices that should be kept in the List.
Return Value
A
NIO.EventLoopFuture
that resolves when the operation has succeeded, or fails with aRedisError
. -
ltrim(_:keepingIndices:)
Extension methodTrims a List to only contain the elements from the specified index up to the index provided.
To keep the first 4 elements:
client.ltrim("myList", keepingIndices: 0..<4)
To keep all but the last 3 elements:
client.ltrim("myList", keepingIndices: 0..<(-3))
See https://redis.io/commands/ltrim
Warning
A
Range
cannot be created whereupperBound
is less thanlowerBound
; so while Redis may support0..<(-1)
,Range
will trigger a precondition failure.If you need such a range, use
ltrim(_:before:after:)
instead.Declaration
Swift
public func ltrim(_ key: RedisKey, keepingIndices range: Range<Int>) -> EventLoopFuture<Void>
Parameters
key
The key of the List to trim.
range
The range of indices that should be kept in the List.
Return Value
A
NIO.EventLoopFuture
that resolves when the operation has succeeded, or fails with aRedisError
.
-
lrange(from:firstIndex:lastIndex:)
Extension methodGets all elements from a List within the the specified inclusive bounds of 0-based indices.
Declaration
Parameters
key
The key of the List.
firstIndex
The index of the first element to include in the range of elements returned.
lastIndex
The index of the last element to include in the range of elements returned.
Return Value
An array of elements found within the range specified.
-
lrange(from:firstIndex:lastIndex:as:)
Extension methodGets all elements from a List within the the specified inclusive bounds of 0-based indices.
Declaration
Swift
@inlinable public func lrange<Value: RESPValueConvertible>( from key: RedisKey, firstIndex: Int, lastIndex: Int, as type: Value.Type ) -> EventLoopFuture<[Value?]>
Parameters
key
The key of the List.
firstIndex
The index of the first element to include in the range of elements returned.
lastIndex
The index of the last element to include in the range of elements returned.
type
The type to convert the values to.
Return Value
An array of elements found within the range specified, otherwise
nil
if theRESPValue
conversion failed. -
lrange(from:indices:)
Extension methodGets all elements from a List within the specified inclusive bounds of 0-based indices.
To get the elements at index 4 through 7:
client.lrange(from: "myList", indices: 4...7)
To get the last 4 elements:
client.lrange(from: "myList", indices: (-4)...(-1))
To get the first and last 4 elements:
client.lrange(from: "myList", indices: (-4)...3)
To get the first element, and the last 4:
client.lrange(from: "myList", indices: (-4)...0))
See https://redis.io/commands/lrange
Warning
A
ClosedRange
cannot be created whereupperBound
is less thanlowerBound
; so while Redis may support0...-1
,ClosedRange
will trigger a precondition failure.If you need such a range, use
lrange(from:firstIndex:lastIndex:)
instead.Declaration
Parameters
key
The key of the List to return elements from.
range
The range of inclusive indices of elements to get.
Return Value
An array of elements found within the range specified.
-
lrange(from:indices:as:)
Extension methodGets all elements from a List within the specified inclusive bounds of 0-based indices.
See https://redis.io/commands/lrange.
Warning
A
ClosedRange
cannot be created whereupperBound
is less thanlowerBound
; so while Redis may support0...-1
,ClosedRange
will trigger a precondition failure.If you need such a range, use
lrange(from:firstIndex:lastIndex:)
instead.Declaration
Swift
@inlinable public func lrange<Value: RESPValueConvertible>( from key: RedisKey, indices range: ClosedRange<Int>, as type: Value.Type ) -> EventLoopFuture<[Value?]>
Parameters
key
The key of the List to return elements from.
range
The range of inclusive indices of elements to get.
type
The type to convert the values to.
Return Value
An array of elements found within the range specified, otherwise
nil
if theRESPValue
conversion failed. -
lrange(from:indices:)
Extension methodGets all the elements from a List starting with the first index bound up to, but not including, the element at the last index bound.
To get the elements at index 4 through 7:
client.lrange(from: "myList", indices: 4..<8)
To get the last 4 elements:
client.lrange(from: "myList", indices: (-4)..<0)
To get the first and last 4 elements:
client.lrange(from: "myList", indices: (-4)..<4)
To get the first element, and the last 4:
client.lrange(from: "myList", indices: (-4)..<1)
See https://redis.io/commands/lrange
Warning
A
Range
cannot be created whereupperBound
is less thanlowerBound
; so while Redis may support0..<(-1)
,Range
will trigger a precondition failure.If you need such a range, use
lrange(from:firstIndex:lastIndex:)
instead.Declaration
Parameters
key
The key of the List to return elements from.
range
The range of indices (inclusive lower, exclusive upper) elements to get.
Return Value
An array of elements found within the range specified.
-
lrange(from:indices:as:)
Extension methodGets all the elements from a List starting with the first index bound up to, but not including, the element at the last index bound.
See https://redis.io/commands/lrange
Warning
A
Range
cannot be created whereupperBound
is less thanlowerBound
; so while Redis may support0..<(-1)
,Range
will trigger a precondition failure.If you need such a range, use
lrange(from:firstIndex:lastIndex:)
instead.Declaration
Swift
@inlinable public func lrange<Value: RESPValueConvertible>( from key: RedisKey, indices range: Range<Int>, as type: Value.Type ) -> EventLoopFuture<[Value?]>
Parameters
key
The key of the List to return elements from.
range
The range of indices (inclusive lower, exclusive upper) elements to get.
type
The type to convert the values to.
Return Value
An array of elements found within the range specified, otherwise
nil
if theRESPValue
conversion failed. -
lrange(from:fromIndex:)
Extension methodGets all elements from the index specified to the end of a List.
To get all except the first 2 elements of a List:
client.lrange(from: "myList", fromIndex: 2)
To get the last 4 elements of a List:
client.lrange(from: "myList", fromIndex: -4)
See
lrange(from:indices:)
,lrange(from:firstIndex:lastIndex:)
, and https://redis.io/commands/lrangeDeclaration
Parameters
key
The key of the List to return elements from.
index
The index of the first element that will be in the returned values.
Return Value
An array of elements from the List between the index and the end.
-
lrange(from:fromIndex:as:)
Extension methodGets all elements from the index specified to the end of a List.
See
lrange(from:indices:)
,lrange(from:firstIndex:lastIndex:)
, and https://redis.io/commands/lrangeDeclaration
Swift
@inlinable public func lrange<Value: RESPValueConvertible>( from key: RedisKey, fromIndex index: Int, as type: Value.Type ) -> EventLoopFuture<[Value?]>
Parameters
key
The key of the List to return elements from.
index
The index of the first element that will be in the returned values.
type
The type to convert the values to.
Return Value
An array of elements from the List between the index and the end, otherwise
nil
if theRESPValue
conversion failed. -
lrange(from:throughIndex:)
Extension methodGets all elements from the the start of a List up to, and including, the element at the index specified.
To get the first 3 elements of a List:
client.lrange(from: "myList", throughIndex: 2)
To get all except the last 3 elements of a List:
client.lrange(from: "myList", throughIndex: -4)
See
lrange(from:indices:)
,lrange(from:firstIndex:lastIndex:)
, and https://redis.io/commands/lrangeDeclaration
Parameters
key
The key of the List to return elements from.
index
The index of the last element that will be in the returned values.
Return Value
An array of elements from the start of a List to the index.
-
lrange(from:throughIndex:as:)
Extension methodGets all elements from the the start of a List up to, and including, the element at the index specified.
See
lrange(from:indices:)
,lrange(from:firstIndex:lastIndex:)
, and https://redis.io/commands/lrangeDeclaration
Swift
@inlinable public func lrange<Value: RESPValueConvertible>( from key: RedisKey, throughIndex index: Int, as type: Value.Type ) -> EventLoopFuture<[Value?]>
Parameters
key
The key of the List to return elements from.
index
The index of the last element that will be in the returned values.
type
The type to convert the values to.
Return Value
An array of elements from the start of a List to the index, otherwise
nil
if theRESPValue
conversion failed. -
lrange(from:upToIndex:)
Extension methodGets all elements from the the start of a List up to, but not including, the element at the index specified.
To get the first 3 elements of a List:
client.lrange(from: "myList", upToIndex: 3)
To get all except the last 3 elements of a List:
client.lrange(from: "myList", upToIndex: -3)
See
lrange(from:indices:)
,lrange(from:firstIndex:lastIndex:)
, and https://redis.io/commands/lrangeDeclaration
Parameters
key
The key of the List to return elements from.
index
The index of the element to not include in the returned values.
Return Value
An array of elements from the start of the List and up to the index.
-
lrange(from:upToIndex:as:)
Extension methodGets all elements from the the start of a List up to, but not including, the element at the index specified.
See
lrange(from:indices:)
,lrange(from:firstIndex:lastIndex:)
, and https://redis.io/commands/lrangeDeclaration
Swift
@inlinable public func lrange<Value: RESPValueConvertible>( from key: RedisKey, upToIndex index: Int, as type: Value.Type ) -> EventLoopFuture<[Value?]>
Parameters
key
The key of the List to return elements from.
index
The index of the element to not include in the returned values.
type
The type to convert the values to.
Return Value
An array of elements from the start of the List and up to the index, otherwise
nil
if theRESPValue
conversion failed.
-
rpoplpush(from:to:)
Extension methodPops the last element from a source list and pushes it to a destination list.
Declaration
Parameters
source
The key of the list to pop from.
dest
The key of the list to push to.
Return Value
The element that was moved.
-
rpoplpush(from:to:valueType:)
Extension methodPops the last element from a source list and pushes it to a destination list.
Declaration
Swift
@inlinable public func rpoplpush<Value: RESPValueConvertible>( from source: RedisKey, to dest: RedisKey, valueType: Value.Type ) -> EventLoopFuture<Value?>
Parameters
source
The key of the list to pop from.
dest
The key of the list to push to.
type
The type to convert the value to.
Return Value
The element that was moved. This value is
nil
if theRESPValue
conversion failed. -
brpoplpush(from:to:timeout:)
Extension methodPops the last element from a source list and pushes it to a destination list, blocking until an element is available from the source list.
Important
This will block the connection from completing further commands until an element is available to pop from the source list.
It is highly recommended to set a reasonable
timeout
or to use the non-blockingrpoplpush
method where possible.Declaration
Parameters
source
The key of the list to pop from.
dest
The key of the list to push to.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
The element popped from the source list and pushed to the destination or
.null
if the timeout was reached. -
brpoplpush(from:to:timeout:valueType:)
Extension methodPops the last element from a source list and pushes it to a destination list, blocking until an element is available from the source list.
Important
This will block the connection from completing further commands until an element is available to pop from the source list.
It is highly recommended to set a reasonable
timeout
or to use the non-blockingrpoplpush
method where possible.Declaration
Swift
@inlinable public func brpoplpush<Value: RESPValueConvertible>( from source: RedisKey, to dest: RedisKey, timeout: TimeAmount = .seconds(0), valueType: Value.Type ) -> EventLoopFuture<Value?>
Parameters
source
The key of the list to pop from.
dest
The key of the list to push to.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.type
The type to convert the value to.
Return Value
The element popped from the source list and pushed to the destination. If the timeout was reached or
RESPValue
conversion failed, the returned value will benil
.
-
linsert(_:into:before:)
Extension methodInserts the element before the first element matching the “pivot” value specified.
Declaration
Swift
@inlinable public func linsert<Value: RESPValueConvertible>( _ element: Value, into key: RedisKey, before pivot: Value ) -> EventLoopFuture<Int>
Parameters
element
The value to insert into the list.
key
The key of the list.
pivot
The value of the element to insert before.
Return Value
The size of the list after the insert, or -1 if an element matching the pivot value was not found.
-
linsert(_:into:after:)
Extension methodInserts the element after the first element matching the “pivot” value provided.
Declaration
Swift
@inlinable public func linsert<Value: RESPValueConvertible>( _ element: Value, into key: RedisKey, after pivot: Value ) -> EventLoopFuture<Int>
Parameters
element
The value to insert into the list.
key
The key of the list.
pivot
The value of the element to insert after.
Return Value
The size of the list after the insert, or -1 if an element matching the pivot value was not found.
-
lpop(from:)
Extension methodRemoves the first element of a list.
Parameters
key
The key of the list to pop from.
Return Value
The element that was popped from the list, or
.null
. -
lpop(from:as:)
Extension methodRemoves the first element of a list.
Declaration
Swift
@inlinable public func lpop<Value>(from key: RedisKey, as type: Value.Type) -> EventLoopFuture<Value?> where Value : RESPValueConvertible
Parameters
key
The key of the list to pop from.
type
The type to convert the value to.
Return Value
The element that was popped from the list. If the list is empty or the
RESPValue
conversion failed, this value isnil
. -
lpush(_:into:)
Extension methodPushes all of the provided elements into a list.
Note
This inserts the elements at the head of the list; for the tail seerpush(_:into:)
.Declaration
Swift
@inlinable public func lpush<Value>(_ elements: [Value], into key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Parameters
elements
The values to push into the list.
key
The key of the list.
Return Value
The length of the list after adding the new elements.
-
lpush(_:into:)
Extension methodPushes all of the provided elements into a list.
Note
This inserts the elements at the head of the list; for the tail seerpush(_:into:)
.Declaration
Swift
@inlinable public func lpush<Value>(_ elements: Value..., into key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Parameters
elements
The values to push into the list.
key
The key of the list.
Return Value
The length of the list after adding the new elements.
-
lpushx(_:into:)
Extension methodPushes an element into a list, but only if the key exists and holds a list.
Note
This inserts the element at the head of the list, for the tail seerpushx(_:into:)
.Declaration
Swift
@inlinable public func lpushx<Value>(_ element: Value, into key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Parameters
element
The value to try and push into the list.
key
The key of the list.
Return Value
The length of the list after adding the new elements.
-
rpop(from:)
Extension methodRemoves the last element a list.
Parameters
key
The key of the list to pop from.
Return Value
The element that was popped from the list, else
.null
. -
rpop(from:as:)
Extension methodRemoves the last element a list.
Declaration
Swift
@inlinable public func rpop<Value>(from key: RedisKey, as type: Value.Type) -> EventLoopFuture<Value?> where Value : RESPValueConvertible
Parameters
key
The key of the list to pop from.
Return Value
The element that was popped from the list. If the list is empty or the
RESPValue
conversion fails, this value isnil
. -
rpush(_:into:)
Extension methodPushes all of the provided elements into a list.
Note
This inserts the elements at the tail of the list; for the head seelpush(_:into:)
.See https://redis.io/commands/rpush - elements: The values to push into the list. - key: The key of the list.
Declaration
Swift
@inlinable public func rpush<Value>(_ elements: [Value], into key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Return Value
The length of the list after adding the new elements.
-
rpush(_:into:)
Extension methodPushes all of the provided elements into a list.
Note
This inserts the elements at the tail of the list; for the head seelpush(_:into:)
.See https://redis.io/commands/rpush - elements: The values to push into the list. - key: The key of the list.
Declaration
Swift
@inlinable public func rpush<Value>(_ elements: Value..., into key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Return Value
The length of the list after adding the new elements.
-
rpushx(_:into:)
Extension methodPushes an element into a list, but only if the key exists and holds a list.
Note
This inserts the element at the tail of the list; for the head seelpushx(_:into:)
.Declaration
Swift
@inlinable public func rpushx<Value>(_ element: Value, into key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Parameters
element
The value to try and push into the list.
key
The key of the list.
Return Value
The length of the list after adding the new elements.
-
blpop(from:timeout:)
Extension methodRemoves the first element of a list, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the list.
It is highly recommended to set a reasonable
timeout
or to use the non-blockinglpop
method where possible.Declaration
Parameters
key
The key of the list to pop from.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
The element that was popped from the list, or
.null
if the timeout was reached. -
blpop(from:as:timeout:)
Extension methodRemoves the first element of a list, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the list.
It is highly recommended to set a reasonable
timeout
or to use the non-blockinglpop
method where possible.Declaration
Swift
@inlinable public func blpop<Value: RESPValueConvertible>( from key: RedisKey, as type: Value.Type, timeout: TimeAmount = .seconds(0) ) -> EventLoopFuture<Value?>
Parameters
key
The key of the list to pop from.
type
The type to convert the value to.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
The element that was popped from the list. If the timeout was reached or
RESPValue
conversion failed,nil
. -
blpop(from:timeout:)
Extension methodRemoves the first element of a list, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the group of lists.
It is highly recommended to set a reasonable
timeout
or to use the non-blockinglpop
method where possible.Declaration
Parameters
keys
The keys of lists in Redis that should be popped from.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
If timeout was reached,
nil
.Otherwise, the key of the list the element was removed from and the popped element.
-
blpop(from:timeout:valueType:)
Extension methodRemoves the first element of a list, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the group of lists.
It is highly recommended to set a reasonable
timeout
or to use the non-blockinglpop
method where possible.Declaration
Swift
@inlinable public func blpop<Value: RESPValueConvertible>( from keys: [RedisKey], timeout: TimeAmount = .seconds(0), valueType: Value.Type ) -> EventLoopFuture<(RedisKey, Value)?>
Parameters
keys
The keys of lists in Redis that should be popped from.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.valueType
The type to convert the value to.
Return Value
If timeout was reached or the
RESPValue
conversion failed,nil
.Otherwise, the key of the list the element was removed from and the popped element.
-
blpop(from:timeout:)
Extension methodRemoves the first element of a list, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the group of lists.
It is highly recommended to set a reasonable
timeout
or to use the non-blockinglpop
method where possible.Declaration
Parameters
keys
The keys of lists in Redis that should be popped from.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
If timeout was reached,
nil
.Otherwise, the key of the list the element was removed from and the popped element.
-
blpop(from:timeout:valueType:)
Extension methodRemoves the first element of a list, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the group of lists.
It is highly recommended to set a reasonable
timeout
or to use the non-blockinglpop
method where possible.Declaration
Swift
@inlinable public func blpop<Value: RESPValueConvertible>( from keys: RedisKey..., timeout: TimeAmount = .seconds(0), valueType: Value.Type ) -> EventLoopFuture<(RedisKey, Value)?>
Parameters
keys
The keys of lists in Redis that should be popped from.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.valueType
The type to convert the value to.
Return Value
If timeout was reached or
RESPValue
conversion failed,nil
.Otherwise, the key of the list the element was removed from and the popped element.
-
brpop(from:timeout:)
Extension methodRemoves the last element of a list, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the list.
It is highly recommended to set a reasonable
timeout
or to use the non-blockingrpop
method where possible.Declaration
Parameters
key
The key of the list to pop from.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
The element that was popped from the list, or
.null
if the timeout was reached. -
brpop(from:as:timeout:)
Extension methodRemoves the last element of a list, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the list.
It is highly recommended to set a reasonable
timeout
or to use the non-blockingrpop
method where possible.Declaration
Swift
@inlinable public func brpop<Value: RESPValueConvertible>( from key: RedisKey, as type: Value.Type, timeout: TimeAmount = .seconds(0) ) -> EventLoopFuture<Value?>
Parameters
key
The key of the list to pop from.
type
The type to convert the value to.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
The element that was popped from the list. If the timeout was reached or the
RESPValue
conversion fails, this value isnil
. -
brpop(from:timeout:)
Extension methodRemoves the last element of a list, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the group of lists.
It is highly recommended to set a reasonable
timeout
or to use the non-blockingrpop
method where possible.Declaration
Parameters
keys
The keys of lists in Redis that should be popped from.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
If timeout was reached,
nil
.Otherwise, the key of the list the element was removed from and the popped element.
-
brpop(from:timeout:valueType:)
Extension methodRemoves the last element of a list, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the group of lists.
It is highly recommended to set a reasonable
timeout
or to use the non-blockingrpop
method where possible.Declaration
Swift
@inlinable public func brpop<Value: RESPValueConvertible>( from keys: [RedisKey], timeout: TimeAmount = .seconds(0), valueType: Value.Type ) -> EventLoopFuture<(RedisKey, Value)?>
Parameters
keys
The keys of lists in Redis that should be popped from.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
If timeout was reached or
RESPValue
conversion failed,nil
.Otherwise, the key of the list the element was removed from and the popped element.
-
brpop(from:timeout:)
Extension methodRemoves the last element of a list, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the group of lists.
It is highly recommended to set a reasonable
timeout
or to use the non-blockingrpop
method where possible.Declaration
Parameters
keys
The keys of lists in Redis that should be popped from.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
If timeout was reached,
nil
.Otherwise, the key of the list the element was removed from and the popped element.
-
brpop(from:timeout:valueType:)
Extension methodRemoves the last element of a list, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the group of lists.
It is highly recommended to set a reasonable
timeout
or to use the non-blockingrpop
method where possible.Declaration
Swift
@inlinable public func brpop<Value: RESPValueConvertible>( from keys: RedisKey..., timeout: TimeAmount = .seconds(0), valueType: Value.Type ) -> EventLoopFuture<(RedisKey, Value)?>
Parameters
keys
The keys of lists in Redis that should be popped from.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
If timeout was reached or
RESPValue
conversion failed,nil
.Otherwise, the key of the list the element was removed from and the popped element.
-
publish(_:to:)
Extension methodPublishes the provided message to a specific Redis channel.
See PUBLISH
Declaration
Swift
@discardableResult @inlinable public func publish<Message: RESPValueConvertible>( _ message: Message, to channel: RedisChannelName ) -> EventLoopFuture<Int>
Parameters
message
The “message” value to publish on the channel.
channel
The name of the channel to publish the message to.
Return Value
The number of subscribed clients that received the message.
-
activeChannels(matching:)
Extension methodResolves a list of all the channels that have at least 1 (non-pattern) subscriber.
See PUBSUB CHANNELS
Note
If nomatch
pattern is provided, all active channels will be returned.Declaration
Swift
public func activeChannels(matching match: String? = nil) -> EventLoopFuture<[RedisChannelName]>
Parameters
match
An optional pattern of channel names to filter for.
Return Value
A list of all active channel names.
-
patternSubscriberCount()
Extension methodResolves the total count of active subscriptions to channels that were made using patterns.
See PUBSUB NUMPAT
Declaration
Swift
public func patternSubscriberCount() -> EventLoopFuture<Int>
Return Value
The total count of subscriptions made through patterns.
-
subscriberCount(forChannels:)
Extension methodResolves a count of (non-pattern) subscribers for each given channel.
See PUBSUB NUMSUB
Declaration
Swift
public func subscriberCount(forChannels channels: [RedisChannelName]) -> EventLoopFuture<[RedisChannelName : Int]>
Parameters
channels
A list of channel names to collect the subscriber counts for.
Return Value
A mapping of channel names and their (non-pattern) subscriber count.
-
smembers(of:)
Extension methodGets all of the elements contained in a set.
Note
Ordering of results are stable between multiple calls of this method to the same set.Results are UNSTABLE in regards to the ordering of insertions through the
sadd
command and this method.Parameters
key
The key of the set.
Return Value
A list of elements found within the set.
-
smembers(of:as:)
Extension methodGets all of the elements contained in a set.
Note
Ordering of results are stable between multiple calls of this method to the same set.Results are UNSTABLE in regards to the ordering of insertions through the
sadd
command and this method.Declaration
Swift
@inlinable public func smembers<Value>(of key: RedisKey, as type: Value.Type) -> EventLoopFuture<[Value?]> where Value : RESPValueConvertible
Parameters
key
The key of the set.
type
The type to convert the values to.
Return Value
A list of elements found within the set. Elements that fail the
RESPValue
conversion will benil
. -
sismember(_:of:)
Extension methodChecks if the element is included in a set.
Declaration
Swift
@inlinable public func sismember<Value>(_ element: Value, of key: RedisKey) -> EventLoopFuture<Bool> where Value : RESPValueConvertible
Parameters
element
The element to look for in the set.
key
The key of the set to look in.
Return Value
true
if the element is in the set. -
scard(of:)
Extension methodGets the total count of elements within a set.
Declaration
Swift
public func scard(of key: RedisKey) -> EventLoopFuture<Int>
Parameters
key
The key of the set.
Return Value
The total count of elements in the set.
-
sadd(_:to:)
Extension methodAdds elements to a set.
Declaration
Swift
@inlinable public func sadd<Value>(_ elements: [Value], to key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Parameters
elements
The values to add to the set.
key
The key of the set to insert into.
Return Value
The number of elements that were added to the set.
-
sadd(_:to:)
Extension methodAdds elements to a set.
Declaration
Swift
@inlinable public func sadd<Value>(_ elements: Value..., to key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Parameters
elements
The values to add to the set.
key
The key of the set to insert into.
Return Value
The number of elements that were added to the set.
-
srem(_:from:)
Extension methodRemoves elements from a set.
Declaration
Swift
@inlinable public func srem<Value>(_ elements: [Value], from key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Parameters
elements
The values to remove from the set.
key
The key of the set to remove from.
Return Value
The number of elements that were removed from the set.
-
srem(_:from:)
Extension methodRemoves elements from a set.
Declaration
Swift
@inlinable public func srem<Value>(_ elements: Value..., from key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Parameters
elements
The values to remove from the set.
key
The key of the set to remove from.
Return Value
The number of elements that were removed from the set.
-
spop(from:max:)
Extension methodRandomly selects and removes one or more elements in a set.
Declaration
Parameters
key
The key of the set.
count
The max number of elements to pop from the set.
Return Value
The element that was popped from the set.
-
spop(from:as:max:)
Extension methodRandomly selects and removes one or more elements in a set.
Declaration
Swift
@inlinable public func spop<Value: RESPValueConvertible>( from key: RedisKey, as type: Value.Type, max count: Int = 1 ) -> EventLoopFuture<[Value?]>
Parameters
key
The key of the set.
type
The type to convert the values to.
count
The max number of elements to pop from the set.
Return Value
The element that was popped from the set. Elements that fail the
RESPValue
conversion will benil
. -
srandmember(from:max:)
Extension methodRandomly selects one or more elements in a set.
connection.srandmember("my_key") // pulls just one random element connection.srandmember("my_key", max: -3) // pulls up to 3 elements, allowing duplicates connection.srandmember("my_key", max: 3) // pulls up to 3 elements, guaranteed unique
Declaration
Parameters
key
The key of the set.
count
The max number of elements to select from the set.
Return Value
The elements randomly selected from the set.
-
srandmember(from:as:max:)
Extension methodRandomly selects one or more elements in a set.
Declaration
Swift
@inlinable public func srandmember<Value: RESPValueConvertible>( from key: RedisKey, as type: Value.Type, max count: Int = 1 ) -> EventLoopFuture<[Value?]>
Parameters
key
The key of the set.
count
The max number of elements to select from the set.
Return Value
The elements randomly selected from the set. Elements that fail the
RESPValue
conversion will benil
. -
smove(_:from:to:)
Extension methodMoves an element from one set to another.
Declaration
Swift
@inlinable public func smove<Value: RESPValueConvertible>( _ element: Value, from sourceKey: RedisKey, to destKey: RedisKey ) -> EventLoopFuture<Bool>
Parameters
element
The value to move from the source.
sourceKey
The key of the source set.
destKey
The key of the destination set.
Return Value
true
if the element was successfully removed from the source set. -
sscan(_:startingFrom:matching:count:)
Extension methodIncrementally iterates over all values in a set.
Declaration
Parameters
key
The key of the set.
position
The position to start the scan from.
count
The number of elements to advance by. Redis default is 10.
match
A glob-style pattern to filter values to be selected from the result set.
Return Value
A cursor position for additional invocations with a limited collection of elements found in the set.
-
sscan(_:startingFrom:matching:count:valueType:)
Extension methodIncrementally iterates over all values in a set.
Declaration
Swift
@inlinable public func sscan<Value: RESPValueConvertible>( _ key: RedisKey, startingFrom position: Int = 0, matching match: String? = nil, count: Int? = nil, valueType: Value.Type ) -> EventLoopFuture<(Int, [Value?])>
Parameters
key
The key of the set.
position
The position to start the scan from.
match
A glob-style pattern to filter values to be selected from the result set.
count
The number of elements to advance by. Redis default is 10.
valueType
The type to convert the value to.
Return Value
A cursor position for additional invocations with a limited collection of elements found in the set. Elements that fail the
RESPValue
conversion will benil
.
-
sdiff(of:)
Extension methodCalculates the difference between two or more sets.
Parameters
keys
The source sets to calculate the difference of.
Return Value
A list of elements resulting from the difference.
-
sdiff(of:valueType:)
Extension methodCalculates the difference between two or more sets.
Declaration
Swift
@inlinable public func sdiff<Value>(of keys: [RedisKey], valueType: Value.Type) -> EventLoopFuture<[Value?]> where Value : RESPValueConvertible
Parameters
keys
The source sets to calculate the difference of.
valueType
The type to convert the values to.
Return Value
A list of elements resulting from the difference. Elements that fail the
RESPValue
conversion will benil
. -
sdiff(of:)
Extension methodCalculates the difference between two or more sets.
Parameters
keys
The source sets to calculate the difference of.
Return Value
A list of elements resulting from the difference.
-
sdiff(of:valueType:)
Extension methodCalculates the difference between two or more sets.
Declaration
Swift
@inlinable public func sdiff<Value>(of keys: RedisKey..., valueType: Value.Type) -> EventLoopFuture<[Value?]> where Value : RESPValueConvertible
Parameters
keys
The source sets to calculate the difference of.
valueType
The type to convert the values to.
Return Value
A list of elements resulting from the difference. Elements that fail the
RESPValue
conversion will benil
. -
sdiffstore(as:sources:)
Extension methodCalculates the difference between two or more sets and stores the result.
Important
If the destination key already exists, it is overwritten.Declaration
Parameters
destination
The key of the new set from the result.
sources
The list of source sets to calculate the difference of.
Return Value
The number of elements in the difference result.
-
sinter(of:)
Extension methodCalculates the intersection of two or more sets.
Parameters
keys
The source sets to calculate the intersection of.
Return Value
A list of elements resulting from the intersection.
-
sinter(of:valueType:)
Extension methodCalculates the intersection of two or more sets.
Declaration
Swift
@inlinable public func sinter<Value>(of keys: [RedisKey], valueType: Value.Type) -> EventLoopFuture<[Value?]> where Value : RESPValueConvertible
Parameters
keys
The source sets to calculate the intersection of.
valueType
The type to convert all values to.
Return Value
A list of elements resulting from the intersection. Elements that fail the
RESPValue
conversion will benil
. -
sinter(of:)
Extension methodCalculates the intersection of two or more sets.
Parameters
keys
The source sets to calculate the intersection of.
Return Value
A list of elements resulting from the intersection.
-
sinter(of:valueType:)
Extension methodCalculates the intersection of two or more sets.
Declaration
Swift
@inlinable public func sinter<Value>(of keys: RedisKey..., valueType: Value.Type) -> EventLoopFuture<[Value?]> where Value : RESPValueConvertible
Parameters
keys
The source sets to calculate the intersection of.
valueType
The type to convert all values to.
Return Value
A list of elements resulting from the intersection. Elements that fail the
RESPValue
conversion will benil
. -
sinterstore(as:sources:)
Extension methodCalculates the intersetion of two or more sets and stores the result.
Important
If the destination key already exists, it is overwritten.Declaration
Parameters
destination
The key of the new set from the result.
sources
A list of source sets to calculate the intersection of.
Return Value
The number of elements in the intersection result.
-
sunion(of:)
Extension methodCalculates the union of two or more sets.
Parameters
keys
The source sets to calculate the union of.
Return Value
A list of elements resulting from the union.
-
sunion(of:valueType:)
Extension methodCalculates the union of two or more sets.
Declaration
Swift
@inlinable public func sunion<Value>(of keys: [RedisKey], valueType: Value.Type) -> EventLoopFuture<[Value?]> where Value : RESPValueConvertible
Parameters
keys
The source sets to calculate the union of.
valueType
The type to convert all values to.
Return Value
A list of elements resulting from the union. Elements that fail the
RESPValue
conversion will benil
. -
sunion(of:)
Extension methodCalculates the union of two or more sets.
Parameters
keys
The source sets to calculate the union of.
Return Value
A list of elements resulting from the union.
-
sunion(of:valueType:)
Extension methodCalculates the union of two or more sets.
Declaration
Swift
@inlinable public func sunion<Value>(of keys: RedisKey..., valueType: Value.Type) -> EventLoopFuture<[Value?]> where Value : RESPValueConvertible
Parameters
keys
The source sets to calculate the union of.
valueType
The type to convert all values to.
Return Value
A list of elements resulting from the union. Elements that fail the
RESPValue
conversion will benil
. -
sunionstore(as:sources:)
Extension methodCalculates the union of two or more sets and stores the result.
Important
If the destination key already exists, it is overwritten.Declaration
Parameters
destination
The key of the new set from the result.
sources
A list of source sets to calculate the union of.
Return Value
The number of elements in the union result.
-
zadd(_:to:inserting:returning:)
Extension methodAdds elements to a sorted set, assigning their score to the values provided.
Declaration
Swift
@inlinable public func zadd<Value: RESPValueConvertible>( _ elements: [(element: Value, score: Double)], to key: RedisKey, inserting insertBehavior: RedisZaddInsertBehavior = .allElements, returning returnBehavior: RedisZaddReturnBehavior = .insertedElementsCount ) -> EventLoopFuture<Int>
Parameters
elements
A list of elements and their score to add to the sorted set.
key
The key of the sorted set.
insertBehavior
The desired behavior of handling new and existing elements in the SortedSet.
returnBehavior
The desired behavior of what the return value should represent.
Return Value
If
returning
is.changedElementsCount
, the number of elements inserted and that had their score updated. Otherwise, just the number of new elements inserted. -
zadd(_:to:inserting:returning:)
Extension methodAdds elements to a sorted set, assigning their score to the values provided.
Declaration
Swift
@inlinable public func zadd<Value: RESPValueConvertible>( _ elements: (element: Value, score: Double)..., to key: RedisKey, inserting insertBehavior: RedisZaddInsertBehavior = .allElements, returning returnBehavior: RedisZaddReturnBehavior = .insertedElementsCount ) -> EventLoopFuture<Int>
Parameters
elements
A list of elements and their score to add to the sorted set.
key
The key of the sorted set.
insertBehavior
The desired behavior of handling new and existing elements in the SortedSet.
returnBehavior
The desired behavior of what the return value should represent.
Return Value
If
returning
is.changedElementsCount
, the number of elements inserted and that had their score updated. Otherwise, just the number of new elements inserted. -
zadd(_:to:inserting:returning:)
Extension methodAdds an element to a sorted set, assigning their score to the value provided.
Declaration
Swift
@inlinable public func zadd<Value: RESPValueConvertible>( _ element: (element: Value, score: Double), to key: RedisKey, inserting insertBehavior: RedisZaddInsertBehavior = .allElements, returning returnBehavior: RedisZaddReturnBehavior = .insertedElementsCount ) -> EventLoopFuture<Bool>
Parameters
element
The element and its score to add to the sorted set.
key
The key of the sorted set.
insertBehavior
The desired behavior of handling new and existing elements in the SortedSet.
returnBehavior
The desired behavior of what the return value should represent.
Return Value
If
returning
is.changedElementsCount
, the number of elements inserted and that had their score updated. Otherwise, just the number of new elements inserted.
-
zcard(of:)
Extension methodGets the number of elements in a sorted set.
Declaration
Swift
public func zcard(of key: RedisKey) -> EventLoopFuture<Int>
Parameters
key
The key of the sorted set.
Return Value
The number of elements in the sorted set.
-
zscore(of:in:)
Extension methodGets the score of the specified element in a stored set.
Declaration
Swift
@inlinable public func zscore<Value>(of element: Value, in key: RedisKey) -> EventLoopFuture<Double?> where Value : RESPValueConvertible
Parameters
element
The element in the sorted set to get the score for.
key
The key of the sorted set.
Return Value
The score of the element provided, or
nil
if the element is not found in the set or the set does not exist. -
zscan(_:startingFrom:matching:count:)
Extension methodIncrementally iterates over all elements in a sorted set.
Declaration
Parameters
key
The key identifying the sorted set.
position
The position to start the scan from.
match
A glob-style pattern to filter values to be selected from the result set.
count
The number of elements to advance by. Redis default is 10.
Return Value
A cursor position for additional invocations with a limited collection of elements found in the sorted set with their scores.
-
zscan(_:startingFrom:matching:count:valueType:)
Extension methodIncrementally iterates over all elements in a sorted set.
Declaration
Swift
@inlinable public func zscan<Value: RESPValueConvertible>( _ key: RedisKey, startingFrom position: Int = 0, matching match: String? = nil, count: Int? = nil, valueType: Value.Type ) -> EventLoopFuture<(Int, [(Value, Double)?])>
Parameters
key
The key identifying the sorted set.
position
The position to start the scan from.
match
A glob-style pattern to filter values to be selected from the result set.
count
The number of elements to advance by. Redis default is 10.
valueType
The type to convert the values to.
Return Value
A cursor position for additional invocations with a limited collection of elements found in the sorted set with their scores. Any element that fails the
RESPValue
conversion will benil
.
-
zrank(of:in:)
Extension methodReturns the rank (index) of the specified element in a sorted set.
Note
This treats the ordered set as ordered from low to high. For the inverse, seezrevrank(of:in:)
.Declaration
Swift
@inlinable public func zrank<Value>(of element: Value, in key: RedisKey) -> EventLoopFuture<Int?> where Value : RESPValueConvertible
Parameters
element
The element in the sorted set to search for.
key
The key of the sorted set to search.
Return Value
The index of the element, or
nil
if the key was not found. -
zrevrank(of:in:)
Extension methodReturns the rank (index) of the specified element in a sorted set.
Note
This treats the ordered set as ordered from high to low. For the inverse, seezrank(of:in:)
.Declaration
Swift
@inlinable public func zrevrank<Value>(of element: Value, in key: RedisKey) -> EventLoopFuture<Int?> where Value : RESPValueConvertible
Parameters
element
The element in the sorted set to search for.
key
The key of the sorted set to search.
Return Value
The index of the element, or
nil
if the key was not found.
-
zcount(of:withScoresBetween:)
Extension methodReturns the count of elements in a SortedSet with a score within the range specified (inclusive by default).
To get a count of elements that have at least the score of 3, but no greater than 10:
client.zcount(of: "mySortedSet", withScoresBetween: (3, 10))
To get a count of elements that have at least the score of 3, but less than 10:
client.zcount(of: "mySortedSet", withScoresBetween: (3, .exclusive(10)))
Declaration
Swift
public func zcount( of key: RedisKey, withScoresBetween range: (min: RedisZScoreBound, max: RedisZScoreBound) ) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet that will be counted.
range
The min and max score bounds that an element should have in order to be counted.
Return Value
The count of elements in the SortedSet with a score matching the range specified.
-
zcount(of:withScores:)
Extension methodReturns the count of elements in a SortedSet with a score within the inclusive range specified.
To get a count of elements that have at least the score of 3, but no greater than 10:
client.zcount(of: "mySortedSet", withScores: 3...10)
Declaration
Swift
public func zcount(of key: RedisKey, withScores range: ClosedRange<Double>) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet that will be counted.
range
The inclusive range of scores to filter elements to count.
Return Value
The count of elements in the SortedSet with a score within the range specified.
-
zcount(of:withScores:)
Extension methodReturns the count of elements in a SortedSet with a minimum score up to, but not including, a max score.
To get a count of elements that have at least the score of 3, but less than 10:
client.zcount(of: "mySortedSet", withScores: 3..<10)
Declaration
Swift
public func zcount(of key: RedisKey, withScores range: Range<Double>) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet that will be counted.
range
A range with an inclusive lower and exclusive upper bound of scores to filter elements to count.
Return Value
The count of elements in the SortedSet with a score within the range specified.
-
zcount(of:withMinimumScoreOf:)
Extension methodReturns the count of elements in a SortedSet whose score is greater than a minimum score value.
By default, the value provided will be treated as inclusive, meaning any element that has a score matching the value will be counted.
Declaration
Swift
public func zcount(of key: RedisKey, withMinimumScoreOf minScore: RedisZScoreBound) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet that will be counted.
minScore
The minimum score bound an element in the SortedSet should have in order to be counted.
Return Value
The count of elements in the SortedSet above the
minScore
threshold. -
zcount(of:withMaximumScoreOf:)
Extension methodReturns the count of elements in a SortedSet whose score is less than a maximum score value.
By default, the value provided will be treated as inclusive, meaning any element that has a score matching the value will be counted.
Declaration
Swift
public func zcount(of key: RedisKey, withMaximumScoreOf maxScore: RedisZScoreBound) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet that will be counted.
maxScore
The maximum score bound an element in the SortedSet should have in order to be counted.
exclusive
Should the
maxScore
provided be exclusive? Iftrue
, scores matching themaxScore
will not be counted.Return Value
The count of elements in the SortedSet below the
maxScore
threshold.
-
zlexcount(of:withValuesBetween:)
Extension methodReturns the count of elements in a SortedSet whose lexiographical values are between the range specified.
For example:
// "mySortedSet" contains the values [1, 2, 3, 10] each with a score of 1. client.zlexcount(of: "mySortedSet", withValuesBetween: (.inclusive(1), .inclusive(3))) // the response will resolve to 4, as both 10 and 1 have the value "1"
See
RedisZLexBound
and https://redis.io/commands/zlexcountWarning
This assumes all elements in the SortedSet have the same score. If not, the returned elements are unspecified.Declaration
Swift
@inlinable public func zlexcount<Value: CustomStringConvertible>( of key: RedisKey, withValuesBetween range: (min: RedisZLexBound<Value>, max: RedisZLexBound<Value>) ) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet that will be counted.
range
The min and max value bounds that an element should have in order to be counted.
Return Value
The count of elements in the SortedSet with values matching the range specified.
-
zlexcount(of:withMinimumValueOf:)
Extension methodReturns the count of elements in a SortedSet whose lexiographical value is greater than a minimum value.
For example with a SortedSet that contains the values [1, 2, 3, 10] and each a score of 1:
client.zlexcount(of: "mySortedSet", withMinimumValueOf: .inclusive(2)) // the response will resolve to 2, as "10" lexiographically comes before element "2" client.zlexcount(of: "mySortedSet", withMinimumValueOf: .inclusive(10)) // the response will resolve to 3, as the set is ordered as ["1", "10", "2", "3"]
See
RedisZLexBound
and https://redis.io/commands/zlexcountWarning
This assumes all elements in the SortedSet have the same score. If not, the returned elements are unspecified.Declaration
Swift
@inlinable public func zlexcount<Value: CustomStringConvertible>( of key: RedisKey, withMinimumValueOf minValue: RedisZLexBound<Value> ) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet that will be counted.
minValue
The minimum lexiographical value an element in the SortedSet should have in order to be counted.
Return Value
The count of elements in the SortedSet above the
minValue
threshold. -
zlexcount(of:withMaximumValueOf:)
Extension methodReturns the count of elements in a SortedSet whose lexiographical value is less than a maximum value.
For example with a SortedSet that contains the values [1, 2, 3, 10] and each a score of 1:
client.zlexcount(of: "mySortedSet", withMaximumValueOf: .exclusive(10)) // the response will resolve to 1, as "1" and "10" are sorted into the first 2 elements client.zlexcount(of: "mySortedSet", withMaximumValueOf: .inclusive(3)) // the response will resolve to 4, as the set is ordered as ["1", "10", "2", "3"]
See
RedisZLexBound
and https://redis.io/commands/zlexcountWarning
This assumes all elements in the SortedSet have the same score. If not, the returned elements are unspecified.Declaration
Swift
@inlinable public func zlexcount<Value: CustomStringConvertible>( of key: RedisKey, withMaximumValueOf maxValue: RedisZLexBound<Value> ) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet that will be counted.
maxValue
The maximum lexiographical value an element in the SortedSet should have in order to be counted.
Return Value
The count of elements in the SortedSet below the
maxValue
threshold.
-
zpopmin(from:max:)
Extension methodRemoves elements from a sorted set with the lowest scores.
Declaration
Parameters
key
The key identifying the sorted set in Redis.
count
The max number of elements to pop from the set.
Return Value
A list of elements popped from the sorted set with their associated score.
-
zpopmin(from:)
Extension methodRemoves the element from a sorted set with the lowest score.
Parameters
key
The key identifying the sorted set in Redis.
Return Value
The element and its associated score that was popped from the sorted set, or
nil
if set was empty. -
zpopmax(from:max:)
Extension methodRemoves elements from a sorted set with the highest scores.
Declaration
Parameters
key
The key identifying the sorted set in Redis.
count
The max number of elements to pop from the set.
Return Value
A list of elements popped from the sorted set with their associated score.
-
zpopmax(from:)
Extension methodRemoves the element from a sorted set with the highest score.
Parameters
key
The key identifying the sorted set in Redis.
Return Value
The element and its associated score that was popped from the sorted set, or
nil
if set was empty.
-
bzpopmin(from:timeout:)
Extension methodRemoves the element from a sorted set with the lowest score, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the set.
It is highly recommended to set a reasonable
timeout
or to use the non-blockingzpopmin
method where possible.Declaration
Parameters
key
The key identifying the sorted set in Redis.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
The element and its associated score that was popped from the sorted set, or
nil
if the timeout was reached. -
bzpopmin(from:timeout:)
Extension methodRemoves the element from a sorted set with the lowest score, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the group of sets.
It is highly recommended to set a reasonable
timeout
or to use the non-blockingzpopmin
method where possible.Declaration
Parameters
keys
A list of sorted set keys in Redis.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
If timeout was reached,
nil
.Otherwise, the key of the sorted set the element was removed from, the element itself, and its associated score is returned.
-
bzpopmax(from:timeout:)
Extension methodRemoves the element from a sorted set with the highest score, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the set.
It is highly recommended to set a reasonable
timeout
or to use the non-blockingzpopmax
method where possible.Declaration
Parameters
key
The key identifying the sorted set in Redis.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
The element and its associated score that was popped from the sorted set, or
nil
if the timeout was reached. -
bzpopmax(from:timeout:)
Extension methodRemoves the element from a sorted set with the highest score, blocking until an element is available.
Important
This will block the connection from completing further commands until an element is available to pop from the group of sets.
It is highly recommended to set a reasonable
timeout
or to use the non-blockingzpopmax
method where possible.Declaration
Parameters
keys
A list of sorted set keys in Redis.
timeout
The max time to wait for a value to use.
0
seconds means to wait indefinitely.Return Value
If timeout was reached,
nil
.Otherwise, the key of the sorted set the element was removed from, the element itself, and its associated score is returned.
-
zincrby(_:element:in:)
Extension methodIncrements the score of the specified element in a sorted set.
Declaration
Swift
@inlinable public func zincrby<Value: RESPValueConvertible>( _ amount: Double, element: Value, in key: RedisKey ) -> EventLoopFuture<Double>
Parameters
amount
The amount to increment this element’s score by.
element
The element to increment.
key
The key of the sorted set.
Return Value
The new score of the element.
-
zunionstore(as:sources:weights:aggregateMethod:)
Extension methodCalculates the union of two or more sorted sets and stores the result.
Note
This operation overwrites any value stored at the destination key.Declaration
Swift
public func zunionstore( as destination: RedisKey, sources: [RedisKey], weights: [Int]? = nil, aggregateMethod aggregate: RedisSortedSetAggregateMethod? = nil ) -> EventLoopFuture<Int>
Parameters
destination
The key of the new sorted set from the result.
sources
The list of sorted set keys to treat as the source of the union.
weights
The multiplying factor to apply to the corresponding
sources
key based on index of the two parameters.aggregateMethod
The method of aggregating the values of the union. If one isn’t specified, Redis will default to
.sum
.Return Value
The number of elements in the new sorted set.
-
zinterstore(as:sources:weights:aggregateMethod:)
Extension methodCalculates the intersection of two or more sorted sets and stores the result.
Note
This operation overwrites any value stored at the destination key.Declaration
Swift
public func zinterstore( as destination: RedisKey, sources: [RedisKey], weights: [Int]? = nil, aggregateMethod aggregate: RedisSortedSetAggregateMethod? = nil ) -> EventLoopFuture<Int>
Parameters
destination
The key of the new sorted set from the result.
sources
The list of sorted set keys to treat as the source of the intersection.
weights
The multiplying factor to apply to the corresponding
sources
key based on index of the two parameters.aggregateMethod
The method of aggregating the values of the intersection. If one isn’t specified, Redis will default to
.sum
.Return Value
The number of elements in the new sorted set.
-
zrange(from:firstIndex:lastIndex:includeScoresInResponse:)
Extension methodGets all elements from a SortedSet within the specified inclusive bounds of 0-based indices.
See https://redis.io/commands/zrange
Important
This treats the SortedSet as ordered from low to high.For the inverse, see
zrevrange(from:firstIndex:lastIndex:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet
firstIndex
The index of the first element to include in the range of elements returned.
lastIndex
The index of the last element to include in the range of elements returned.
Return Value
An array of elements found within the range specified.
-
zrange(from:indices:includeScoresInResponse:)
Extension methodGets all elements from a SortedSet within the specified inclusive bounds of 0-based indices.
To get the elements at index 4 through 7:
client.zrange(from: "mySortedSet", indices: 4...7)
To get the last 4 elements:
client.zrange(from: "mySortedSet", indices: (-4)...(-1))
To get the first and last 4 elements:
client.zrange(from: "mySortedSet", indices: (-4)...3)
To get the first element, and the last 4:
client.zrange(from: "mySortedSet", indices: (-4)...0))
See https://redis.io/commands/zrange
Warning
A
ClosedRange
cannot be created whereupperBound
is less thanlowerBound
; so while Redis may support0...-1
,ClosedRange
will trigger a precondition failure.If you need such a range, use
zrange(from:firstIndex:lastIndex:)
instead.Important
This treats the SortedSet as ordered from low to high.
For the inverse, see
zrevrange(from:indices:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet to return elements from.
range
The range of inclusive indices of elements to get.
Return Value
An array of elements found within the range specified.
-
zrange(from:indices:includeScoresInResponse:)
Extension methodGets all the elements from a SortedSet starting with the first index bound up to, but not including, the element at the last index bound.
To get the elements at index 4 through 7:
client.zrange(from: "mySortedSet", indices: 4..<8)
To get the last 4 elements:
client.zrange(from: "mySortedSet", indices: (-4)..<0)
To get the first and last 4 elements:
client.zrange(from: "mySortedSet", indices: (-4)..<4)
To get the first element, and the last 4:
client.zrange(from: "mySortedSet", indices: (-4)..<1)
See https://redis.io/commands/zrange
Warning
A
Range
cannot be created whereupperBound
is less thanlowerBound
; so while Redis may support0..<(-1)
,Range
will trigger a precondition failure.If you need such a range, use
zrange(from:firstIndex:lastIndex:)
instead.Important
This treats the SortedSet as ordered from low to high.
For the inverse, see
zrevrange(from:indices:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet to return elements from.
range
The range of indices (inclusive lower, exclusive upper) elements to get.
Return Value
An array of elements found within the range specified.
-
zrange(from:fromIndex:includeScoresInResponse:)
Extension methodGets all elements from the index specified to the end of a SortedSet.
To get all except the first 2 elements of a SortedSet:
client.zrange(from: "mySortedSet", fromIndex: 2)
To get the last 4 elements of a SortedSet:
client.zrange(from: "mySortedSet", fromIndex: -4)
See
zrange(from:indices:)
,zrange(from:firstIndex:lastIndex:)
, and https://redis.io/commands/zrangeImportant
This treats the SortedSet as ordered from low to high.For the inverse, see
zrevrange(from:fromIndex:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet to return elements from.
index
The index of the first element that will be in the returned values.
Return Value
An array of elements from the SortedSet between the index and the end.
-
zrange(from:throughIndex:includeScoresInResponse:)
Extension methodGets all elements from the start of a SortedSet up to, and including, the element at the index specified.
To get the first 3 elements of a SortedSet:
client.zrange(from: "mySortedSet", throughIndex: 2)
To get all except the last 3 elements of a SortedSet:
client.zrange(from: "mySortedSet", throughIndex: -4)
See
zrange(from:indices:)
,zrange(from:firstIndex:lastIndex:)
, and https://redis.io/commands/zrangeImportant
This treats the SortedSet as ordered from low to high.For the inverse, see
zrevrange(from:throughIndex:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet to return elements from.
index
The index of the last element that will be in the returned values.
Return Value
An array of elements from the start of a SortedSet to the index.
-
zrange(from:upToIndex:includeScoresInResponse:)
Extension methodGets all elements from the start of a SortedSet up to, but not including, the element at the index specified.
To get the first 3 elements of a List:
client.zrange(from: "myList", upToIndex: 3)
To get all except the last 3 elements of a List:
client.zrange(from: "myList", upToIndex: -3)
See
zrange(from:indices:)
,zrange(from:upToIndex:lastIndex:)
, and https://redis.io/commands/zrangeImportant
This treats the SortedSet as ordered from low to high.For the inverse, see
zrevrange(from:upToIndex:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet to return elements from.
index
The index of the last element to not include in the returned values.
Return Value
An array of elements from the start of the SortedSet and up to the index.
-
zrevrange(from:firstIndex:lastIndex:includeScoresInResponse:)
Extension methodGets all elements from a SortedSet within the specified inclusive bounds of 0-based indices.
See https://redis.io/commands/zrevrange
Important
This treats the SortedSet as ordered from high to low.For the inverse, see
zrange(from:firstIndex:lastIndex:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet
firstIndex
The index of the first element to include in the range of elements returned.
lastIndex
The index of the last element to include in the range of elements returned.
Return Value
An array of elements found within the range specified.
-
zrevrange(from:indices:includeScoresInResponse:)
Extension methodGets all elements from a SortedSet within the specified inclusive bounds of 0-based indices.
To get the elements at index 4 through 7:
client.zrevrange(from: "mySortedSet", indices: 4...7)
To get the last 4 elements:
client.zrevrange(from: "mySortedSet", indices: (-4)...(-1))
To get the first and last 4 elements:
client.zrevrange(from: "mySortedSet", indices: (-4)...3)
To get the first element, and the last 4:
client.zrevrange(from: "mySortedSet", indices: (-4)...0))
See https://redis.io/commands/zrevrange
Warning
A
ClosedRange
cannot be created whereupperBound
is less thanlowerBound
; so while Redis may support0...-1
,ClosedRange
will trigger a precondition failure.If you need such a range, use
zrevrange(from:firstIndex:lastIndex:)
instead.Important
This treats the SortedSet as ordered from high to low.
For the inverse, see
zrange(from:indices:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet to return elements from.
range
The range of inclusive indices of elements to get.
Return Value
An array of elements found within the range specified.
-
zrevrange(from:indices:includeScoresInResponse:)
Extension methodGets all the elements from a SortedSet starting with the first index bound up to, but not including, the element at the last index bound.
To get the elements at index 4 through 7:
client.zrevrange(from: "mySortedSet", indices: 4..<8)
To get the last 4 elements:
client.zrevrange(from: "mySortedSet", indices: (-4)..<0)
To get the first and last 4 elements:
client.zrevrange(from: "mySortedSet", indices: (-4)..<4)
To get the first element, and the last 4:
client.zrevrange(from: "mySortedSet", indices: (-4)..<1)
See https://redis.io/commands/zrevrange
Warning
A
Range
cannot be created whereupperBound
is less thanlowerBound
; so while Redis may support0..<(-1)
,Range
will trigger a precondition failure.If you need such a range, use
zrevrange(from:firstIndex:lastIndex:)
instead.Important
This treats the SortedSet as ordered from high to low.
For the inverse, see
zrange(from:indices:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet to return elements from.
range
The range of indices (inclusive lower, exclusive upper) elements to get.
Return Value
An array of elements found within the range specified.
-
zrevrange(from:fromIndex:includeScoresInResponse:)
Extension methodGets all elements from the index specified to the end of a SortedSet.
To get all except the first 2 elements of a SortedSet:
client.zrevrange(from: "mySortedSet", fromIndex: 2)
To get the last 4 elements of a SortedSet:
client.zrevrange(from: "mySortedSet", fromIndex: -4)
See
zrevrange(from:indices:)
,zrevrange(from:firstIndex:lastIndex:)
, and https://redis.io/commands/zrevrangeImportant
This treats the SortedSet as ordered from high to low.For the inverse, see
zrange(from:fromIndex:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet to return elements from.
index
The index of the first element that will be in the returned values.
Return Value
An array of elements from the SortedSet between the index and the end.
-
zrevrange(from:throughIndex:includeScoresInResponse:)
Extension methodGets all elements from the start of a SortedSet up to, and including, the element at the index specified.
To get the first 3 elements of a SortedSet:
client.zrevrange(from: "mySortedSet", throughIndex: 2)
To get all except the last 3 elements of a SortedSet:
client.zrevrange(from: "mySortedSet", throughIndex: -4)
See
zrevrange(from:indices:)
,zrevrange(from:firstIndex:lastIndex:)
, and https://redis.io/commands/zrevrangeImportant
This treats the SortedSet as ordered from high to low.For the inverse, see
zrange(from:throughIndex:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet to return elements from.
index
The index of the last element that will be in the returned values.
Return Value
An array of elements from the start of a SortedSet to the index.
-
zrevrange(from:upToIndex:includeScoresInResponse:)
Extension methodGets all elements from the start of a SortedSet up to, but not including, the element at the index specified.
To get the first 3 elements of a List:
client.zrevrange(from: "myList", upToIndex: 3)
To get all except the last 3 elements of a List:
client.zrevrange(from: "myList", upToIndex: -3)
See
zrevrange(from:indices:)
,zrevrange(from:upToIndex:lastIndex:)
, and https://redis.io/commands/zrevrangeImportant
This treats the SortedSet as ordered from high to low.For the inverse, see
zrange(from:upToIndex:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet to return elements from.
index
The index of the last element to not include in the returned values.
Return Value
An array of elements from the start of the SortedSet and up to the index.
-
Gets all elements from a SortedSet whose score is within the range specified.
See
RedisZScoreBound
and https://redis.io/commands/zrangebyscoreImportant
This treats the SortedSet as ordered from low to high.For the inverse, see
zrevrangebyscore(from:withScoresBetween:limitBy:includeScoresInResponse:)
.Declaration
Swift
public func zrangebyscore( from key: RedisKey, withScoresBetween range: (min: RedisZScoreBound, max: RedisZScoreBound), limitBy limit: (offset: Int, count: Int)? = nil, includeScoresInResponse includeScores: Bool = false ) -> EventLoopFuture<[RESPValue]>
Parameters
key
The key of the SortedSet.
range
The min and max score bounds to filter elements by.
limit
The optional offset and count of elements to query.
includeScores
Should the response array contain the elements AND their scores? If
true
, the response array will follow the pattern [Item_1, Score_1, Item_2, …]Return Value
An array of elements from the SortedSet that were within the range provided, and optionally their scores.
-
zrangebyscore(from:withScores:limitBy:includeScoresInResponse:)
Extension methodGets all elements from a SortedSet whose score is within the inclusive range specified.
See
RedisZScoreBound
and https://redis.io/commands/zrangebyscoreImportant
This treats the SortedSet as ordered from low to high.For the inverse, see
zrevrangebyscore(from:withScores:limitBy:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet.
range
The inclusive range of scores to filter elements by.
limit
The optional offset and count of elements to query.
includeScores
Should the response array contain the elements AND their scores? If
true
, the response array will follow the pattern [Item_1, Score_1, Item_2, …]Return Value
An array of elements from the SortedSet that were within the range provided, and optionally their scores.
-
zrangebyscore(from:withScores:limitBy:includeScoresInResponse:)
Extension methodGets all elements from a SortedSet whose score is at least a minimum score up to, but not including, a max score.
See
RedisZScoreBound
and https://redis.io/commands/zrangebyscoreImportant
This treats the SortedSet as ordered from low to high.For the inverse, see
zrevrangebyscore(from:withScores:limitBy:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet.
range
A range with an inclusive lower and exclusive upper bound of scores to filter elements by.
limit
The optional offset and count of elements to query.
includeScores
Should the response array contain the elements AND their scores? If
true
, the response array will follow the pattern [Item_1, Score_1, Item_2, …]Return Value
An array of elements from the SortedSet that were within the range provided, and optionally their scores.
-
Gets all elements from a SortedSet whose score is greater than a minimum score value.
See
RedisZScoreBound
and https://redis.io/commands/zrangebyscoreImportant
This treats the SortedSet as ordered from low to high.For the inverse, see
zrevrangebyscore(from:withMinimumScoreOf:limitBy:includeScoresInResponse:)
.Declaration
Swift
public func zrangebyscore( from key: RedisKey, withMinimumScoreOf minScore: RedisZScoreBound, limitBy limit: (offset: Int, count: Int)? = nil, includeScoresInResponse includeScores: Bool = false ) -> EventLoopFuture<[RESPValue]>
Parameters
key
The key of the SortedSet.
range
The minimum score bound an element in the SortedSet should have to be included in the response.
limit
The optional offset and count of elements to query.
includeScores
Should the response array contain the elements AND their scores? If
true
, the response array will follow the pattern [Item_1, Score_1, Item_2, …]Return Value
An array of elements from the SortedSet that were within the range provided, and optionally their scores.
-
Gets all elements from a SortedSet whose score is less than a maximum score value.
See
RedisZScoreBound
and https://redis.io/commands/zrangebyscoreImportant
This treats the SortedSet as ordered from low to high.For the inverse, see
zrevrangebyscore(from:withMaximumScoreOf:limitBy:includeScoresInResponse:)
.Declaration
Swift
public func zrangebyscore( from key: RedisKey, withMaximumScoreOf maxScore: RedisZScoreBound, limitBy limit: (offset: Int, count: Int)? = nil, includeScoresInResponse includeScores: Bool = false ) -> EventLoopFuture<[RESPValue]>
Parameters
key
The key of the SortedSet.
range
The maximum score bound an element in the SortedSet should have to be included in the response.
limit
The optional offset and count of elements to query.
includeScores
Should the response array contain the elements AND their scores? If
true
, the response array will follow the pattern [Item_1, Score_1, Item_2, …]Return Value
An array of elements from the SortedSet that were within the range provided, and optionally their scores.
-
Gets all elements from a SortedSet whose score is within the range specified.
See
RedisZScoreBound
and https://redis.io/commands/zrangebyscoreImportant
This treats the SortedSet as ordered from high to low.For the inverse, see
zrangebyscore(from:withScoresBetween:limitBy:includeScoresInResponse:)
.Declaration
Swift
public func zrevrangebyscore( from key: RedisKey, withScoresBetween range: (min: RedisZScoreBound, max: RedisZScoreBound), limitBy limit: (offset: Int, count: Int)? = nil, includeScoresInResponse includeScores: Bool = false ) -> EventLoopFuture<[RESPValue]>
Parameters
key
The key of the SortedSet.
range
The min and max score bounds to filter elements by.
limit
The optional offset and count of elements to query.
includeScores
Should the response array contain the elements AND their scores? If
true
, the response array will follow the pattern [Item_1, Score_1, Item_2, …]Return Value
An array of elements from the SortedSet that were within the range provided, and optionally their scores.
-
zrevrangebyscore(from:withScores:limitBy:includeScoresInResponse:)
Extension methodGets all elements from a SortedSet whose score is within the inclusive range specified.
See
RedisZScoreBound
and https://redis.io/commands/zrangebyscoreImportant
This treats the SortedSet as ordered from high to low.For the inverse, see
zrangebyscore(from:withScores:limitBy:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet.
range
The inclusive range of scores to filter elements by.
limit
The optional offset and count of elements to query.
includeScores
Should the response array contain the elements AND their scores? If
true
, the response array will follow the pattern [Item_1, Score_1, Item_2, …]Return Value
An array of elements from the SortedSet that were within the range provided, and optionally their scores.
-
zrevrangebyscore(from:withScores:limitBy:includeScoresInResponse:)
Extension methodGets all elements from a SortedSet whose score is at least a minimum score up to, but not including, a max score.
See
RedisZScoreBound
and https://redis.io/commands/zrangebyscoreImportant
This treats the SortedSet as ordered from high to low.For the inverse, see
zrangebyscore(from:withScores:limitBy:includeScoresInResponse:)
.Declaration
Parameters
key
The key of the SortedSet.
range
A range with an inclusive lower and exclusive upper bound of scores to filter elements by.
limit
The optional offset and count of elements to query.
includeScores
Should the response array contain the elements AND their scores? If
true
, the response array will follow the pattern [Item_1, Score_1, Item_2, …]Return Value
An array of elements from the SortedSet that were within the range provided, and optionally their scores.
-
Gets all elements from a SortedSet whose score is greater than a minimum score value.
See
RedisZScoreBound
and https://redis.io/commands/zrangebyscoreImportant
This treats the SortedSet as ordered from high to low.For the inverse, see
zrangebyscore(from:withMinimumScoreOf:limitBy:includeScoresInResponse:)
.Declaration
Swift
public func zrevrangebyscore( from key: RedisKey, withMinimumScoreOf minScore: RedisZScoreBound, limitBy limit: (offset: Int, count: Int)? = nil, includeScoresInResponse includeScores: Bool = false ) -> EventLoopFuture<[RESPValue]>
Parameters
key
The key of the SortedSet.
range
The minimum score bound an element in the SortedSet should have to be included in the response.
limit
The optional offset and count of elements to query.
includeScores
Should the response array contain the elements AND their scores? If
true
, the response array will follow the pattern [Item_1, Score_1, Item_2, …]Return Value
An array of elements from the SortedSet that were within the range provided, and optionally their scores.
-
Gets all elements from a SortedSet whose score is less than a maximum score value.
See
RedisZScoreBound
and https://redis.io/commands/zrangebyscoreImportant
This treats the SortedSet as ordered from high to low.For the inverse, see
zrangebyscore(from:withMaximumScoreOf:limitBy:includeScoresInResponse:)
.Declaration
Swift
public func zrevrangebyscore( from key: RedisKey, withMaximumScoreOf maxScore: RedisZScoreBound, limitBy limit: (offset: Int, count: Int)? = nil, includeScoresInResponse includeScores: Bool = false ) -> EventLoopFuture<[RESPValue]>
Parameters
key
The key of the SortedSet.
range
The maximum score bound an element in the SortedSet should have to be included in the response.
limit
The optional offset and count of elements to query.
includeScores
Should the response array contain the elements AND their scores? If
true
, the response array will follow the pattern [Item_1, Score_1, Item_2, …]Return Value
An array of elements from the SortedSet that were within the range provided, and optionally their scores.
-
zrangebylex(from:withValuesBetween:limitBy:)
Extension methodGets all elements from a SortedSet whose lexiographical values are between the range specified.
For example:
// "mySortedSet" contains the values [1, 2, 3, 10] each with a score of 1 client.zrangebylex(of: "mySortedSet", withValuesBetween: (.inclusive(1), .exclusive(3))) // the response resolves to [1, 10, 2]
See
RedisZLexBound
and https://redis.io/commands/zrangebylexWarning
This assumes all elements in the SortedSet have the same score. If not, the returned elements are unspecified.Important
This treats the SortedSet as ordered from low to high.For the inverse, see
zrevrangebylex(from:withValuesBetween:limitBy:)
.Declaration
Swift
@inlinable public func zrangebylex<Value: CustomStringConvertible>( from key: RedisKey, withValuesBetween range: (min: RedisZLexBound<Value>, max: RedisZLexBound<Value>), limitBy limit: (offset: Int, count: Int)? = nil ) -> EventLoopFuture<[RESPValue]>
Parameters
key
The key of the SortedSet that will be counted.
range
The min and max value bounds for filtering elements by.
limitBy
The optional offset and count of elements to query.
Return Value
An array of elements from the SortedSet that were within the range provided.
-
zrangebylex(from:withMinimumValueOf:limitBy:)
Extension methodGets all elements from a SortedSet whose lexiographical value is greater than a minimum value.
// "mySortedSet" contains the values [1, 2, 3, 10] each with a score of 1 client.zrangebylex(of: "mySortedSet", withMinimumValueOf: .inclusive(1)) // the response resolves to [1, 10, 2, 3]
See
RedisZLexBound
and https://redis.io/commands/zrangebylexWarning
This assumes all elements in the SortedSet have the same score. If not, the returned elements are unspecified.Important
This treats the SortedSet as ordered from low to high.For the inverse, see
zrevrangebylex(from:withMinimumValueOf:limitBy:)
.Declaration
Swift
@inlinable public func zrangebylex<Value: CustomStringConvertible>( from key: RedisKey, withMinimumValueOf minValue: RedisZLexBound<Value>, limitBy limit: (offset: Int, count: Int)? = nil ) -> EventLoopFuture<[RESPValue]>
Parameters
key
The key of the SortedSet.
minValue
The minimum lexiographical value an element in the SortedSet should have to be included in the result set.
limit
The optional offset and count of elements to query
Return Value
An array of elements from the SortedSet above the
minValue
threshold. -
zrangebylex(from:withMaximumValueOf:limitBy:)
Extension methodGets all elements from a SortedSet whose lexiographical value is less than a maximum value.
// "mySortedSet" contains the values [1, 2, 3, 10] each with a score of 1 client.zlexcount(of: "mySortedSet", withMaximumValueOf: .exclusive(2)) // the response resolves to [1, 10]
See
RedisZLexBound
and https://redis.io/commands/zrangebylexWarning
This assumes all elements in the SortedSet have the same score. If not, the returned elements are unspecified.Important
This treats the SortedSet as ordered from low to high.For the inverse, see
zrevrangebylex(from:withMaximumValueOf:limitBy:)
.Declaration
Swift
@inlinable public func zrangebylex<Value: CustomStringConvertible>( from key: RedisKey, withMaximumValueOf maxValue: RedisZLexBound<Value>, limitBy limit: (offset: Int, count: Int)? = nil ) -> EventLoopFuture<[RESPValue]>
Parameters
key
The key of the SortedSet.
minValue
The maximum lexiographical value an element in the SortedSet should have to be included in the result set.
limit
The optional offset and count of elements to query
Return Value
An array of elements from the SortedSet below the
maxValue
threshold. -
zrevrangebylex(from:withValuesBetween:limitBy:)
Extension methodGets all elements from a SortedSet whose lexiographical values are between the range specified.
For example:
// "mySortedSet" contains the values [1, 2, 3, 10] each with a score of 1 client.zrevrangebylex(of: "mySortedSet", withValuesBetween: (.inclusive(1), .exclusive(3))) // the response resolves to [2, 10 1]
See
RedisZLexBound
and https://redis.io/commands/zrevrangebylexWarning
This assumes all elements in the SortedSet have the same score. If not, the returned elements are unspecified.Important
This treats the SortedSet as ordered from high to low.For the inverse, see
zrangebylex(from:withValuesBetween:limitBy:)
.Declaration
Swift
@inlinable public func zrevrangebylex<Value: CustomStringConvertible>( from key: RedisKey, withValuesBetween range: (min: RedisZLexBound<Value>, max: RedisZLexBound<Value>), limitBy limit: (offset: Int, count: Int)? = nil ) -> EventLoopFuture<[RESPValue]>
Parameters
key
The key of the SortedSet that will be counted.
range
The min and max value bounds for filtering elements by.
limitBy
The optional offset and count of elements to query.
Return Value
An array of elements from the SortedSet that were within the range provided.
-
zrevrangebylex(from:withMinimumValueOf:limitBy:)
Extension methodGets all elements from a SortedSet whose lexiographical value is greater than a minimum value.
// "mySortedSet" contains the values [1, 2, 3, 10] each with a score of 1 client.zrevrangebylex(of: "mySortedSet", withMinimumValueOf: .inclusive(1)) // the response resolves to [3, 2, 10, 1]
See
RedisZLexBound
and https://redis.io/commands/zrevrangebylexWarning
This assumes all elements in the SortedSet have the same score. If not, the returned elements are unspecified.Important
This treats the SortedSet as ordered from high to low.For the inverse, see
zrangebylex(from:withMinimumValueOf:limitBy:)
.Declaration
Swift
@inlinable public func zrevrangebylex<Value: CustomStringConvertible>( from key: RedisKey, withMinimumValueOf minValue: RedisZLexBound<Value>, limitBy limit: (offset: Int, count: Int)? = nil ) -> EventLoopFuture<[RESPValue]>
Parameters
key
The key of the SortedSet.
minValue
The minimum lexiographical value an element in the SortedSet should have to be included in the result set.
limit
The optional offset and count of elements to query
Return Value
An array of elements from the SortedSet above the
minValue
threshold. -
zrevrangebylex(from:withMaximumValueOf:limitBy:)
Extension methodGets all elements from a SortedSet whose lexiographical value is less than a maximum value.
// "mySortedSet" contains the values [1, 2, 3, 10] each with a score of 1 client.zrevrangebylex(of: "mySortedSet", withMaximumValueOf: .exclusive(2)) // the response resolves to [10, 1]
See
RedisZLexBound
and https://redis.io/commands/zrevrangebylexWarning
This assumes all elements in the SortedSet have the same score. If not, the returned elements are unspecified.Important
This treats the SortedSet as ordered from high to low.For the inverse, see
zrangebylex(from:withMaximumValueOf:limitBy:)
.Declaration
Swift
@inlinable public func zrevrangebylex<Value: CustomStringConvertible>( from key: RedisKey, withMaximumValueOf maxValue: RedisZLexBound<Value>, limitBy limit: (offset: Int, count: Int)? = nil ) -> EventLoopFuture<[RESPValue]>
Parameters
key
The key of the SortedSet.
minValue
The maximum lexiographical value an element in the SortedSet should have to be included in the result set.
limit
The optional offset and count of elements to query
Return Value
An array of elements from the SortedSet below the
maxValue
threshold.
-
zrem(_:from:)
Extension methodRemoves the specified elements from a sorted set.
Declaration
Swift
@inlinable public func zrem<Value>(_ elements: [Value], from key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Parameters
elements
The values to remove from the sorted set.
key
The key of the sorted set.
Return Value
The number of elements removed from the set.
-
zrem(_:from:)
Extension methodRemoves the specified elements from a sorted set.
Declaration
Swift
@inlinable public func zrem<Value>(_ elements: Value..., from key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Parameters
elements
The values to remove from the sorted set.
key
The key of the sorted set.
Return Value
The number of elements removed from the set.
-
zremrangebylex(from:withValuesBetween:)
Extension methodRemoves elements from a SortedSet whose lexiographical values are between the range specified.
For example:
// "mySortedSet" contains the values [1, 2, 3, 10] each with a score of 1. client.zremrangebylex(from: "mySortedSet", withValuesBetween: (.inclusive(10), .exclusive(3)) // elements 10 and 2 were removed
See
RedisZLexBound
and https://redis.io/commands/zremrangebylexWarning
This assumes all elements in the SortedSet have the same score. If not, the elements removed are unspecified.Declaration
Swift
@inlinable public func zremrangebylex<Value: CustomStringConvertible>( from key: RedisKey, withValuesBetween range: (min: RedisZLexBound<Value>, max: RedisZLexBound<Value>) ) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
range
The min and max value bounds that an element should have to be removed.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebylex(from:withMinimumValueOf:)
Extension methodRemoves elements from a SortedSet whose lexiographical values are greater than a minimum value.
For example:
// "mySortedSet" contains the values [1, 2, 3, 10] each with a score of 1. client.zremrangebylex(from: "mySortedSet", withMinimumValueOf: .inclusive(10)) // elements 10, 2, and 3 are removed
See
RedisZLexBound
and https://redis.io/commands/zremrangebylexWarning
This assumes all elements in the SortedSet have the same score. If not, the elements removed are unspecified.Declaration
Swift
@inlinable public func zremrangebylex<Value: CustomStringConvertible>( from key: RedisKey, withMinimumValueOf minValue: RedisZLexBound<Value> ) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
minValue
The minimum lexiographical value an element in the SortedSet should have to be removed.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebylex(from:withMaximumValueOf:)
Extension methodRemoves elements from a SortedSet whose lexiographical values are less than a maximum value.
For example:
// "mySortedSet" contains the values [1, 2, 3, 10] each with a score of 1. client.zremrangebylex(from: "mySortedSet", withMaximumValueOf: .exclusive(2)) // elements 1 and 10 are removed
See
RedisZLexBound
and https://redis.io/commands/zremrangebylexWarning
This assumes all elements in the SortedSet have the same score. If not, the elements removed are unspecified.Declaration
Swift
@inlinable public func zremrangebylex<Value: CustomStringConvertible>( from key: RedisKey, withMaximumValueOf maxValue: RedisZLexBound<Value> ) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
maxValue
The maximum lexiographical value and element in the SortedSet should have to be removed.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebyrank(from:firstIndex:lastIndex:)
Extension methodRemoves all elements from a SortedSet within the specified inclusive bounds of 0-based indices.
Declaration
Swift
public func zremrangebyrank(from key: RedisKey, firstIndex: Int, lastIndex: Int) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
firstIndex
The index of the first element to remove.
lastIndex
The index of the last element to remove.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebyrank(from:indices:)
Extension methodRemoves all elements from a SortedSet within the specified inclusive bounds of 0-based indices.
See https://redis.io/commands/zremrangebyrank
Warning
A
ClosedRange
cannot be created whereupperBound
is less thanlowerBound
; so while Redis may support0...-1
,ClosedRange
will trigger a precondition failure.If you need such a range, use
zremrangebyrank(from:firstIndex:lastIndex:)
instead.Declaration
Swift
public func zremrangebyrank(from key: RedisKey, indices range: ClosedRange<Int>) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
range
The range of inclusive indices of elements to remove.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebyrank(from:indices:)
Extension methodRemoves all elements from a SortedSet starting with the first index bound up to, but not including, the element at the last index bound.
See https://redis.io/commands/zremrangebyrank
Warning
A
Range
cannot be created whereupperBound
is less thanlowerBound
; so while Redis may support0...-1
,Range
will trigger a precondition failure.If you need such a range, use
zremrangebyrank(from:firstIndex:lastIndex:)
instead.Declaration
Swift
public func zremrangebyrank(from key: RedisKey, indices range: Range<Int>) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
range
The range of indices (inclusive lower, exclusive upper) elements to remove.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebyrank(from:fromIndex:)
Extension methodRemoves all elements from the index specified to the end of a SortedSet.
Declaration
Swift
public func zremrangebyrank(from key: RedisKey, fromIndex index: Int) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
index
The index of the first element that will be removed.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebyrank(from:throughIndex:)
Extension methodRemoves all elements from the start of a SortedSet up to, and including, the element at the index specified.
Declaration
Swift
public func zremrangebyrank(from key: RedisKey, throughIndex index: Int) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
index
The index of the last element that will be removed.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebyrank(from:upToIndex:)
Extension methodRemoves all elements from the start of a SortedSet up to, but not including, the element at the index specified.
See https://redis.io/commands/zremrangebyrank
Warning
Providing an index of0
will remove all elements from the SortedSet.Declaration
Swift
public func zremrangebyrank(from key: RedisKey, upToIndex index: Int) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
index
The index of the last element to not remove.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebyscore(from:withScoresBetween:)
Extension methodRemoves elements from a SortedSet whose score is within the range specified.
See
RedisZScoreBound
and https://redis.io/commands/zremrangebyscoreDeclaration
Swift
public func zremrangebyscore( from key: RedisKey, withScoresBetween range: (min: RedisZScoreBound, max: RedisZScoreBound) ) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
range
The min and max score bounds to filter elements by.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebyscore(from:withScores:)
Extension methodRemoves elements from a SortedSet whose score is within the inclusive range specified.
See
RedisZScoreBound
and https://redis.io/commands/zremrangebyscoreDeclaration
Swift
public func zremrangebyscore(from key: RedisKey, withScores range: ClosedRange<Double>) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
range
The inclusive range of scores to filter elements by.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebyscore(from:withScores:)
Extension methodRemoves elements from a SortedSet whose score is at least a minimum score up to, but not including, a max score.
See
RedisZScoreBound
and https://redis.io/commands/zremrangebyscoreDeclaration
Swift
public func zremrangebyscore(from key: RedisKey, withScores range: Range<Double>) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
range
A range with an inclusive lower and exclusive upper bound of scores to filter elements by.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebyscore(from:withMinimumScoreOf:)
Extension methodRemoves elements from a SortedSet whose score is greater than a minimum score value.
See
RedisZScoreBound
and https://redis.io/commands/zremrangebyscoreDeclaration
Swift
public func zremrangebyscore(from key: RedisKey, withMinimumScoreOf minScore: RedisZScoreBound) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
minScore
The minimum score bound an element in the SortedSet should have to be removed.
Return Value
The count of elements that were removed from the SortedSet.
-
zremrangebyscore(from:withMaximumScoreOf:)
Extension methodRemoves elements from a SortedSet whose score is less than a maximum score value.
See
RedisZScoreBound
and https://redis.io/commands/zremrangebyscoreDeclaration
Swift
public func zremrangebyscore(from key: RedisKey, withMaximumScoreOf maxScore: RedisZScoreBound) -> EventLoopFuture<Int>
Parameters
key
The key of the SortedSet to remove elements from.
minScore
The maximum score bound an element in the SortedSet should have to be removed.
Return Value
The count of elements that were removed from the SortedSet.
-
get(_:)
Extension methodGet the value of a key.
Parameters
key
The key to fetch the value from.
Return Value
The value stored at the key provided. If the key does not exist, the value will be
.null
. -
get(_:as:)
Extension methodGet the value of a key, converting it to the desired type.
Declaration
Swift
@inlinable public func get<StoredType: RESPValueConvertible>( _ key: RedisKey, as type: StoredType.Type ) -> EventLoopFuture<StoredType?>
Parameters
key
The key to fetch the value from.
type
The desired type to convert the stored data to.
Return Value
The converted value stored at the key provided, otherwise
nil
if the key does not exist or fails the type conversion. -
mget(_:)
Extension methodGets the values of all specified keys, using
.null
to represent non-existant values.Parameters
keys
The list of keys to fetch the values from.
Return Value
The values stored at the keys provided, matching the same order.
-
mget(_:as:)
Extension methodGets the values of all specified keys, using
.null
to represent non-existant values.Declaration
Swift
@inlinable public func mget<Value>(_ keys: [RedisKey], as type: Value.Type) -> EventLoopFuture<[Value?]> where Value : RESPValueConvertible
Parameters
keys
The list of keys to fetch the values from.
type
The type to convert the values to.
Return Value
The values stored at the keys provided, matching the same order. Values that fail the
RESPValue
conversion will benil
. -
mget(_:)
Extension methodGets the values of all specified keys, using
.null
to represent non-existant values.Parameters
keys
The list of keys to fetch the values from.
Return Value
The values stored at the keys provided, matching the same order.
-
mget(_:as:)
Extension methodGets the values of all specified keys, using
.null
to represent non-existant values.Declaration
Swift
@inlinable public func mget<Value>(_ keys: RedisKey..., as type: Value.Type) -> EventLoopFuture<[Value?]> where Value : RESPValueConvertible
Parameters
keys
The list of keys to fetch the values from.
type
The type to convert the values to.
Return Value
The values stored at the keys provided, matching the same order. Values that fail the
RESPValue
conversion will benil
.
-
append(_:to:)
Extension methodAppend a value to the end of an existing entry.
Note
If the key does not exist, it is created and set as an empty string, soAPPEND
will be similar toSET
in this special case.Declaration
Swift
@inlinable public func append<Value>(_ value: Value, to key: RedisKey) -> EventLoopFuture<Int> where Value : RESPValueConvertible
Parameters
value
The value to append onto the value stored at the key.
key
The key to use to uniquely identify this value.
Return Value
The length of the key’s value after appending the additional value.
-
set(_:to:)
Extension methodSets the value stored in the key provided, overwriting the previous value.
Any previous expiration set on the key is discarded if the SET operation was successful.
Important
Regardless of the type of value stored at the key, it will be overwritten to a string value.Declaration
Swift
@inlinable public func set<Value>(_ key: RedisKey, to value: Value) -> EventLoopFuture<Void> where Value : RESPValueConvertible
Parameters
key
The key to use to uniquely identify this value.
value
The value to set the key to.
Return Value
An
EventLoopFuture
that resolves if the operation was successful. -
set(_:to:onCondition:expiration:)
Extension methodSets the key to the provided value with options to control how it is set.
Important
Regardless of the type of data stored at the key, it will be overwritten to a “string” data type.ie. If the key is a reference to a Sorted Set, its value will be overwritten to be a “string” data type.
Declaration
Swift
public func set<Value: RESPValueConvertible>( _ key: RedisKey, to value: Value, onCondition condition: RedisSetCommandCondition, expiration: RedisSetCommandExpiration? = nil ) -> EventLoopFuture<RedisSetCommandResult>
Parameters
key
The key to use to uniquely identify this value.
value
The value to set the key to.
condition
The condition under which the key should be set.
expiration
The expiration to use when setting the key. No expiration is set if
nil
.Return Value
A
NIO.EventLoopFuture
indicating the result of the operation;.ok
if the operation was successful and.conditionNotMet
if the specifiedcondition
was not met.If the condition
.none
was used, then the result value will always be.ok
. -
setnx(_:to:)
Extension methodSets the key to the provided value if the key does not exist.
https://redis.io/commands/setnx
Important
Regardless of the type of data stored at the key, it will be overwritten to a “string” data type.ie. If the key is a reference to a Sorted Set, its value will be overwritten to be a “string” data type.
Declaration
Swift
@inlinable public func setnx<Value>(_ key: RedisKey, to value: Value) -> EventLoopFuture<Bool> where Value : RESPValueConvertible
Parameters
key
The key to use to uniquely identify this value.
value
The value to set the key to.
Return Value
true
if the operation successfully completed. -
setex(_:to:expirationInSeconds:)
Extension methodSets a key to the provided value and an expiration timeout in seconds.
See https://redis.io/commands/setex
Important
Regardless of the type of data stored at the key, it will be overwritten to a “string” data type.ie. If the key is a reference to a Sorted Set, its value will be overwritten to be a “string” data type.
Important
The actual expiration used will be the specified value or1
, whichever is larger.Declaration
Swift
@inlinable public func setex<Value: RESPValueConvertible>( _ key: RedisKey, to value: Value, expirationInSeconds expiration: Int ) -> EventLoopFuture<Void>
Parameters
key
The key to use to uniquely identify this value.
value
The value to set the key to.
expiration
The number of seconds after which to expire the key.
Return Value
A
NIO.EventLoopFuture
that resolves if the operation was successful. -
psetex(_:to:expirationInMilliseconds:)
Extension methodSets a key to the provided value and an expiration timeout in milliseconds.
See https://redis.io/commands/psetex
Important
Regardless of the type of data stored at the key, it will be overwritten to a “string” data type.ie. If the key is a reference to a Sorted Set, its value will be overwritten to be a “string” data type.
Important
The actual expiration used will be the specified value or1
, whichever is larger.Declaration
Swift
@inlinable public func psetex<Value: RESPValueConvertible>( _ key: RedisKey, to value: Value, expirationInMilliseconds expiration: Int ) -> EventLoopFuture<Void>
Parameters
key
The key to use to uniquely identify this value.
value
The value to set the key to.
expiration
The number of milliseconds after which to expire the key.
Return Value
A
NIO.EventLoopFuture
that resolves if the operation was successful. -
mset(_:)
Extension methodSets each key to their respective new value, overwriting existing values.
Note
Usemsetnx(_:)
if you don’t want to overwrite values.Declaration
Swift
@inlinable public func mset<Value>(_ operations: [RedisKey : Value]) -> EventLoopFuture<Void> where Value : RESPValueConvertible
Parameters
operations
The key-value list of SET operations to execute.
Return Value
An
EventLoopFuture
that resolves if the operation was successful. -
msetnx(_:)
Extension methodSets each key to their respective new value, only if all keys do not currently exist.
Note
Usemset(_:)
if you don’t care about overwriting values.Declaration
Swift
@inlinable public func msetnx<Value