Home > Backend Development > PHP Tutorial > Simple use of Redis module RediSearch

Simple use of Redis module RediSearch

藏色散人
Release: 2023-04-06 06:18:01
forward
4674 people have browsed it

Note: The installed Redis server must be version 4.0 or above, check it through the info command

127.0.0.1:6379> INFO
redis_version:4.0.2
Copy after login

1. Install 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
Copy after login

2. Start the service

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
Copy after login

Can be loaded dynamically

www@TinywanAliYun:/usr/local/redis4.0/etc$ redis-cli 
127.0.0.1:6379> MODULE LOAD /home/www/build/RediSearch/src/redisearch.so
Copy after login

Configuration file loading:

vi /usr/local/redis4.0/etc/redis.conf
#文件底部加入
loadmodule /home/www/build/RediSearch/src/redisearch.so
Copy after login

Restart the server

sudo systemctl restart redis
Copy after login

3. Use

(1) Create an index using fields and weights (Default weight is 1.0)

127.0.0.1:6379> FT.CREATE myIdx SCHEMA title TEXT WEIGHT 5.0 body TEXT url TEXT
OK
Copy after login

(2) Add the document to the index

127.0.0.1:6379> FT.ADD myIdx doc1 1.0 FIELDS title "hello world" body "lorem ipsum" url "http://redis.io" 
OK
Copy after login

(3) Search Index

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"
Copy after login

Note: Input is expected to be valid utf-8 or ascii . Currently the engine cannot handle wide character unicode.

(4) Delete index

127.0.0.1:6379> FT.DROP myIdx
OK
Copy after login

(5) Add and get auto-complete suggestions

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

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

Simple use of Redis module RediSearch


The above is the detailed content of Simple use of Redis module RediSearch. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php redis connection problem
From 1970-01-01 08:00:00
0
0
0
About a small error in the redis manual
From 1970-01-01 08:00:00
0
0
0
python2.7 - django cannot connect to redis
From 1970-01-01 08:00:00
0
0
0
I can't connect to redis using php
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template