开发者说明

关于 RediSearch 调试、测试和文档的说明

RediSearch 功能的开发涉及设置开发环境(可以是基于 Linux 或 macOS),构建模块,运行测试和基准测试,以及调试模块及其测试。

克隆 Git 仓库

运行以下命令克隆 RediSearch 模块及其子模块

git clone --recursive https://github.com/RediSearch/RediSearch.git

在隔离环境中工作

在隔离环境中进行开发有多种原因,例如保持工作站整洁,以及为不同的 Linux 发行版进行开发。隔离环境最通用的选项是虚拟机。使用 Vagrant 设置虚拟机非常容易。Docker 甚至更灵活,因为它提供了几乎即时可用的解决方案。

search=$(docker run -d -it -v $PWD:/build debian:bullseye bash)
docker exec -it $search bash

然后,在容器内,cd /build 并照常进行。

在此模式下,所有安装都保留在 Docker 容器的范围内。退出容器后,您可以使用上述 docker exec 重新调用它,或者将容器的状态提交到镜像并在以后重新调用它。

docker commit $search redisearch1
docker stop $search
search=$(docker run -d -it -v $PWD:/build rediseatch1 bash)
docker exec -it $search bash

您可以将 debian:bullseye 替换为您选择的操作系统,其中宿主操作系统是最佳选择,允许您在构建完成后在宿主上运行 RediSearch 二进制文件。

安装先决条件

要构建和测试 RediSearch,您需要安装几个软件包,具体取决于底层操作系统。支持以下操作系统:

  • Ubuntu 18.04
  • Ubuntu 20.04
  • Ubuntu 22.04
  • Debian Linux 11
  • Rocky Linux 8
  • Rocky Linux 9
  • Amazon Linux 2
  • Mariner 2.0
  • macOS

要使用安装脚本在您的系统上安装先决条件,首先进入 RediSearch 目录,然后运行

cd ./install
./install_script.sh sudo
./install_boost.sh 1.83.0

请注意,这将使用本机包管理器在您的系统上安装各种软件包(在 Docker 环境中不需要 sudo)。

如果您想避免这样做,您可以

  • 查看 ./install 目录下的相关安装脚本并手动安装软件包。
  • 使用如上所述的隔离环境。

安装 Redis

通常情况下,您应该运行最新的 Redis 版本。

如果您的操作系统有 Redis 7.x 软件包,您可以使用操作系统包管理器进行安装。

否则,您可以按照 Redis GitHub 页面中的说明从源代码构建并安装它。

获取帮助

make help 提供了开发功能的快速摘要。以下是包含最常用和最相关功能的列表(部分)

make fetch         # download and prepare dependant modules

make build          # compile and link
  COORD=1             # build coordinator
  DEBUG=1             # build for debugging
  NO_TESTS=1          # disable unit tests
  WHY=1               # explain CMake decisions (in /tmp/cmake-why)
  FORCE=1             # Force CMake rerun (default)
  CMAKE_ARGS=...      # extra arguments to CMake
  VG=1                # build for Valgrind
  SAN=type            # build with LLVM sanitizer (type=address|memory|leak|thread) 
  SLOW=1              # do not parallelize build (for diagnostics)
  GCC=1               # build with GCC (default unless Sanitizer)
  CLANG=1             # build with CLang
  STATIC_LIBSTDCXX=0  # link libstdc++ dynamically (default: 1)
make parsers       # build parsers code (required after chaging files under query_parser dir)
make clean         # remove build artifacts
  ALL=1              # remove entire artifacts directory

make run           # run redis with RediSearch
  COORD=1            # run three local shards with coordinator (assuming the module was built with coordinator support)
  GDB=1              # invoke using gdb

make test          # run all tests
  COORD=1            # test coordinator
  TEST=name          # run specified test
make pytest        # run python tests (tests/pytests)
  COORD=1            # test coordinator 
  TEST=name          # e.g. TEST=test:testSearch
  RLTEST_ARGS=...    # pass args to RLTest
  REJSON=1|0|get     # also load JSON module (default: 1)
  REJSON_PATH=path   # use JSON module at `path`
  EXT=1              # External (existing) environment
  GDB=1              # RLTest interactive debugging
  VG=1               # use Valgrind
  VG_LEAKS=0         # do not search leaks with Valgrind
  SAN=type           # use LLVM sanitizer (type=address|memory|leak|thread) 
make unit-tests    # run unit tests (C and C++)
  TEST=name          # e.g. TEST=FGCTest.testRemoveLastBlock
make c_tests       # run C tests (from tests/ctests)
make cpp_tests     # run C++ tests (from tests/cpptests)

make callgrind     # produce a call graph
  REDIS_ARGS="args"

make sanbox        # create container with CLang Sanitizer

从源代码构建

从项目根目录运行以下命令

make build 将构建 RediSearch。

make build COORD=1 将构建 Redis Open Source RediSearch Coordinator。

make build STATIC=1 将构建为静态库。

注意

  • 二进制文件根据平台和构建变体放置在 bin 目录下。
  • RediSearch 使用 CMake 作为其构建系统。make build 将调用 CMake 以及完成构建所需的后续 make 命令。

使用 make clean 清除构建产物。make clean ALL=1 将删除整个 bin 子目录。

诊断构建过程

默认情况下,make build 将并行构建。

为了诊断构建过程,可以使用 make build SLOW=1 VERBOSE=1 来检查编译命令。

运行带有 RediSearch 的 Redis

以下命令将运行 redis 并加载 RediSearch 模块。

make run

您可以在另一个终端中打开 redis-cli 与其交互。

运行测试

有几组单元测试

  • C 测试,位于 tests/ctests 中,通过 make c-tests 运行。
  • C++ 测试(由 GTest 启用),位于 tests/cpptests 中,通过 make cpp-tests 运行。
  • Python 测试(由 RLTest 启用),位于 tests/pytests 中,通过 make pytest 运行。

您可以通过调用 make test 运行所有测试。

可以使用 TEST 参数运行单个测试,例如 make test TEST=regex

调试

要进行调试构建(启用符号信息并禁用优化),请运行 make DEBUG=1。然后您可以使用 make run DEBUG=1 调用 gdb。除了在 gdb 中设置断点的常规方式外,还可以使用 BB 宏在 RediSearch 代码内部设置断点。这仅在 gdb 下运行时有效。

同样,在单测试模式下的 Python 测试中,您可以在测试内部使用 BB() 函数设置断点。

为本页评分
回到顶部 ↑