Swiftpack.co - Package - Mordil/swift-redis-nio-client

| The GitHub repository is a read-only mirror of the GitLab repository. For issues and merge requests, please visit GitLab. | |---|

License Build Swift Redis

Swift Redis NIO Client

A non-blocking Swift client for Redis built on top of SwiftNIO.

This package defines everything you need to work with Redis through the Redis Seralization Protocol (RESP).

RedisNIO is part of the Swift on Server Working Group ecosystem.

| Proposal | Pitch | Discussion | Review | Vote | |----------|-------|------------|--------|------| | SSWG-0004 | 2019-01-07 | 2019-04-01 | TBD | TBD |

:package: Installation

To install RedisNIO, just add the package as a dependency in your Package.swift

dependencies: [
    .package(url: "https://github.com/Mordil/swift-redis-nio-client.git", from: "1.0.0-alpha.1")

and run the following command: swift package resolve

:zap: Getting Started

RedisNIO is ready to use right after installation.

import RedisNIO

let connection = Redis.makeConnection(
    to: try .init(ipAddress: "", port: RedisConnection.defaultPort),
    password: "my_pass"

let result = try connection.set("my_key", to: "some value")
    .flatMap { return connection.get("my_key" }

print(result) // Optional("some value")

:closed_book: Documentation

API Documentation is generated every time a new release is published.

The latest version's docs are always available at https://mordil.gitlab.io/swift-redis-nio-client

:construction: Contributing

Check out CONTRIBUTING.md for more information on how to help with RedisNIO.

It is highly recommended to use Docker to install Redis locally.

docker run -d -p 6379:6379 --name redis redis:5

Otherwise, install Redis directly on your machine from Redis.io.


Stars: 11
Help us keep the lights on

Used By



0.9.0 - Jun 6, 2019

This release brings a major breaking change. GitHub will forward most requests from the previous repository URL to the new one - but in code it has more specific ramifications.

This is necessary to align with the goals of the SSWG and to solve problems that will exist in the future before it causes real issues.

For further context into the discussion, see the following threads on the Swift Forums:


  • Renamed the repo in GitHub from nio-redis to swift-redis-nio-client
  • Renamed the package from nio-redis to redis-nio
  • Renamed the NIORedis module to RedisNIO
  • Renamed NIORedisError to RedisNIOError
  • Changed references to NIORedis to RedisNIO in object labels such as NIO Channel Handlers & Loggers


  • Changed all references in copyright blocks, project files (README, LICENSE, etc.) to refer to the project as RedisNIO

0.8.0 - Jun 6, 2019


  • Added SwiftMetrics dependency (https://github.com/Mordil/swift-redis-nio-client/pull/41)
  • Changed ChannelPipeline registration of handlers for RedisConnection to now have a reliable name (https://github.com/Mordil/nio-redis/commit/d0da3e760bb864dedffc60e0f4634c1f2d03a1d8)


  • Added bzpopmin and bzpopmax convenience methods for sorted sets (https://github.com/Mordil/nio-redis/pull/42)
  • Added brpop, blpop, and brpoplpush convenience methods for lists (https://github.com/Mordil/nio-redis/pull/43)


  • Update legal notices for SwiftLog & SwiftMetrics (https://github.com/Mordil/swift-redis-nio-client/commit/b0d0882ee2b7892a16b5283f87dfae790718b2a2)
  • Fixed minor comment issues (https://github.com/Mordil/nio-redis/commit/d9d61bafe432f9b01e65733965e02f93bfce28a9)

0.7.0 - May 2, 2019

Breaking Changes

  • Static factory methods for building a default Redis Channel pipeline and RedisConnection have been moved to a new Redis enum namespace (https://github.com/Mordil/nio-redis/pull/38)
    • Their method signatures have also seen some changes
  • Encoding / Decoding RESP has been separated from the Channel pipelines (https://github.com/Mordil/nio-redis/pull/39)
    • RESPTranslator is a new type that implements the encoding/decoding of RESP formatted bytes to Swift types
    • RESPDecoder has been renamed to RedisByteDecoder and is just a ByteToMessageDecoder
    • RESPEncoder has been renamed to RedisMessageEncoder and is just a MessageToByteEncoder
  • Error handling is now more straight forward (https://github.com/Mordil/nio-redis/pull/37)
    • RedisError is to represent only errors returned by Redis itself in command responses
    • NIORedisError represents errors thrown within the library
    • RESPTranslator.ParsingError represents errors thrown while parsing bytes
  • RedisPipeline has been removed (https://github.com/Mordil/nio-redis/pull/36)
    • This feature may be re-introduced in the future, but for now is left up to higher level packages to implement
  • RESPValue now holds references to ByteBuffers rather than Data (https://github.com/Mordil/nio-redis/pull/34)
  • Foundation.Data is no longer RESPValueConvertible (https://github.com/Mordil/nio-redis/pull/30)


  • RedisConnection now has a property sendCommandsImmediately that controls the timing of when commands written to the network socket should be flushed and sent to Redis. (https://github.com/Mordil/nio-redis/pull/36)
    • The default is true, which means every command will trigger a flush.
  • RESPValue now has the following computed properties converted from the underlying storage (https://github.com/Mordil/nio-redis/pull/30/, https://github.com/Mordil/nio-redis/pull/34):
    • bytes: [UInt8]?
    • data: Data?
    • string: String? (this isn't new, but now also works with .integer storage instances)

Implementation Changes

  • SwiftLog has been anchored to version 1.0.0
  • RESPTranslator now uses ByteBufferViews and ByteBufferSlices internally, so there should be a performance increase (https://github.com/Mordil/nio-redis/pull/34)

0.6.0 - Mar 28, 2019


Much of the exposed types in the library were wordy, unclear, or not fulfilling strong use cases - so a revisit was done to the foundational protocols: RedisCommandExecutor, RedisConnection, RedisPipeline - as well as their implementations and RedisDriver.

Breaking Changes

  • RedisCommandExecutor is now RedisClient (https://github.com/Mordil/nio-redis/pull/24)
  • RedisConnection is no longer a protocol (https://github.com/Mordil/nio-redis/pull/24)
    • NIORedisConnection has taken the name to act as the primary concrete implementation for Redis connections
      • the isClosed property has been renamed to isConnected
  • RedisPipeline is no longer a protocol (https://github.com/Mordil/nio-redis/pull/26)
    • NIORedisPipeline has taken the name to act as the primary concrete implementation for Redis pipelines
  • RedisDriver is no longer a thing (https://github.com/Mordil/nio-redis/pull/25)
    • Connections are now made with a static method on RedisConnection


  • RedisConnection.close() has had some tweaks to resolve a state where closing a connection results in error and the QUIT command could not be sent (https://github.com/Mordil/nio-redis/pull/24)

0.5.0 - Mar 25, 2019


The goal of this release was to bring feature parity with Vapor's Redis implementation and to have as Swifty of an API as possible, with consistent documentation and minimal performance impact.

Breaking Changes

  • Every command extension has the @inlinable attribute to remove method call overhead as much as possible
  • Every existing command extension up to this point has been re-evaluated with the function names, parameter labels, and return types.

New Additions

  • EventLoopFutures resolving RESPValue now have an extension method that can convert to a type you desire or fail with a RedisError: .mapFromRESP(to:) (https://github.com/Mordil/nio-redis/commit/5a35a918aeebb85fb7c069bb2e330fefcb52ca93)
  • New convenience command methods
    • strings (https://github.com/Mordil/nio-redis/pull/18)
      • mget, mset, msetnx, incr, incrby, incrbyfloat, decr, decrby
    • hashes (https://github.com/Mordil/nio-redis/pull/19)
    • lists (https://github.com/Mordil/nio-redis/pull/20)
      • except blocking
    • sorted sets (https://github.com/Mordil/nio-redis/pull/21)
      • except blocking