Swift Memcached Client[GSoC 2023]

GSoC Proposal - Swift Memcached Client using SwiftNIO - Feedback and Guidance Requested

Hey everyone,

My name is Adam, and I'm currently working on a proposal for the Google Summer of Code program. I would like to create a Swift native implementation of a Memcached Client using SwiftNIO for the networking stack. As this is my first time working alot of these concepts, I would greatly appreciate any feedback and guidance on my approach.I've mostly worked with Swift on the job working on more UI/UX stuff so, feel free to help lead me in the right direction here!

Project Description:

The goal of the project is to implement the meta command protocol of Memcached to send commands and receive responses. In order to achieve this, I need to implement request encoding and response decoding. The client should support request pipelining to improve its performance.
See the Swift GSoC ideas as well & scroll down to Swift on Server -> Swift.org - Project Ideas for GSoC 2023

Current Progress:

So far, I've started implementing the core components of the client. Here's a brief overview of my implementation:

  1. Created a MemcachedCommand enum to represent Memcached commands.
  2. Implemented the MemcachedRequestEncoder to encode the commands into a ByteBuffer.
  3. Implemented the MemcachedResponseDecoder to decode the responses from a ByteBuffer.
  4. Created the ResponseHandler class that conforms to ChannelInboundHandler and RemovableChannelHandler for handling the decoded responses.
  5. Implemented the MemcachedClient class that uses SwiftNIO's ClientBootstrap for connecting to the Memcached server and sending pipelined commands.

Here's a snippet of the MemcachedCommand enum:

public enum MemcachedCommand {
    case get(key: String)
    case set(key: String, value: String, flags: Int, expiration: Int)
    // Other commands...
}

This is the MemcachedRequestEncoder:

public final class MemcachedRequestEncoder: ChannelOutboundHandler {
    public typealias OutboundIn = MemcachedCommand
    public typealias OutboundOut = ByteBuffer

    // Encoding implementation...
}

The MemcachedResponseDecoder:

public final class MemcachedResponseDecoder: ByteToMessageDecoder {
    public typealias InboundOut = MemcachedResponse

    // Decoding implementation...
}

And the sendPipelinedCommands function in the MemcachedClient class:

public func sendPipelinedCommands(channel: Channel, commands: [MemcachedCommand]) -> EventLoopFuture<[MemcachedResponse]> {
    // Implementation...
}

Request for Feedback:

I would appreciate it if anyone could take the time to look at my solution and provide feedback or guidance on how to improve it. Again, I'm a super noob for alot of these concepts and working with Swift in this paradigm outside of the typical product work so, this is also my first time trying out Open Source contributions in the Swift community, I'm eager to learn and improve my skills. Any suggestions or critiques are welcome.

Thank you in advance for your time and assistance!

Github Repo -> GitHub - atj3097/swift-memcached
Also, mentioning @FranzBusch , as I see he's the mentor for this project!

4 Likes

Also just apologies in advance, I'm still learning how to navigate the Swift community, just joined. I see that there's already been a thread on this, will check out some of the work that's already been done and how I can contribute!

1 Like