A simple Redis server implementation in Go, built as part of a learning exercise or for lightweight, custom Redis-like use cases. This project leverages Go'store networking and concurrency features to support basic Redis commands, aiming to provide a functional yet minimal Redis-like server.
- Basic Commands
PING
- Test connectivity with the server. Responds withPONG
.ECHO
- Responds with the argument passed.SET
- Stores a key-value pair in memory with optional expiration.GET
- Retrieves the value for a given key. Returnsnil
if the key does not exist.CONFIG
- Retrieve or set server and environment configuration.KEYS
- Fetches keys matching a pattern (currently supports*
wildcard).INFO
- Provides server information.REPLCONF
- Acknowledge and synchronize replica configuration.GETACK
- Replica synchronisationACK
- Replica synchronisation
PSYNC
- Implements full resynchronization for replica servers.COMMAND
for documentation purposes.DOCS
- Server documentation. Currently just returns Welcome
WAIT
- Replica consistency - This command blocks the current client until all the previous write commands are successfully transferred and acknowledged by at least the number of replicas you specify in the numreplicas argument.
- Go v1.23 or higher.
- Redis CLI or any Redis client for testing.
- Clone the repository::
git clone <repository-url>
- Navigate to the project directory:
cd redis-gp
- Build the project:
go build -o redis-go .
- Start the server:
./redis-go
- Connect to the server using the Redis CLI:
redis-cli
- PING:
> PING
+PONG
- SET:
> SET key value
+OK
- GET:
> GET key
"value"
Retrieve configurations:
> CONFIG GET dir
1) "dir"
2) "/path/to/directory"
> KEYS *
1) "key1"
2) "key2"
> INFO replication
"Master replication information"
> REPLCONF ACK 0
+OK
> PSYNC
1) "FULLRESYNC <master-replid> <master-offset>"
2) "<data-dump>"
> COMMAND docs
"Welcome"
This server supports a basic implementation of redis' master server replication, allowing replicas to synchronize with the master for data consistency. The server supports replica synchronization and replica command acknowledgment to ensure consistency and coordination between the master server and its replicas. Replication is implemented to allow replicas to stay synchronized with the master server, especially for critical commands and state updates. The commands related to replica synchronization include:
This project is designed to:
- Explore Go'store capabilities in building a custom server.
- Understand concurrency patterns and networking in Go.
- Serve as a practical example for custom lightweight Redis-like use cases.