方式一:源码编译安装(未成功)
能找到的文档基本都是这一套,但是编译过程中会遇到各种坑,make版本,其他依赖问题,尝试解决无果。
# --recursive 选项递归下载子模块依赖
git clone --recursive https://github.com/RediSearch/RediSearch.git
make setup
make build
#在redis.conf最后一行添加
loadmodule /home/redisearch/build/redisearch.so
方式二:docker安装
docker run -p 6379:6379 -d docker.io/redislabs/redisearch
如果无法拉取镜像更换源尝试。
redisearch使用
docker exec -it <container_name> redis-cli
127.0.0.1:6379>
命令行操作
#列出索引
FT._list
#创建索引
FT.CREATE myIndex SCHEMA filename TEXT filepath TEXT time TEXT
#插入数据
FT.ADD myIndex document1 1.0 FIELDS filename "file1" filepath "/root/dir1/file1" time "2024-05-06 9:00"
#根据前缀file查找字段
FT.SEARCH myIndex "@filename:file*"
#删除所有数据
FLUSHALL
代码操作(c++)
#include <iostream>
#include <filesystem>
#include <map>
#include <hiredis/hiredis.h>
int main() {
// Connect to Redis server
redisContext *redis = redisConnect("127.0.0.1", 6379);
if (redis == nullptr || redis->err) {
if (redis) {
std::cerr << "Error: " << redis->errstr << std::endl;
redisFree(redis);
} else {
std::cerr << "Failed to connect to Redis server" << std::endl;
}
return 1;
}
std::cout << "Connected to Redis server successfully " << std::endl;
return 0;
}
标签:FT,redisearch,redis,6379,使用,docker,include,安装
From: https://www.cnblogs.com/itsfei/p/18179257