Thanks to visit codestin.com
Credit goes to github.com

Skip to content

agungfir98/mini-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mini-redis

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


Architecture diagram

+--------+          +-------------+              +------------------+
| client | -------> | TCP Request | -----------> | Resp Deserialize |
+--------+          +-------------+              +------------------+
    ^                                                      |
    |                                                      |
    |                                                      
+----------+          +----------------+          +-----------------+
| Response | <------- | Resp serialize | <------- | Command Handler |
+----------+          +----------------+          +-----------------+

Features

  • 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

Getting Started

1. Clone and Build

git clone https://github.com/agungfir98/mini-redis.git
cd mini-redis
go build -o mini-redis

Connecting with mini-redis

using redis-cli or redli

redis-cli -p 6380
# or redli
redli -p 6380

example usage

127.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)

Implementation Notes

  • 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

About

super minimal (way to minimal) redis clone

Topics

Resources

License

Stars

Watchers

Forks