A simple Redis clone made with Go.
Multitype data storage
Lazy expiration
Memory cap with LRU eviction
Multithreaded connection manager
String
List
Hashmap
Hashset
The server listens for tcp connections on port 8080. After connecting to the server following commands can be ran.
GET [key] // Get string value
SET [key] [value] [expire seconds] // Set string value
LPUSH [key] [value] // push to list, if doesn't exist create one
LREM [key] [value] // remove first matching value from list
LRANGE [key] [start] [end] // get elements from list in range
HGET [key] [hash] // get value of the hash
HSET [key] [hash] [value] // sets value of the hash, creates hashmap if doesn't exist
EXPIR [key] [expire seconds] // sets expiration time from current time
SPUSH [key] [value] // push to set, of doesn't exist create one
SREM [key] [value] // remove value from set
SHAS [key] [value] // check if set has value
Each command returns some response.
Usage examples with expected results.
SET user1 50 500
OK
GET user1
50
LPUSH responses 10
OK
LREM responses 10
OK
LRANGE responses 0 3
$ 10,5,15
HSET comments John Hi
OK
HGET comments John
Hi
EXPIR comments 50
OK
SPUSH users John
OK
SREM users John
OK
SHAS users John
0
go 1.25.0+
git
Open terminal
Clone repo
git clone https://github.com/CodeForBeauty/GoRedisGo into cloned directory
cd GoRedisRun server with go
go run ./cmd/main.goTo run unit tests run
go test -v ./testsNo persistens
White line characters aren't supported
This was a great learning experience. I've learned to design message parser, distribute tasks across threads and to manage memory usage.