开发者笔记

关于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
  • 亚马逊 Linux 2
  • 水手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 社区版 RediSearch 协调器。

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()函数来设置断点。

RATE THIS PAGE
Back to top ↑