Welcome to the Redis-lite repository! This project involves creating a lite version of Redis, an in-memory data structure server. The goal is to support operations similar to the original Redis server.
Redis is a famous in-memory data structure store that serves as a database, cache, and message broker. Known for its versatility and performance, Redis supports a variety of data types, including strings, hashes, lists, sets, and sorted sets. It is widely used in applications requiring high-speed data access, real-time analytics, and caching.
This project aims to create a lightweight, Python-based version of Redis, termed "Redis Lite." The goal is to replicate essential functionalities of Redis while simplifying its core operations. This project will focus on understanding and implementing the core concepts behind Redis, including:
- Redis Serialization Protocol (RESP): I implemented my version of the communication protocol used by Redis, which defines how data is serialized and deserialized between the server and clients.
- Basic Commands: Implemented fundamental commands such as SET and GET, which are crucial for data storage and retrieval.
- Concurrency: Handled simultaneous multiple client connections to mimic Redis’s ability to manage concurrent requests.
- Expiry Mechanisms: Added support for command expiry options to understand Redis’s data expiration capabilities.
- Additional Commands: Expanded functionality to include various Redis commands such as EXISTS, DEL, INCR, DECR, LPUSH, and RPUSH.
- Performance Testing: Compare the performance of your Redis Lite server against the official Redis server to assess efficiency and speed.
By building this Redis Lite server, I gained hands-on experience with:
- Network Programming: Learnt to manage client-server communication over TCP/IP in Python.
- Serialization Protocols: Understood how data is encoded and decoded in a real-world system.
- Concurrency Models: Explored multi-threading or asynchronous approaches to handle multiple simultaneous connections.
- System Design: Develop a deeper understanding of how in-memory data stores are designed and optimized.
This project was an excellent opportunity to delve into the inner workings of Redis and gain practical experience in building a high-performance data structure server.
Redis is an in-memory data structure server supporting strings, hashes, lists, sets, sorted sets, and more. This project is inspired by Redis's original goal as a REmote DIctionary Server. To do this, I built a lite version of Redis supporting similar operations, implemented in Python.
The project is divided into several steps, each focusing on different aspects of building a Redis server:
- Environment Setup: Prepare the development environment.
- RESP Serialization/Deserialization: Implement the Redis Serialization Protocol.
- Building the Server: Create a server that listens for client connections and handles basic commands.
- Core Functionality: Implement the SET and GET commands.
- Concurrent Clients: Handle multiple client connections concurrently.
- SET Command Expiry Options: Extend the SET command to support expiry options.
- Additional Commands: Implement commands like EXISTS, DEL, INCR, DECR, LPUSH, RPUSH, and SAVE.
- Performance Testing: Compare performance with the original Redis.
To get started, clone this repository and set up your development environment. Ensure you have Python installed and optionally install Redis for testing purposes.
git clone https://github.com/kapoor98ak/redis-lite.git
cd redis-lite
Set up your development environment, including your editor and necessary tools for network programming and test-driven development (TDD). Optionally, install Redis for testing your implementation.
Implement the Redis Serialization Protocol (RESP). This protocol is used to communicate with a Redis Server. Create tests for example messages to ensure correct serialization and deserialization.
Create a Redis Lite server that starts and listens on port 6379. Implement the PING command to respond with PONG.
Implement the core functionality of Redis by adding support for the SET and GET commands.
% redis-cli set Name John
OK
% redis-cli get Name
"John"
Make your Redis Lite server handle multiple concurrent clients. You can choose between multi-threading or asynchronous programming.
Extend the SET command to support the EX, PX, EXAT, and PXAT expiry options. Ensure that the expiry is implemented efficiently.
Implement additional commands:
- EXISTS: Check if a key is present.
- DEL: Delete one or more keys.
- INCR: Increment a stored number by one.
- DECR: Decrement a stored number by one.
- LPUSH: Insert values at the head of a list.
- RPUSH: Insert values at the tail of a list.
- SAVE: Save the database state to disk and implement load on startup.
Use Redis Benchmark to test the performance of your server. Compare your server's performance with the original Redis server.
% redis-benchmark -t SET,GET -q
SET: 108225.10 requests per second, p50=0.223 msec
GET: 115606.94 requests per second, p50=0.215 msec
- Implemented CI using Github Actions: Referred Github Documentation