使用 Python 客户端在 Redisearch 中进行范围查询
Range query in Redisearch with Python client
我正在尝试使用 python 客户端在 Redisearch 中查询一系列值,但它没有正确读取值之间的 space。关于如何解决的任何想法?
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>
尝试将命令与参数分开传递。这是一个例子:
conn.execute_command('ft.search', 'books-idx', '@average_rating:[0 1]')
我们还有一个专用的Python RediSearch 库,它建立在 redis-py 之上:https://github.com/RediSearch/redisearch-py
我正在尝试使用 python 客户端在 Redisearch 中查询一系列值,但它没有正确读取值之间的 space。关于如何解决的任何想法?
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>
尝试将命令与参数分开传递。这是一个例子:
conn.execute_command('ft.search', 'books-idx', '@average_rating:[0 1]')
我们还有一个专用的Python RediSearch 库,它建立在 redis-py 之上:https://github.com/RediSearch/redisearch-py