Swiftpack.co -  SwiftNIOExtras/swift-nio-redis as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
SwiftNIOExtras/swift-nio-redis
A high performance Redis protocol (RESP) implementation for SwiftNIO
.package(url: "https://github.com/SwiftNIOExtras/swift-nio-redis.git", from: "0.10.3")

SwiftNIO Redis

Swift5 macOS tuxOS Travis

SwiftNIO Redis is a Swift package that contains a high performance Redis protocol implementation for SwiftNIO. This is a standalone project and has no other dependencies but SwiftNIO.

Apart from the protocol implementation which can encode and decode RESP (REdis Serialization Protocol), we also provide a Redis client module build on top.

What is Redis? Redis is a highly scalable in-memory data structure store, used as a database, cache and message broker. For example it can be used to implement a session store backing a web backend using its "expiring keys" feature, or it can be used as a relay to implement a chat server using its builtin PubSub features.

This Swift package includes the RESP protocol implementation. A simple Redis client can be found on swift-nio-redis-client. We also provide an actual Redis Server written in Swift, using SwiftNIO and SwiftNIO Redis.

Performance

This implementation is focused on performance. It tries to reuse NIO ByteBuffers as much as possible to avoid copies.

The parser is based on a state machine, not on a buffering ByteToMessageDecoder/Encoder. That doesn't make it nice, but efficient ;-)

Importing the module using Swift Package Manager

An example Package.swift importing the necessary modules:

// swift-tools-version:5.0

import PackageDescription

let package = Package(
    name: "RedisTests",
    dependencies: [
        .package(url: "https://github.com/SwiftNIOExtras/swift-nio-redis.git", 
                 from: "0.9.2")
    ],
    targets: [
        .target(name: "MyProtocolTool",
                dependencies: [ "NIORedis" ])
    ]
)

Using the SwiftNIO Redis protocol handler

The RESP protocol is implemented as a regular ChannelHandler, similar to NIOHTTP1. It takes incoming ByteBuffer data, parses that, and emits RESPValue items. Same the other way around, the user writes RESPValue (or RESPEncodable) objects, and the handler renders such into ByteBuffers.

The NIORedis module has a litte more information.

To add the RESP handler to a NIO Channel pipeline, the configureRedisPipeline method is called, e.g.:

import NIORedis

bootstrap.channelInitializer { channel in
    channel.pipeline
        .configureRedisPipeline()
        .then { ... }
}

Status

The protocol implementation is considered complete. There are a few open ends in the telnet variant, yet the regular binary protocol is considered done.

Who

Brought to you by ZeeZide. We like feedback, GitHub stars, cool contract work, presumably any form of praise you can think of.

GitHub

link
Stars: 26
Last commit: 28 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Dependencies

Release Notes

Extra Protocol
3 years ago

Decouple the protocol implementation from the client to make it useful to arbitrary higher level frameworks. The client now lives in an extra package over at Noze.io.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics