Swiftpack.co - Package - Mordil/swift-redi-stack

RediStack logo

SSWG Maturity Apache 2 License Swift 5.0+ Redis 5.0

Build Status Documentation Coverage

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

Introduction

RediStack (pronounced like "ready stack") is a non-blocking Swift client for Redis built on top of SwiftNIO.

It communicates over the network using Redis' Redis Seralization Protocol (RESP2).

This library is primarily developed for Redis v5, but is backwards compatible to Redis v3¹.

The table below lists the major releases alongside their compatible language, dependency, and Redis versions.

| RediStack Release | Swift | Redis | SwiftNIO | SwiftLog | SwiftMetrics | |:-----------------:|:-----------------------------------:|:-------------------------:|:----------------------------------------------:|:----------------------------------------------:|:------------------------------:| | from: "1.0.0-alpha.7" | 5.0+ | 3.x¹ < 6.x | 2.x | 1.x | 1.x |

¹ Use of newer Redis features on older Redis versions is done at your own risk. See Redis' release notes for v5, v4, and v3 for what is supported for each version of Redis.

Supported Operating Systems

RediStack runs anywhere that is officially supported by the Swift project.

See the test matrix below for more details.

Installing

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

dependencies: [
    .package(url: "https://gitlab.com/mordil/swift-redi-stack.git", from: "1.0.0-alpha.5")
]

Getting Started

RediStack is quick to use - all you need is an EventLoop from SwiftNIO.

import NIO
import RediStack

let eventLoop: EventLoop = ...
let connection = RedisConnection.connect(
    to: try .init(ipAddress: "127.0.0.1", port: RedisConnection.defaultPort),
    on: eventLoop
).wait()

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

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

Note: Use of wait() was used here for simplicity. Never call this method on an eventLoop!

Documentation

The docs for the latest tagged release are always available at docs.redistack.info.

Questions

For bugs or feature requests, file a new issue.

For all other support requests, please email support@redistack.info.

Changelog

SemVer changes are documented for each release on the releases page.

Contributing

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

Contributors

Check out CONTRIBUTORS.txt to see the full list. This list is updated for each release.

Swift on Server Ecosystem

RediStack is part of the Swift on Server Working Group ecosystem - currently recommended as Sandbox Maturity.

| Proposal | Pitch | Discussion | Review | Vote | |:---:|:---:|:---:|:---:|:---:| | SSWG-0004 | 2019-01-07 | 2019-04-01 | 2019-06-09 | 2019-06-27 |

Language and Platform Test Matrix

The following table shows the combination of Swift language versions and operating systems that receive regular unit testing (either in development, or with CI).

| Platform | Swift 5 | 5.1 | 5.2 | Trunk | |:---------|:-------:|:---:|:---:|:-----:| | macOS Latest | | :white_check_mark: | | | | Ubuntu 18.04 (Bionic) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | Ubuntu 16.04 (Xenial) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |

License

Apache 2.0

Copyright (c) 2019-present, Nathan Harris (@mordil)

This project contains code written by others not affliated with this project. All copyright claims are reserved by them. For a full list, with their claimed rights, see NOTICE.txt

Redis is a registered trademark of Redis Labs. Any use of their trademark is under the established trademark guidelines and does not imply any affiliation with or endorsement by them, and all rights are reserved by them.

Swift is a registered trademark of Apple, Inc. Any use of their trademark does not imply any affiliation with or endorsement by them, and all rights are reserved by them.

Github

link
Stars: 23

Used By

Total: 0

Releases

RediStack 1.0.0 Alpha 7.1 - 2019-12-17 05:26:19

API Docs are always available at docs.redistack.info

Patch

  • Fixed deprecation warnings of SwiftNIO's Atomic usage (8d85cb2b)

RediStack 1.0.0 Alpha 7 - 2019-12-14 00:05:20

API Docs are always available at docs.redistack.info

All changes made in this tag were from Merge Request !92.

Logging is now more dynamic - as RedisClient loggers can be changed, rather than being static at initialization.

This is particularly useful for attaching metadata from a logger you already have, so you can correlate the logs generated by RediStack.

For example:

let connection = RedisConnection.connect(...)
let response = connection
    .logging(to: myRequestLogger) // this logger has a `requestID` metadata element
    .ping() // logs from RedisConnection while fulfilling this command will also include the `requestID` metadata
    .wait()

Major

  • RedisClient has 2 new requirements:
    • logger: Logging.Logger readonly property
    • setLogging(to: Logging.Logger) method
  • RedisCommandHandler no longer supports logging
    • The init method has been changed to no longer accept a Logger
  • RedisMessageEncoder no longer supports logging
    • The init method has been changed to just an empty init
  • The exact timing of when certain logs and metrics has been tweaked slightly in the RedisConnection.init method

Minor

  • RedisClient has a default extension method logging(to:) that is chainable and calls setLogging(to:)
  • RedisConnection now has a public id: UUID property
  • RedisConnection has more trace logs
  • Some RedisConnection debug logs re-adjusted to trace
  • Some RedisConnection logs had their level increased to account for being the sole source of logs now

Patch

  • The RedisConnection metadata id value is now correctly stable.
  • Corrected some code documentation, specifically around logging.

RediStack 1.0.0 Alpha 6.1 - 2019-10-27 07:10:16

API Docs are always available at docs.redistack.info

Minor

  • Several methods now have variadic overloads !87
  • get now has a generic overload for any RESPValueConvertible type !86
    • The String specialized implementation is still available

Patch

  • Unnecessary assertions in RedisCommandHandler have been removed !85

RediStack 1.0.0 Alpha 6 - 2019-09-24 03:38:37

API Docs are always available at docs.redistack.info

Major

  • RedisIntegrationTestCase now has properties that can be overridden in subclasses for specializing how to connect to Redis !74
  • RESPTranslator.ParsingError has two new cases: invalidBulkStringSize and bulkStringSizeMismatch !82
  • RedisMetrics.activeConnectionCount is no longer an Int and instead is a new specialized wrapper class called ActiveConnectionGauge !84
    • This is to address the data race found by the thread sanitizer that now runs on test passes
    • It maintains an internal Atomic<Int> count that can be modified with the public increment(by:)/decrement(by:) methods

Minor

  • RESPValue now conforms to Equatable !76
  • RedisError now conforms to Equatable !77
  • RESPValue.init(bulk:) now accepts a wider range of values !81
    • The String overload is now String?
    • The Int overload is now generic with a constraint of FixedWidthInteger

Patch

  • Fixed a data race with RedisMetrics.activeConnectionCount that was caught with the new thread sanitizer test passes !84
    • The job that caught the error: https://gitlab.com/Mordil/swift-redi-stack/-/jobs/302079265

RediStack 1.0.0 Alpha 5.0.2 - 2019-07-13 03:42:40

API Docs are always available at docs.redistack.info

Patch

  • RedisConnection.sendCommandsImmediately is now correctly public (fae8eada)

RediStack 1.0.0 Alpha 5.0.1 - 2019-07-11 21:44:58

API Docs are always available at docs.redistack.info

Patch

  • RediStackTestUtils is now correctly an importable module (aeae1f6c)

RediStack 1.0.0 Alpha 5 - 2019-07-11 21:44:10

API Docs are always available at docs.redistack.info

Major

  • The library module was renamed from RedisNIO to RediStack !73
  • RedisNIOError was renamed to RedisClientError !72
    • .responseConversion(to:) was renamed to .failedRESPConversion(to:)
    • .unsupportedOperation(method:message:) was removed
  • RedisCommandHandler is no longer open (now public final) !55
  • RedisCommandContext was renamed to RedisCommand !66
  • RedisCommand.command was renamed to message and the initializer signature updated to match its properties (2605763)
  • RedisCommandHandler.init(logger:) is now .init(initialQueueCapacity:logger:) !66
  • The names for the ChannelPipeline handlers are now explicitly named !66
    • RediStack.OutgoingHandler
    • RediStack.IncomingHandler
    • RediStack.CommandHandler
  • The Redis namespace enum was removed !71
    • The makeConnection factory method was moved to RedisConnection.connect
      • This method now requires a NIO.EventLoop instance, no longer creating a MultiThreadedEventLoopGroup for you
      • This method also now supports overriding the default NIO.ClientBootstrap and is the preferred way of building your own pipelines
  • RedisConnection.init is now internal, all connections are made with RedisConnection.connect !71
  • A few different logs have had their severity adjusted
    • Sending a command while the connection is closed is now a warning !71
  • Sorted Set methods zadd, zunionstore, and zinterstore, have stronger type safety with options defined as enums !70 and (0ecb3c1)
  • RESPValueConvertible is no longer used as an existential !69
    • This also changes RedisConnection.send(command:with:) to require the RESPValue arguments up front, rather than doing the conversion for you
  • RESPValue and RESPValueConvertible had many internal implementations changed !67
    • RESPValue.array no longer uses ContiguousArray
    • ContiguousArray is no longer RESPValueConvertible
    • several of the computed properties on RESPValue will no longer behave exactly the same, or have moved to the new RediStackTestUtils module
  • Redis.makeDefaultClientBootstrap(using:) was renamed and moved to ClientBootstrap.makeRedisTCPClient(group:) !64
    • The implementation for adding the "default" RESP handlers is now publicly available with Channel.addBaseRedisHandlers()
  • RESPTranslator saw a major refactor !63
    • It is now a struct instead of an enum
    • ByteBuffer.writeRESPValue(_:) is a new method carrying most of the implementation for writing out RESPValue
    • RESPTranslator.ParsingResult was removed
    • RESPTranslator now updates the passed in ByteBuffer.readerIndex on successful parses
    • RESPTranslator.parseBytes(from:) uses the passed in ByteBuffer entirely for position and recursion
  • RESPValueConvertible.init(_:) was renamed to .init(fromRESP:) !56

Minor

  • A new module RediStackTestUtils is available for some helpers with writing tests for RediStack !67

Patch

  • The observable behavior of closing a channel should be more straight forward and dependable !71

RedisNIO 1.0.0 Alpha 3 - 2019-07-11 21:35:42

Major

  • NIO is no longer exported, you will need to explicitly import NIO !57
  • errorCaught in RedisCommandHandler now fails all pending responses, and does not increment RedisMetrics.commandFailureCount !59
  • EventLoopFuture.mapFromRESP has been renamed to `EventLoopFuture.convertFromRESPValue !60

Minor

  • The APPEND command is now available with the append(_:to:) method !61

RedisNIO 1.0.0 Alpha 2.1 - 2019-07-11 21:34:35

Minor

  • Added new RedisConnection.defaultPort static property set to 6379 for users to reference !51

RedisNIO 1.0.0 Alpha 2 - 2019-07-11 21:33:54

Major

  • Added explicit conformance to RESPValueConvertible for Foundation.Data to resolve a bug where it received conformance from Collection (!50)

RedisNIO 1.0.0 Alpha 1.1.1 - 2019-07-11 21:33:07

Patch

  • Fix warning from default in switch (788f69de)

RedisNIO 1.0.0 Alpha 1.1 - 2019-07-11 21:28:21

Minor

  • Improve debugging of RESPValue (d4584924)

RedisNIO 1.0.0 Alpha 1 - 2019-07-11 21:27:26

API Docs:

https://mordil.gitlab.io/swift-redis-nio-client

RedisNIO 0.10.0 - 2019-07-11 21:22:45

This release introduces a "minor" breaking change that is large enough that it warrants releasing it as a major revision.

SE-0226 Package Manager Target Dependency Resolution introduces a change to expected form of packages and their naming.

To be compliant with future changes to SPM - it was decided to rename the package from redis-nio (matching the module name) to swift-redis-nio-client to match the repo instead.

Major

  • Renamed package from redis-nio to swift-redis-nio-client !47

RedisNIO 0.9.0: Renaming - 2019-06-06 17:06:44

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:

Major

  • 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

Minor

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

NIORedis 0.8.0: Blocking & Pub/Sub - 2019-06-06 16:46:31

Major

  • 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)

Minor

  • 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)

Patch

  • 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)

NIORedis 0.7.0: The Proposal - 2019-05-02 02:29:09

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)

Additions

  • 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)

NIORedis 0.6.0: Simple Connections - 2019-03-28 06:16:58

Motivation

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

Fixes

  • 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)

NIORedis 0.5.0: Everything is Convenient - 2019-03-25 23:04:13

Motivation

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

NIORedis 0.4.0: POP and SSWG - 2019-03-19 05:08:18

Breaking Changes

  • Removed DispatchRedis package (https://github.com/Mordil/nio-redis/commit/5c32b97a0c5cd3e560dd2a7d465b51686915b62a)
  • RedisConnection and RedisPipeline have become protocols. The default implementations have been renamed to NIORedisConnection and NIORedisPipeline (https://github.com/Mordil/nio-redis/commit/6b30127f6b7a3f75cdbeca8f426fe9260bdbe370)
  • The select(_:) command convenience method has been renamed to select(database:) (https://github.com/Mordil/nio-redis/commit/6b30127f6b7a3f75cdbeca8f426fe9260bdbe370)
  • RedisPipeline.enqueue(command:arguments:) has been renamed to RedisPipeline.enqueue(operation:) which is now a closure that provides a RedisCommandExecutor so all of the command convenience methods are made available. (https://github.com/Mordil/nio-redis/commit/6b30127f6b7a3f75cdbeca8f426fe9260bdbe370)
    • Commands are still queued and not executed immediately.
  • RedisConnection.command(_:arguments:) is no longer supported (https://github.com/Mordil/nio-redis/commit/6b30127f6b7a3f75cdbeca8f426fe9260bdbe370)

New Additions

  • swift-log is now added, and default logging implementations have been added (https://github.com/Mordil/nio-redis/commit/73d5930f3413f944c9c209d4e0b276a915f7f34b)
    • Most logging is done with debug
    • Each logging instance can be overridden in constructors of objects that log
    • Each logger uses a NIORedis. prefix in their label
  • RedisCommandExecutor protocol that creates an interface for objects responsible for sending commands (https://github.com/Mordil/nio-redis/commit/6b30127f6b7a3f75cdbeca8f426fe9260bdbe370)
    • NIORedisConnection and NIORedisPipeline both conform to this protocol
  • RESPConvertible conformance to Optional (https://github.com/Mordil/nio-redis/commit/618481fe1eae8208e5d160eba2ecce6978dd606f)
  • New command convenience methods (https://github.com/Mordil/nio-redis/commit/9f505be4d2a16c441d9a2b1d7266a04b4106bfaf)

Fixes

  • NIORedisConnection.close() to send a "QUIT" command to Redis before closing, and properly checking if the connection has been closed already (https://github.com/Mordil/nio-redis/commit/68254519636bbcd3b882e4b4f63d8cbf2b3e3fb1)

NIORedis 0.3.0: Housekeeping - 2019-03-14 23:16:10

NIORedis 0.2.0: The Return Pitch - 2019-01-10 20:08:04

NIORedis 0.1.0: The First Pitch - 2019-01-08 03:56:51