Code Monkey home page Code Monkey logo

red1s's Introduction

Red1s

An extremely simplified key/value store that sorta kinda implements some of the Redis RESP spec that I hacked together in a few hours for a job interview. Currently supports the following commands:

  • GET
  • DEL
  • SET

Note:

  • Keys and values are limited to 4096 bytes.
  • Only supports basic strings in the form $3\r\nset\r\n$3\r\nkey\r\n$5\r\nvalue\r\n.

Tasks

  • Implement TCP listener to handle incoming client requests.
  • Create parser / decoder to process incoming commands.
  • Create thread-safe key-value store to hold data.
  • Return Redis Wire protocol encoded responses.

Nice to haves

  • List command.
  • Data store abstraction.
  • Automatic key expiration.
  • Persistence - save data to disk, read in contents during startup.
  • Partitioning - would require a load balancer / router.

Developer Notes

  • Redis can store up to 512 MB per key. Obviously allocating this much data per request would be terribly inefficient, especially for requests that are only a few bytes in size. Reading incoming request data can be done using chunking where we read in say 1024 KB at a time, writing the data to a byte buffer.

    • Note: I ended up opting for a basic solution for now due to issues reading CRLF requests correctly. Would like to re-address this down the road.
  • Manually parsing the command bytes, but will probably refactor to use simple regex checks.

Resources


Notes for the reviewer

There's a tremendous amount of stuff I would like to, and would have liked to do for this project, such as:

  • Passing a context to cancel requests.
  • Redo how I did the parsing entirely (Regex would have been simpler / cleaner).
  • Adding a graceful shutdown by monitoring sigint and having the network later update a channel whenever a request as in-flight.
  • TCP code is not great. I got hung up trying to get bufio/bytes package, etc. working with conn.Read. I suspect the issue with the CRLF, but I decided to move after spending a bit too long on it. However, this left me having to use a pre-allocated byte slice of 4096 which is of course, much less than ideal :(
  • Package layout isn't great. Naming is hard. This would definitely be part of a refactor.
  • The storage system uses a standadrd RWMutex vs a sync.Map since sync.Map is more optimized for high reads and fewer rights.
  • I have not written as many tests and or bench marked everything as well as I'd have liked. I also haven't ran the race detector.

Author

Jason Welch ([email protected])

red1s's People

Contributors

xealgo avatar

Watchers

 avatar FlippantTurnip avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.