pip install redis
import redis
def getRedis():
url='192.168.20.3'
port=6379
pool = redis.ConnectionPool(host=url, port=port, db=0)
return redis.Redis(connection_pool=pool)
from redis.commands.search.field import TextField
from redis.commands.search import Search
from redis.commands.search.indexDefinition import IndexDefinition
def createIndex(indexName):
r = getRedis()
search = Search(r,indexName)
definition = IndexDefinition(prefix=['blog:'],language='chinese')
search.create_index([TextField("title"),TextField("link"),TextField("richContent"),TextField("authorLink"),TextField("createTime")],definition=definition)
return search ;
r=getRedis()
r.haset('blog:1',{'title':'你好','link':'www.xxx.com'})
search = createIndex('testIndex')
result = search.search(Query('%你%').highlight().language('chinese'))
print(result)
https://pypi.org/project/redisearch/
http://www.zzvips.com/article/173822.html