This is a simple Redis-like key-value database server implemented in Go. It allows to store and retrieve data using a simple command-line interface through telnet.
- In-memory key-value storage
- Support for basic Redis-like commands
- Multiple client connections
- Data persistence using RDB file
- Transaction support using MULTI commands
- Go
- Telnet client
You can build the binary file for the server. Run the following command from the project root:
go build -o my-redis redis/main.goThen, start the server using the binary:
./my-redisThe server runs using the binary file. By default, it listens on:
- Host: localhost
- Port: 8080
- Storage path: /usr/local/var/db/my_redis/
Override settings using the flags:
./my-redis -H <host> -p <port> -s <storage-path>Use telnet to connect to the server:
telnet localhost 8080-
SET key value- Store a key-value pairSET name john -
GET key- Retrieve a value by keyGET name -
DEL key [key ...]- Delete one or more keysDEL name age -
INCR key- Increment the integer value of a key by 1INCR counter -
INCRBY key increment- Increment the integer value of a key by the given amountINCRBY counter 5 -
Transaction Commands:
MULTI- Start a transactionEXEC- Execute all commands in the transactionDISCARD- Discard the transaction
Example:
MULTI SET user1 john SET user2 jane EXEC -
exit- Close the connection
The server automatically saves data to the specified storage path in an RDB file. This data is loaded when the server starts up again.
- All commands are case-insensitive
- String values containing spaces should be wrapped in quotes
- The server supports multiple concurrent client connections
To run tests, execute the following command from the root:
go test ./...