This is a simple Redis server implementation written in Go.
- Supports basic Redis commands: SET, GET, PING, and ECHO.
- Handles concurrent client connections over TCP/IP.
- Uses a synchronized map and locks for data storage to prevent race conditions.
- Supports expiration time for keys.
- Go 1.15 or higher
-
Clone the repository:
git clone https://github.com/theakhandpatel/redis-server.git
-
Change to the project directory:
cd redis-server
-
Run the server:
./spawn_redis_server.sh
By default, the server listens on port 6379.
Connect to the Redis server using a Redis client and send commands. The supported commands are:
SET
: Set the value of a key.GET
: Get the value of a key.PING
: Check if the server is running.ECHO
: Return the given message.
Example usage:
$ redis-cli
127.0.0.1:6379> SET mykey hello
OK
127.0.0.1:6379> GET mykey
"hello"
127.0.0.1:6379> SET yourkey lost PX 500ms
OK
127.0.0.1:6379> GET yourkey
nil
127.0.0.1:6379> PING
PONG
127.0.0.1:6379> ECHO hello world
"hello world"
The Redis server implementation handles concurrent client connections using Goroutines. Each client connection is handled in a separate Goroutine, allowing multiple clients to interact with the server simultaneously.
To prevent race conditions when accessing and modifying the data storage (sync.Map
), the implementation uses locks. The sync.Map
type provides built-in synchronization for concurrent access, but locks are used when necessary to ensure exclusive access to critical sections of the code.
By utilizing Goroutines and locks, the Redis server ensures concurrent execution and prevents race conditions, maintaining data integrity.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License.
This Redis server implementation was inspired by the Redis open-source project (https://redis.io/).