Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: |
sudo apt update
sudo apt install libssl-dev libnghttp2-dev
./configure --with-openssl --with-nghttp2 --with-kcp --with-mqtt
./configure --with-openssl --with-nghttp2 --with-kcp --with-mqtt --with-redis
make libhv evpp
- name: test
Expand Down
28 changes: 28 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ config_setting(
visibility = [":__subpackages__"],
)

config_setting(
name = "with_redis",
define_values = {
"WITH_EVPP": "ON",
"WITH_REDIS": "ON",
},
visibility = [":__subpackages__"],
)

config_setting(
name = "enable_uds",
define_values = {"ENABLE_UDS": "ON"}
Expand Down Expand Up @@ -189,6 +198,9 @@ HEADERS_DIRS = ["base", "ssl", "event"] + select({
}) + select({
"with_evpp": ["cpputil", "evpp"],
"//conditions:default": [],
}) + select({
"with_redis": ["redis"],
"//conditions:default": [],
}) + select({
"with_http": ["http"],
"//conditions:default": [],
Expand Down Expand Up @@ -305,6 +317,7 @@ CPPUTIL_HEADERS = [
"cpputil/iniparser.h",
"cpputil/json.hpp",
"cpputil/singleton.h",
"cpputil/LRUCache.h",
"cpputil/ThreadLocalStorage.h",
]

Expand All @@ -322,6 +335,15 @@ EVPP_HEADERS = [
"evpp/UdpServer.h",
]

REDIS_HEADERS = [
"redis/RedisMessage.h",
"redis/AsyncRedisClient.h",
"redis/RedisClient.h",
"redis/RedisPipeline.h",
"redis/RedisTransaction.h",
"redis/RedisSubscriber.h",
]

PROTOCOL_HEADERS = [
"protocol/icmp.h",
"protocol/dns.h",
Expand Down Expand Up @@ -372,6 +394,9 @@ HEADERS = ["hv.h", ":config", "hexport.h"] + BASE_HEADERS + SSL_HEADERS + EVENT_
}) + select({
"with_evpp": CPPUTIL_HEADERS + EVPP_HEADERS,
"//conditions:default": [],
}) + select({
"with_redis": REDIS_HEADERS,
"//conditions:default": [],
}) + select({
"with_http": HTTP_HEADERS,
"//conditions:default": [],
Expand Down Expand Up @@ -412,6 +437,9 @@ SRCS = CORE_SRCS + glob(["util/*.h", "util/*.c", "util/*.cpp"], exclude = ["util
}) + select({
"with_evpp": glob(["cpputil/*.h", "cpputil/*.c", "cpputil/*.cpp", "evpp/*.h", "evpp/*.c", "evpp/*.cpp"], exclude = ["cpputil/*_test.c", "evpp/*_test.c", "evpp/*_test.cpp"]),
"//conditions:default": [],
}) + select({
"with_redis": glob(["redis/*.h", "redis/*.c", "redis/*.cpp"], exclude = ["redis/*_test.c", "redis/*_test.cpp"]),
"//conditions:default": [],
}) + select({
"with_http": glob(["http/*.h", "http/*.c", "http/*.cpp"], exclude = ["http/*_test.c"]),
"//conditions:default": [],
Expand Down
6 changes: 6 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ make clean && make
make clean && make
```

### compile WITH_REDIS
```
./configure --with-redis
make clean && make
```

### More
```
./configure --help
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ option(WITH_HTTP "compile http" ON)
option(WITH_HTTP_SERVER "compile http/server" ON)
option(WITH_HTTP_CLIENT "compile http/client" ON)
option(WITH_MQTT "compile mqtt" OFF)
option(WITH_REDIS "compile redis" OFF)

option(ENABLE_UDS "Unix Domain Socket" OFF)
option(USE_MULTIMAP "MultiMap" OFF)
Expand Down Expand Up @@ -203,7 +204,7 @@ if(APPLE)
endif()

# see Makefile
set(ALL_SRCDIRS . base ssl event event/kcp util cpputil evpp protocol http http/client http/server mqtt)
set(ALL_SRCDIRS . base ssl event event/kcp util cpputil evpp redis protocol http http/client http/server mqtt)
set(CORE_SRCDIRS . base ssl event)
if(WIN32 OR MINGW)
if(WITH_WEPOLL)
Expand All @@ -225,6 +226,10 @@ endif()
if(WITH_EVPP)
set(LIBHV_HEADERS ${LIBHV_HEADERS} ${CPPUTIL_HEADERS} ${EVPP_HEADERS})
set(LIBHV_SRCDIRS ${LIBHV_SRCDIRS} cpputil evpp)
if(WITH_REDIS)
set(LIBHV_HEADERS ${LIBHV_HEADERS} ${REDIS_HEADERS})
set(LIBHV_SRCDIRS ${LIBHV_SRCDIRS} redis)
endif()
if(WITH_HTTP)
set(LIBHV_HEADERS ${LIBHV_HEADERS} ${HTTP_HEADERS})
set(LIBHV_SRCDIRS ${LIBHV_SRCDIRS} http)
Expand Down
34 changes: 33 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include config.mk
include Makefile.vars

MAKEF=$(MAKE) -f Makefile.in
ALL_SRCDIRS=. base ssl event event/kcp util cpputil evpp protocol http http/client http/server mqtt
ALL_SRCDIRS=. base ssl event event/kcp util cpputil evpp redis protocol http http/client http/server mqtt
CORE_SRCDIRS=. base ssl event
ifeq ($(WITH_KCP), yes)
CORE_SRCDIRS += event/kcp
Expand All @@ -24,6 +24,11 @@ ifeq ($(WITH_EVPP), yes)
LIBHV_HEADERS += $(CPPUTIL_HEADERS) $(EVPP_HEADERS)
LIBHV_SRCDIRS += cpputil evpp

ifeq ($(WITH_REDIS), yes)
LIBHV_HEADERS += $(REDIS_HEADERS)
LIBHV_SRCDIRS += redis
endif

ifeq ($(WITH_HTTP), yes)
LIBHV_HEADERS += $(HTTP_HEADERS)
LIBHV_SRCDIRS += http
Expand Down Expand Up @@ -71,6 +76,9 @@ EXAMPLES = hmain_test htimer_test hloop_test pipe_test \

ifeq ($(WITH_EVPP), yes)
EXAMPLES += nmap
ifeq ($(WITH_REDIS), yes)
EXAMPLES += redis_client_example redis_subscriber_example
endif
ifeq ($(WITH_HTTP), yes)
EXAMPLES += wrk
ifeq ($(WITH_HTTP_SERVER), yes)
Expand Down Expand Up @@ -185,6 +193,16 @@ tinyproxyd: prepare
nmap: prepare libhv
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) cpputil examples/nmap" DEFINES="PRINT_DEBUG"

ifeq ($(WITH_EVPP), yes)
ifeq ($(WITH_REDIS), yes)
redis_client_example: prepare
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) cpputil evpp redis" SRCS="examples/redis_client_test.cpp"

redis_subscriber_example: prepare
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) cpputil evpp redis" SRCS="examples/redis_subscriber_test.cpp"
endif
endif

wrk: prepare
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http" SRCS="examples/wrk.cpp"

Expand Down Expand Up @@ -287,6 +305,20 @@ unittest: prepare
$(CC) -g -Wall -O0 -std=c99 -I. -Ibase -Iprotocol -o bin/ping unittest/ping_test.c protocol/icmp.c base/hsocket.c base/htime.c -DPRINT_DEBUG
$(CC) -g -Wall -O0 -std=c99 -I. -Ibase -Iprotocol -o bin/ftp unittest/ftp_test.c protocol/ftp.c base/hsocket.c base/htime.c
$(CC) -g -Wall -O0 -std=c99 -I. -Ibase -Iprotocol -Iutil -o bin/sendmail unittest/sendmail_test.c protocol/smtp.c base/hsocket.c base/htime.c util/base64.c
ifeq ($(WITH_EVPP), yes)
ifeq ($(WITH_REDIS), yes)
$(MAKE) libhv
$(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Ievent -Icpputil -Iredis -o bin/redis_protocol_test unittest/redis_protocol_test.cpp redis/RedisMessage.cpp
$(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Iredis -Ievpp -o bin/redis_async_client_test unittest/redis_async_client_test.cpp unittest/redis_test_server.cpp -Llib -lhv -pthread
$(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Iredis -Ievpp -o bin/redis_client_test unittest/redis_client_test.cpp unittest/redis_test_server.cpp -Llib -lhv -pthread
$(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Iredis -Ievpp -o bin/redis_batch_test unittest/redis_batch_test.cpp unittest/redis_test_server.cpp -Llib -lhv -pthread
$(CXX) -g -Wall -O0 -std=c++11 -I. -Ibase -Issl -Ievent -Icpputil -Iredis -Ievpp -o bin/redis_subscriber_test unittest/redis_subscriber_test.cpp unittest/redis_test_server.cpp -Llib -lhv -pthread
else
$(RM) bin/redis_protocol_test bin/redis_async_client_test bin/redis_client_test bin/redis_batch_test bin/redis_subscriber_test
endif
else
$(RM) bin/redis_protocol_test bin/redis_async_client_test bin/redis_client_test bin/redis_batch_test bin/redis_subscriber_test
endif

run-unittest: unittest
bash scripts/unittest.sh
Expand Down
7 changes: 7 additions & 0 deletions Makefile.vars
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ EVPP_HEADERS = evpp/Buffer.h\
evpp/UdpClient.h\
evpp/UdpServer.h\

REDIS_HEADERS = redis/RedisMessage.h\
redis/AsyncRedisClient.h\
redis/RedisClient.h\
redis/RedisPipeline.h\
redis/RedisTransaction.h\
redis/RedisSubscriber.h\

PROTOCOL_HEADERS = protocol/icmp.h\
protocol/dns.h\
protocol/ftp.h\
Expand Down
15 changes: 15 additions & 0 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
- HTTP支持RESTful风格、路由、中间件、keep-alive长连接、chunked分块、SSE等特性
- WebSocket服务端/客户端
- MQTT客户端
- Redis客户端

## ⌛️ 构建

Expand Down Expand Up @@ -397,6 +398,18 @@ int main(int argc, char** argv) {
}
```

### Redis
见 [examples/redis_client_test.cpp](examples/redis_client_test.cpp) 和 [examples/redis_subscriber_test.cpp](examples/redis_subscriber_test.cpp)

Redis C++ 模块位于仓库根目录 `redis/`,并采用 `.h + .cpp` 分离结构。Redis 默认不编译,需要显式使用 `./configure --with-redis` 或 `cmake -DWITH_REDIS=ON` 打开。

```shell
./configure --with-redis
make unittest
cmake -S . -B build -DWITH_EVPP=ON -DWITH_REDIS=ON -DBUILD_UNITTEST=ON
cmake --build build --target redis_protocol_test redis_async_client_test redis_client_test redis_batch_test redis_subscriber_test
```

## 🍭 更多示例

### c版本
Expand Down Expand Up @@ -430,6 +443,8 @@ int main(int argc, char** argv) {
- HTTP客户端: [examples/http_client_test.cpp](examples/http_client_test.cpp)
- WebSocket服务端: [examples/websocket_server_test.cpp](examples/websocket_server_test.cpp)
- WebSocket客户端: [examples/websocket_client_test.cpp](examples/websocket_client_test.cpp)
- Redis客户端示例: [examples/redis_client_test.cpp](examples/redis_client_test.cpp)
- Redis订阅示例: [examples/redis_subscriber_test.cpp](examples/redis_subscriber_test.cpp)
- protobufRPC示例: [examples/protorpc](examples/protorpc)
- Qt中使用libhv示例: [hv-projects/QtDemo](https://github.com/hv-projects/QtDemo)

Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ but simpler api and richer protocols.
- HTTP supports RESTful, router, middleware, keep-alive, chunked, SSE, etc.
- WebSocket client/server
- MQTT client
- Redis client

## ⌛️ Build

Expand Down Expand Up @@ -338,6 +339,18 @@ int main(int argc, char** argv) {
}
```

### Redis
see [examples/redis_client_test.cpp](examples/redis_client_test.cpp) and [examples/redis_subscriber_test.cpp](examples/redis_subscriber_test.cpp)

The Redis C++ module lives in the repository root `redis/` and follows the same `.h + .cpp` split used by other libhv modules. Redis is disabled by default; enable it explicitly with `./configure --with-redis` or `cmake -DWITH_REDIS=ON`.

```shell
./configure --with-redis
make unittest
cmake -S . -B build -DWITH_EVPP=ON -DWITH_REDIS=ON -DBUILD_UNITTEST=ON
cmake --build build --target redis_protocol_test redis_async_client_test redis_client_test redis_batch_test redis_subscriber_test
```

## 🍭 More examples
### c version
- [examples/hloop_test.c](examples/hloop_test.c)
Expand Down Expand Up @@ -370,6 +383,8 @@ int main(int argc, char** argv) {
- [examples/http_client_test.cpp](examples/http_client_test.cpp)
- [examples/websocket_server_test.cpp](examples/websocket_server_test.cpp)
- [examples/websocket_client_test.cpp](examples/websocket_client_test.cpp)
- [examples/redis_client_test.cpp](examples/redis_client_test.cpp)
- [examples/redis_subscriber_test.cpp](examples/redis_subscriber_test.cpp)
- [examples/protorpc](examples/protorpc)
- [hv-projects/QtDemo](https://github.com/hv-projects/QtDemo)

Expand Down
9 changes: 9 additions & 0 deletions cmake/vars.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ set(EVPP_HEADERS
evpp/UdpServer.h
)

set(REDIS_HEADERS
redis/RedisMessage.h
redis/AsyncRedisClient.h
redis/RedisClient.h
redis/RedisPipeline.h
redis/RedisTransaction.h
redis/RedisSubscriber.h
)

set(PROTOCOL_HEADERS
protocol/icmp.h
protocol/dns.h
Expand Down
1 change: 1 addition & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ WITH_HTTP=yes
WITH_HTTP_SERVER=yes
WITH_HTTP_CLIENT=yes
WITH_MQTT=no
WITH_REDIS=no

# features
# base/hsocket.h: Unix Domain Socket
Expand Down
21 changes: 4 additions & 17 deletions config.mk
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@

PREFIX=/usr/local
INSTALL_INCDIR=$(PREFIX)/include/hv
INSTALL_LIBDIR=$(PREFIX)/lib

BUILD_SHARED=yes
BUILD_STATIC=yes

# modules
# include icmp dns ftp smtp
WITH_PROTOCOL=no

WITH_EVPP=yes
WITH_HTTP=yes
WITH_HTTP_SERVER=yes
WITH_HTTP_CLIENT=yes
WITH_MQTT=no

# features
# base/hsocket.h: Unix Domain Socket
WITH_REDIS=yes
ENABLE_UDS=no
# base/RAII.cpp: Windows MiniDumpWriteDump
ENABLE_WINDUMP=no
# http/http_content.h: KeyValue,QueryParams,MultiPart
USE_MULTIMAP=no

# dependencies
# for http/client
WITH_CURL=no
# for http2
WITH_NGHTTP2=no
# for SSL/TLS
WITH_OPENSSL=no
WITH_GNUTLS=no
WITH_MBEDTLS=no

# rudp
WITH_KCP=no
WITH_IO_URING=no
CONFIG_DATE=20260711
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ modules:
--with-http-client compile http client module? (DEFAULT: $WITH_HTTP_CLIENT)
--with-http-server compile http server module? (DEFAULT: $WITH_HTTP_SERVER)
--with-mqtt compile mqtt module? (DEFAULT: $WITH_MQTT)
--with-redis compile redis module? (DEFAULT: $WITH_REDIS)
features:
--enable-uds enable Unix Domain Socket? (DEFAULT: $ENABLE_UDS)
Expand Down
2 changes: 1 addition & 1 deletion docs/PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
- http client/server: include https http1/x http2
- websocket client/server
- mqtt client
- redis client

## Plan

- redis client
- async DNS
- lua binding
- js binding
Expand Down
1 change: 1 addition & 0 deletions docs/cn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
- [class HttpClient: HTTP客户端类](HttpClient.md)
- [class WebSocketServer: WebSocket服务端类](WebSocketServer.md)
- [class WebSocketClient: WebSocket客户端类](WebSocketClient.md)
- [class RedisClient: Redis客户端类](RedisClient.md)
Loading
Loading