CacheIt is a simple Redis-like in-memory data store implemented in C++. It supports basic operations such as setting, getting, and deleting key-value pairs, along with a few additional data structures like linked lists and hash maps.
- TCP server for handling client connections
- Command parsing and execution
- Support for multiple data structures:
- Linked List
- Hash Map
- Non-blocking I/O using epoll
- Logging functionality with different log levels
cacheit
├── include
│ ├── command.hpp
│ ├── conn.hpp
│ ├── datastructures
│ │ ├── linked_list.hpp
│ │ └── hashmap.hpp
│ ├── epoll_manager.hpp
│ ├── logger.hpp
│ ├── server.hpp
│ └── utils.hpp
├── src
│ ├── client.cpp
│ ├── command.cpp
│ ├── conn.cpp
│ ├── datastructures
│ │ ├── linked_list.cpp
│ │ └── hashmap.cpp
│ ├── epoll_manager.cpp
│ ├── logger.cpp
│ ├── server.cpp
│ └── utils.cpp
├── CMakeLists.txt
└── README.md
-
Clone the repository:
git clone <repository-url> cd cacheit -
Create a build directory and navigate into it:
mkdir build cd build -
Run CMake to configure the project:
cmake .. -
Build the project:
make
To run the server, execute the following command:
./cacheit/src/server
To connect to the server and send commands, you can use the client:
./cacheit/src/client
set <key> <value>: Set a value for a keyget <key>: Get the value for a keydel <key>: Delete a key
lpush <list> <value>: Push value to the end of a listlrange <list> <start> <end>: Get values from a list (use0 -1for all)lrem <list> <count> <value>: Remove value from a list (count times)
sadd <set> <value1> [value2 ...]: Add one or more values to a setsrem <set> <value1> [value2 ...]: Remove one or more values from a setsmembers <set>: List all values in a set
hset <hash> <field> <value>: Set a field in a hashhget <hash> <field>: Get a field from a hashhdel <hash> <field>: Delete a field from a hashhgetall <hash>: Get all fields and values from a hash
zadd <zset> <score> <value>: Add a value with a score to a sorted setzrange <zset> <start> <end>: Get values by rank (use0 -1for all)zrem <zset> <value>: Remove a value from a sorted set
setbit <bitmap> <offset> <0|1>: Set a bit at offsetgetbit <bitmap> <offset>: Get a bit at offsetbitcount <bitmap>: Count bits set to 1
> set hello world
REPLY: set OK
> get hello
REPLY: world
> lpush mylist 42
REPLY: pushed 42 to mylist
> lrange mylist 0 -1
REPLY: 42
> sadd myset a b c
REPLY: added 3
> smembers myset
REPLY: a b c
> hset myhash field1 value1
REPLY: OK
> hget myhash field1
REPLY: value1
> zadd myzset 1.0 foo
REPLY: OK
> zrange myzset 0 -1
REPLY: foo
> setbit mybits 5 1
REPLY: OK
> getbit mybits 5
REPLY: 1
> bitcount mybits
REPLY: 1
A Python-based test suite is provided in the test/ directory. Each data structure and command is tested in its own file, and all tests can be run together with colored output.
python3 test/run_all_tests.pypython3 test/test_string.py
python3 test/test_linkedlist.py
python3 test/test_set.py
python3 test/test_hash.py
python3 test/test_zset.py
python3 test/test_bitmap.pyTest output will be colorized for easy pass/fail visibility.
Contributions are welcome! Please feel free to submit a pull request or open an issue for any suggestions or improvements.
This project is licensed under the MIT License. See the LICENSE file for more details.