This project is a simplified Redis clone implemented in Go, created as part of the CodeCrafters "Build Your Own Redis" challenge. It supports a subset of Redis commands and provides basic functionality for key-value storage and retrieval along with several redis features as described below.
- Basic key/value storage using
GET
andSET
command with values with expiry time. - RDB local database support for persistant storage.
- Partial Replication support.
- Basic streams support with
TYPE
,XADD
,XREAD
andXRANGE
commands. - Basic Transaction support with
MULTI
,INCR
,EXEC
andDISCARD
commands.
This project requires Go to be installed on your system. If you don't have Go installed, you can download it from the official Go downloads page:
Choose the appropriate version for your operating system and follow the installation instructions provided on the Go website.
After ensuring Go is installed on your system, follow these steps to set up Simple Git:
-
Clone the repository:
git clone https://github.com/kakkarot9712/simple_redis_go
-
Navigate to the project directory:
cd simple-redis-go
-
Build the project:
go build -o myredis ./app
This will create an executable named myredis
in your project directory.
- After building the project, you can use the
myredis
executable to start server.
./myredis
- By default this server will bind to port
6379
, Though you can use any port using--port
flag while starting server
./myredis --port 6380
- You can load existing RDB file while staring the server using
--dir
flag to specify file location and--dbfilename
flag to specify RDB file name.
./myredis --dir /tmp/redis-files --dbfilename dump.rdb
Note: If you dont specify directory and file paths, server will try to fetch dump.rdb
file from /tmp/redis-files
directory.
- By default Server will assume a
master
role. To start server as replica server of some other master server you can pass--replicaof
flag along with host and port ofmaster
server.
./myredis --replicaof "localhost 6379"
The following Redis commands are implemented in this project:
PING
: Test the server connectionECHO
: Echo the given stringSET
: Set a key to hold a string valueGET
: Retrieve the value of a keyCONFIG
: Get or set server configuration parametersKEYS *
: Find all keysINFO
: Get information and statistics about the serverREPLCONF
: Configure replication settingsPSYNC
: Internal command used for replicationTYPE
: Get type of key, which can bestring
,stream
ornone
XADD
: Add key-value(s) to a streams storageXRANGE
: Get all streams within two id rangeXREAD
: Read multiple streams of specified ids. supports normal lookup andblocking
lookupINCR
: Increments integer value of specified key by 1.MULTI
: Starts Transaction. By this command allGET
,SET
andINCR
command will be queued without executionEXEC
: Executes all queued commands at one by one and returns result of all in an arrayDISCARD
: Discards previously initialized transaction (withMULTI
).
- This server does not support
HGET
andHSET
commands as of now. - Replication is partially supported. Though propagation of commands does works, some commands related to command propagation valdation like
WAIT
is not implimented as of now. - Server only supports loading RDB file from specified location but does not support RDB File saving using
SAVE
command as of now. - This server only supports very limited and basic features.
- CodeCrafters for providing the "Build Your Own Redis" challenge
- The Redis project for inspiration and documentation