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
GETandSETcommand with values with expiry time. - RDB local database support for persistent storage.
- AOF (Append-Only File) support for enhanced durability with default sync frequency.
- Full Replication support with command propagation, acknowledgement tracking, and replica management.
- List support with
RPUSH,LPUSH,LRANGE,LLEN,LPOPandBLPOPcommands. - Sorted sets support with
ZADD,ZRANK,ZRANGE,ZCARD,ZSCOREandZREMcommands. - Streams support with
TYPE,XADD,XRANGE, andXREADcommands. - Transaction support with
MULTI,INCR,EXEC,DISCARD,WATCHandUNWATCHcommands. - Pub/Sub support with
SUBSCRIBE,UNSUBSCRIBEandPUBLISHcommands. - Basic ACL support with
AUTH,ACL WHOAMI,ACL GETUSERandACL SETUSERcommands. -Geo support withGEOADD,GEOPOS,GEODISTandGEOSEARCHcommands.
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
myredisexecutable to start server.
./myredis
- By default this server will bind to port
6379, Though you can use any port using--portflag while starting server
./myredis --port 6380
- You can load existing RDB file while staring the server using
--dirflag to specify file location and--dbfilenameflag 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.
- You can enable AOF (Append-Only File) persistence using the
--appendonlyflag (set toyesto enable). Configure AOF options using:--appendonly yes|no: Enable/disable AOF persistence--appendfilename: AOF file name (default:appendonly.aof)--appenddirname: Directory for AOF file (default:appendonlydir)--appendfsync: AOF sync frequency -everysec,always, orno(default:everysec)
./myredis --appendonly yes --appendfsync everysec
- By default Server will assume a
masterrole. To start server as replica server of some other master server you can pass--replicaofflag along with host and port ofmasterserver.
./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 settings (supportsLISTENING-PORT,CAPA,GETACK, andACK)PSYNC: Internal command used for full resynchronization in replicationWAIT: Wait for replica acknowledgementsTYPE: Get type of a key (string,stream,list, ornone)INCR: Increments integer value of specified key by 1MULTI: Starts a transaction — subsequent commands are queued without executionEXEC: Executes all queued commands and returns results as an arrayDISCARD: Discards a previously initialized transaction (withMULTI)XADD: Append an entry to a streamXRANGE: Retrieve a range of entries from a streamXREAD: Read from one or more streams with optional blockingRPUSH: Append one or more values to a listLPUSH: Prepend one or more values to a listLRANGE: Get a range of elements from a listLLEN: Get the length of a listLPOP: Remove and return element(s) from the head of a listBLPOP: Blocking pop from the head of a listSUBSCRIBE: Subscribe to one or more channelsUNSUBSCRIBE: Unsubscribe from one or more channelsPUBLISH: Publish a message to a channelAUTH: Authenticate with a username and passwordACL WHOAMI: Return the username of the current connectionACL GETUSER: Get flags and passwords for a userACL SETUSER: Create or modify a user (supports>passwordrule to set password)COMMAND: Get information about Redis commandsZADD: Add one or more members to a sorted setZRANK: Get the rank of a member in a sorted setZRANGE: Get a range of members from a sorted setZCARD: Get the cardinality (number of members) of a sorted setZSCORE: Get the score of a member in a sorted setZREM: Remove one or more members from a sorted setWATCH: Watch one or more keys for transactionUNWATCH: Unwatch all keysGEOADD: Add one or more locations to a geo keyGEOPOS: Get the positions of one or more locationsGEODIST: Get the distance between two locationsGEOSEARCH: Search for locations within a radius
HGETandHSETcommands are not supported.PSUBSCRIBEandPUNSUBSCRIBE(pattern-based pub/sub) are not supported.- RDB file loading is supported but
SAVEcommand (writing RDB) is not. - Only RDB with single database and basic key-value storage is supported.
- ACL support is limited to password-based authentication; command/key permissions are not enforced.
- AOF persistence only supports the default sync frequency (
everysec); other modes (alwaysandno) are not yet implemented. - Replica restrictions: Connected replicas can only execute
REPLCONFcommand; other commands are restricted to prevent accidental modifications.
- CodeCrafters for providing the "Build Your Own Redis" challenge
- The Redis project for inspiration and documentation
- HDT3213 for CRC64 Checksum Jones varient implimentation.