簡體   English   中英

使用 Python 客戶端在 Redisearch 中進行范圍查詢

[英]Range query in Redisearch with Python client

我正在嘗試使用 python 客戶端查詢 Redisearch 中的一系列值,但它沒有正確讀取值之間的空間。 關於如何解決的任何想法?

conn = redis.Redis(host='localhost', port=6379, db=0)

q = 'FT.SEARCH idx "@date:[20200101 20200301]" LIMIT 0 100'
conn.execute_command(q)

拋出錯誤:

--------------------------------------------------------------------------
ResponseError                             Traceback (most recent call last)
<ipython-input-31-5321b184194e> in <module>
      2 q = f'''FT.SEARCH idx "@date:[20200101 20200301]" LIMIT 0 1000000'''
      3 
----> 4 res = conn.execute_command(q)
      5 print(res)

C:\Miniconda3\envs\ssnc\lib\site-packages\redis\client.py in execute_command(self, *args, **options)
    899         try:
    900             conn.send_command(*args)
--> 901             return self.parse_response(conn, command_name, **options)
    902         except (ConnectionError, TimeoutError) as e:
    903             conn.disconnect()

C:\Miniconda3\envs\ssnc\lib\site-packages\redis\client.py in parse_response(self, connection, command_name, **options)
    913         "Parses a response from the Redis server"
    914         try:
--> 915             response = connection.read_response()
    916         except ResponseError:
    917             if EMPTY_RESPONSE in options:

C:\Miniconda3\envs\ssnc\lib\site-packages\redis\connection.py in read_response(self)
    754 
    755         if isinstance(response, ResponseError):
--> 756             raise response
    757         return response
    758 

ResponseError: Unknown argument `20200301]"` at position 1 for <main>

嘗試將命令與 arguments 分開傳遞。 這是一個例子:

conn.execute_command('ft.search', 'books-idx', '@average_rating:[0 1]')

我們還有一個專用的 Python 庫,用於構建在 redis-py 之上的 RediSearch: https://github.com/RediSearch/redisearch-py

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM