swift-nio-redis/Sources/NIORedis
Helge Heß 8e12a8a910
Keep array context values around
... this may be a no-op optimization,
but well.

It is actually trigger to do the right thing here.
In this version we flush the `values` array, which
transfers ownership of the array buffer to the
RESPValue.
But that buffer is never going to be modified, so
it would be nice to keep it alive. But if we do
keep it alive, we also keep the RESPValues alive,
which may point to full ByteBuffer's, which is
not desirable.

Whatever you do in Swift, you loose ;-)
2018-04-13 15:04:02 +02:00
..
README.md Initial drop 2018-04-11 00:27:29 +02:00
RESPChannelHandler.swift Move RESPParser to own file/struct 2018-04-13 13:45:19 +02:00
RESPEncodable.swift Initial drop 2018-04-11 00:27:29 +02:00
RESPParser.swift Keep array context values around 2018-04-13 15:04:02 +02:00
RESPPipelineSetup.swift Initial drop 2018-04-11 00:27:29 +02:00
RESPValue.swift Initial drop 2018-04-11 00:27:29 +02:00

README.md

SwiftNIO Redis - Protocol Implementation

swift-nio-redis is a port of the Noze.io redis module.

The NIO implementation has been optimized for performance.

This Noze.io RedisParser stream:

let parser = RedisParser()

stream! | parser | Writable { values, done in
  handle(replies: values)
  done(nil)
}

This is essentially replaced by the RESPChannelHandler. Instead of piping via |, it can be injected into the Swift NIO channel pipleline like so:

_ = bootstrap.channelInitializer { channel in
  channel.pipeline
    .configureRedisPipeline()
    .then {
      channel.pipeline.add(YourRedisHandler())
    }
}

Your handler will then receive RESPValue enums as the "readable input", and it can emit RESPEncodable values are the "writable output".

A RESPValue is just an enum with the on-the-write datatypes supported by RESP:

  • simpleString (a ByteBuffer)
  • bulkString (a ByteBuffer or nil)
  • integer
  • array (a ContiguousArray of RESPValues)
  • error (an error)

The primary RESPEncodable is again a RESPValue, but Int's, String's, Data's etc can also be directly written w/o having to wrap them in a RESPValue.

Example

For a full example on how to use the protocol implementation, a Redis client module is provided as part of this package.

Telnet Mode

Besides the binary variant, the Redis protocol also supports a "Telnet mode". A basic implementation of that is included, the major piece lacking is quoted strings.