127.0.0.1:6379 INFOredis_version:4.0.2
一、安装 RediSearch
git clone https://github.com/RedisLabsModules/RediSearch.gitcd RediSearch/srcmake all# Assuming you have a redis build from the unstable branch:/path/to/redis-server --loadmodule ./redisearch.so
二、启动服务
www@TinywanAliYun:/usr/local/redis4.0/etc$ /usr/local/redis4.0/bin/redis-server --loadmodule /home/www/build/RediSearch/src/redisearch.so22886:C 15 Nov 16:54:07.255 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo22886:C 15 Nov 16:54:07.255 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=22886, just started22886:C 15 Nov 16:54:07.255 # Configuration loaded22886:M 15 Nov 16:54:07.256 # Creating Server TCP listening socket *:6379: bind: Address already in use
可以动态加载
www@TinywanAliYun:/usr/local/redis4.0/etc$ redis-cli 127.0.0.1:6379 MODULE LOAD /home/www/build/RediSearch/src/redisearch.so
配置文件加载:
vi /usr/local/redis4.0/etc/redis.conf#文件底部加入loadmodule /home/www/build/RediSearch/src/redisearch.so
重启服务器
sudo systemctl restart redis
三、使用
(1)使用字段和权重创建索引(默认权重为1.0)
127.0.0.1:6379 FT.CREATE myIdx SCHEMA title TEXT WEIGHT 5.0 body TEXT url TEXTOK
(2)将文档添加到索引
127.0.0.1:6379 FT.ADD myIdx doc1 1.0 FIELDS title hello world body lorem ipsum url http://redis.io OK
(3)搜索索引
127.0.0.1:6379 FT.SEARCH myIdx hello world LIMIT 0 101) (integer) 12) doc1 3) 1) title 2) hello world 3) body 4) lorem ipsum 5) url 6) http://redis.io
注意:输入预计是有效的utf-8或ascii。目前引擎无法处理宽字符unicode。
(4)删除索引
127.0.0.1:6379 FT.DROP myIdxOK
(5)添加和获取自动完成建议
127.0.0.1:6379 FT.SUGADD autocomplete hello world 100127.0.0.1:6379 FT.SUGGET autocomplete he 1) hello world
以上就是Redis模块之RediSearch的简单使用的详细内容,PHP教程
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。
新闻热点
疑难解答