range查询

xienkqul  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(399)

我试图用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>
6xfqseft

6xfqseft1#

尝试将命令与参数分开传递。举个例子:

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

我们还有一个专门的python库,用于在redis py之上构建的重新搜索:https://github.com/redisearch/redisearch-py

相关问题