Astra is a high-performance Redis-compatible cache middleware based on C++17, featuring modular design with the following core values:
- Provides thread-safe LRU cache implementation
- Supports Redis protocol network communication
- Implements command pattern client SDK, including C++ SDK, C SDK, and LabVIEW SDK, compatible with hiredis library
- Supports TTL expiration mechanism and background cleanup
- Supports service mode startup on Windows
- Provides publish/subscribe mode and Lua script execution
- Supports RDB snapshot saving and restoration
- Supports persistence with LevelDB for high-performance data storage
Please select your preferred language version for detailed information.
- Code Statistics Report - Detailed code line count, file count, etc.
- Interactive Charts - Interactive code statistics charts
Module | Function | Technical Implementation |
---|---|---|
Core | Basic type definitions and macros | C++17 features |
Utils | Logging system/scope protection | RAII pattern |
DataStructures | Lock-free queue/LRU cache | CAS atomic operations |
concurrent | Concurrency support framework | Thread pool/task queue/task flow |
CacheServer | Redis protocol parsing | Asio asynchronous IO |
Client SDK | Command pattern encapsulation | Polymorphic design |
- GET, SET, DEL, EXISTS, KEYS, TTL, MGET, MSET
- INCR, DECR
- PING
- COMMAND, INFO
- SUBSCRIBE, UNSUBSCRIBE, PUBLISH, PSUBSCRIBE, PUNSUBSCRIBE
- EVAL, EVALSHA
concurrent
module provides a complete concurrency solution:
-
ThreadPool Thread Pool
- Priority scheduling support (lower value first)
- Work stealing algorithm for load balancing optimization
- Full lifecycle management (Stop/Join/Resume)
- Supports mixed mode of local task queues and global task queues
-
TaskQueue Task Queue
- Supports task submission with callbacks
- Provides Post/Submit interfaces
- Implements asynchronous task scheduling based on thread pool
-
Task Flow Orchestration
- SeriesWork: Serial task group (similar to Promise chaining)
- ParallelWork: Parallel task group
- TaskPipeline: Stateful task chain with shared context
// Example: Concurrent task orchestration
auto queue = TaskQueue::Create();
// Serial task
SeriesWork::Create(queue)
->Then([]{ std::cout << "Step 1"; })
->Then([]{ std::cout << "Step 2"; })
->Run();
// Parallel task
ParallelWork::Create(queue)
->Add([]{ /* Task A */ })
->Add([]{ /* Task B */ })
->Run();
- Six Major Technical Features:
- Asynchronous network model (based on Asio + custom thread pool)
- Sharding lock mechanism to enhance concurrency performance
- Lock-free data structures to optimize access efficiency
- Full protocol support (Redis RESP compatible)
- Extensible command pattern design
- Multi-level task queue to optimize resource scheduling
Astra provides client SDKs in multiple languages, making it easy for developers to integrate into their applications:
For C++ developers, it provides a complete interface to access Astra features, supporting all Redis-compatible commands.
For C developers, it provides C language interfaces to access Astra features, compatible with standard C language specifications.
For LabVIEW developers, it provides Astra access interfaces in the LabVIEW environment, facilitating cache integration in LabVIEW.
Astra supports running in service mode on Windows systems, providing background persistent operation capabilities:
- Supports installation as a Windows service
- Supports starting and stopping the service
- Supports setting automatic startup
- Stable operation in service mode, supports automatic startup after system restart
- C++17 compatible compiler (GCC 9+/Clang 10+)
- CMake 3.14+
- System dependencies: libfmt-dev libssl-dev
# Clone project
$ git clone https://github.com/caomengxuan666/Astra.git
$ cd Astra
# Initialize submodules (LevelDB etc.)
$ git submodule update --init --recursive
# Build project
$ mkdir build && cd build
$ cmake ..
$ make -j$(nproc)
# Install project
$ sudo make install
Astra-CacheServer supports the following command line parameters:
Parameter | Description | Default |
---|---|---|
-p , --port |
Specify listening port | 6380 |
--bind |
Specify bind address | 127.0.0.1 |
-l , --loglevel |
Set log level(trace/debug/info/warn/error/fatal) | info |
-c , --coredump |
Persistence file path | None |
-m , --maxsize |
Maximum LRU cache size | No limit |
--file |
Enable file logging | false |
--cluster |
Enable cluster mode | false |
--cluster-port |
Cluster communication port | 16380 |
--persistence-type |
Persistence type(file/leveldb) | leveldb |
--leveldb-path |
LevelDB storage path | ./astra_leveldb |
# Start cache server with LevelDB persistence
$ Astra-CacheServer -p 6380 --bind 0.0.0.0 --persistence-type leveldb --leveldb-path ./astra_leveldb
# Start cache server with file persistence
$ Astra-CacheServer -p 6380 --persistence-type file -c dump.rdb
# Install as Windows service
$ Astra-CacheServer.exe install
# Cluster mode example
$ Astra-CacheServer --cluster --cluster-port 16380 -p 6380
#include "sdk/astra_client.hpp"
int main() {
Astra::Client::AstraClient client("127.0.0.1", 8080);
// Basic operations
client.Set("key", "value");
auto val = client.Get("key");
// Cache with TTL
client.Set("temp_key", "value", std::chrono::seconds(10));
auto ttl = client.TTL("temp_key");
// Atomic operations
client.Incr("counter");
auto count = client.Get("counter");
// Batch operations
std::vector<std::pair<std::string, std::string>> kvs = {
{"key1", "value1"},
{"key2", "value2"}
};
client.MSet(kvs);
std::vector<std::string> keys = {"key1", "key2"};
auto values = client.MGet(keys);
// Publish/Subscribe
// Subscription requires a separate client instance
// Publish message
client.Publish("channel", "Hello, Astra!");
}
Astra/
├── Astra-CacheServer/ # Redis-compatible cache service
│ ├── platform/ # Platform-specific code
│ │ └── windows/ # Windows service mode implementation
│ ├── sdk/ # Client SDKs (multiple language implementations)
│ └── ... # Server core code
├── core/ # Core type definitions
├── utils/ # Utility classes (logging/ScopeGuard)
├── concurrent/ # Concurrency support (thread pool/TaskQueue)
├── datastructures/ # Data structures (LRU/lock-free queue)
├── tests/ # GTest unit tests
├── third-party/ # Third-party dependencies (Asio/fmt)
└── benchmark/ # Performance tests
A: This occurs because the client exits immediately after calling the DEL
method, causing the server's message to be considered "lost," as 'DEL' itself returns 'OK'. However, this does not affect the program's normal operation. The client does not need to block indefinitely to wait for the server to confirm the successful deletion of data. Normally, the delete operation will not fail.
Please refer to CONTRIBUTING.md for the complete contribution guide, including code style, submission requirements, and review process.
Please submit bug reports or feature requests through GitHub Issues
This project is licensed under the MIT License - see LICENSE file