RedisClient

public final class RedisClient : DatabaseConnection, BasicWorker

A Redis client.

  • Request for authentication in a password-protected Redis server

    Declaration

    Swift

    public func authorize(with password: String) -> Future<Void>
  • Removes the specified keys. A key is ignored if it does not exist.

    Declaration

    Swift

    public func delete(_ key: String) -> Future<Void>
  • Removes the specified keys. A key is ignored if it does not exist.

    Declaration

    Swift

    public func delete(_ keys: String...) -> Future<Int>
  • Removes the specified keys. A key is ignored if it does not exist.

    Declaration

    Swift

    public func delete(_ keys: [String]) -> Future<Int>
  • Set a timeout on key. After the timeout has expired, the key will automatically be deleted. A key with an associated timeout is often said to be volatile in Redis terminology.

    let res = try redis.expire("foo", after: 42).wait()
    

    https://redis.io/commands/expire

    Declaration

    Swift

    public func expire(_ key: String, after deadline: Int) -> Future<Int>
  • Gets key as a decodable type.

    Declaration

    Swift

    public func jsonGet<D>(_ key: String, as type: D.Type) -> Future<D?> where D : Decodable
  • Sets key to an encodable item.

    Declaration

    Swift

    public func jsonSet<E>(_ key: String, to entity: E) -> Future<Void> where E : Encodable
  • Sets the given keys to their respective values.

    Declaration

    Swift

    public func mset(with values: [String : RedisData]) -> Future<Void>
  • Returns the values of all specified keys.

    Declaration

    Swift

    public func mget(_ keys: [String]) -> Future<[RedisData]>
  • Increments the number stored at key by one or a specified amount.

    Declaration

    Swift

    public func increment(_ key: String, by amount: Int? = nil) -> Future<Int>
  • Decrements the number stored at key by one or a specified amount.

    Declaration

    Swift

    public func decrement(_ key: String, by amount: Int? = nil) -> Future<Int>
  • Returns the specified elements of the list stored at key.

    Declaration

    Swift

    public func lrange(list: String, range: ClosedRange<Int>) -> Future<RedisData>
  • Insert all the specified values at the tail of the list stored at key.

    Declaration

    Swift

    public func rpush(_ values: [RedisData], into list: String) -> Future<Int>
  • Insert all the specified values at the head of the list stored at key.

    Declaration

    Swift

    public func lpush(_ values: [RedisData], into list: String) -> Future<Int>
  • Returns the element at index in the list stored at key.

    Declaration

    Swift

    public func lIndex(list: String, index: Int) -> Future<RedisData>
  • Returns the length of the list stored at key.

    Declaration

    Swift

    public func length(of list: String) -> Future<Int>
  • Sets the list element at index to value.

    Declaration

    Swift

    public func lSet(_ item: RedisData, at index: Int, in list: String) -> Future<Void>
  • Removes and returns the last element of the list stored at key.

    Declaration

    Swift

    public func rPop(_ list: String) -> Future<RedisData>
  • Atomically returns and removes the last element (tail) of the list stored at source, and pushes the element at the first element (head) of the list stored at destination.

    Declaration

    Swift

    public func rpoplpush(source: String, destination: String) -> Future<RedisData>
  • Select the Redis logical database having the specified zero-based numeric index. New connections always use the database 0.

    let res = try redis.select(42).wait()
    

    https://redis.io/commands/select

    Declaration

    Swift

    public func select(_ database: Int) -> Future<String>
  • Subscribes to the channels and call the subscription handler on message from server Should be closed when subscription not needed. Makes the redis client subscription only.

    Declaration

    Swift

    public func subscribe(
        _ channels: Set<String>,
        subscriptionHandler: @escaping (RedisChannelData) -> Void
    ) throws -> Future<Void>
  • Connects to a Redis server using a TCP socket.

    Declaration

    Swift

    public static func connect(
        hostname: String = "localhost",
        port: Int = 6379,
        password: String? = nil,
        on worker: Worker,
        onError: @escaping (Error) -> Void
    ) -> Future<RedisClient>