A minimal Redis clone written in Go — supports a subset of the Redis protocol (RESP).
Warning
Don't use this on productions!, WTF is wrong with you
+--------+ +-------------+ +------------------+
| client | -------> | TCP Request | -----------> | Resp Deserialize |
+--------+ +-------------+ +------------------+
^ |
| |
|
+----------+ +----------------+ +-----------------+
| Response | <------- | Resp serialize | <------- | Command Handler |
+----------+ +----------------+ +-----------------+
- RESP protocol parsing
- Basic commands:
-
PING– Ping the server and will reply with PONG -
SET key value– Store a value by key -
GET key– Retrieve a value by key -
DEL key– Delete a key -
EXPIRE- Set timeout on a key -
TTL- Return remaining time to live of a key that has a timeout. -
KEYS- Return all keys matching pattern -
HSET key field value– Set hash field -
HGET key field– Get hash field -
HDEL key field– Delete specified field from the hash -
HGETALL key field– Delete specified field from the hash - expiration cleanup
- disk storage for persistent across restart
git clone https://github.com/agungfir98/mini-redis.git
cd mini-redis
go build -o mini-redisredis-cli -p 6380
# or redli
redli -p 6380127.0.0.1:6379> SET foo bar
OK
127.0.0.1:6379> GET foo
"bar"
127.0.0.1:6379> DEL foo
(integer) 1
127.0.0.1:6379> GET foo
(nil)- written in pure Go
- parses raw Resp manually
- handle each connection with go routines
- uses map[string]string internally for storage
- Uses min heap data structure to hold data with timeout