旗下导航:搜·么
当前位置:网站首页 > PHP教程 > 正文

Redis模块之RediSearch的简朴运用【php教程】

作者:搜搜PHP网发布时间:2019-11-26分类:PHP教程浏览:108


导读:申明:装置的Redis效劳器必需为4.0以上版本,经由过程info敕令检察127.0.0.1:6379>INFOredis_version:4.0.2...
申明:装置的Redis效劳器必需为 4.0 以上版本,经由过程info敕令检察

127.0.0.1:6379> INFO
redis_version:4.0.2

一、装置 RediSearch

git clone https://github.com/RedisLabsModules/RediSearch.git
cd RediSearch/src
make 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.so
22886:C 15 Nov 16:54:07.255 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
22886:C 15 Nov 16:54:07.255 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=22886, just started
22886:C 15 Nov 16:54:07.255 # Configuration loaded
22886: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 TEXT
OK

(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 10
1) (integer) 1
2) "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 myIdx
OK

(5)增加和猎取自动完成发起

127.0.0.1:6379> FT.SUGADD autocomplete "hello world" 100
OK

127.0.0.1:6379> FT.SUGGET autocomplete "he"
1) "hello world"

以上就是Redis模块之RediSearch的简朴运用的细致内容,更多请关注ki4网别的相干文章!

标签:RedisRediSearch