Why did I build this?
- I was really curious about how Go handles concurrency, and how a scalable application/server is ideally written in Go.
- I researched a little and came across Redis as a prime example to learn about GoRoutines, Channels and the concept of concurrency.
👉 What's better than building a project to learn more about a language?
So here I am, writing as I build a Go Redis (key-value) database.
Learnings
I will update this as I make progress in my project
Day 1
- Built the server and RESP protocol parser
- Concurrent client request reading (achieved using GoRoutines and Channels)
- Accepting peer connection and handling disconnection
- Reading client input while avoiding buffer leaks
- Understood the RESP protocol and implemented the parser
- Understood the need of single threaded command execution in Redis (achieved using Channels)
Day 2
- Added support for
PING, SET, GET, HSET, HGET, HGETALL
- Use of sync.RWMutex locks for:
- Only 1 writer at a time
- Multiple readers at a time
- Readers can't read during writes
- Writers can't write during reads
- Made it Redis-client compliant
- Building response to Redis-clients using RESP
- Handling exceptions properly and reverting to client
- Use of maps (hashmaps) in Go
- Use of sync.RWMutex locks for: