【问题标题】:Redis Python execute_command RedisearchRedis Python execute_command Redisearch
【发布时间】:2021-07-23 17:06:20
【问题描述】:

我正在使用 python 3.6 来在 redis 服务器上添加一些文档!所以我使用命令:execute_command 和模块 Redis。

在我的示例中,我想将元数据添加到重新搜索文档中:

c = 'FT.ADD idx doc 1 REPLACE FIELDS parameter'  + ' ' + a 

r.execute_command(c)

a 是一个 str 数据。 所以我想在文档文档中添加参数:a。其中“a”是文本。

但是当'str a'中有空格时,执行_command认为它是下一个参数,即使我在每一边都加上引号("')...

例如:如果a = '"Test Test"',我会在redis服务器上找到"\"Test" ...

我该如何处理?

感谢您的帮助。

【问题讨论】:

  • 你试过r.execute_command(['FT.ADD','idx','doc',1,'REPLACE','FIELDS', 'parameter',a]吗?
  • 当我使用它时出现此错误:DataError: Invalid input of type: 'list'。先转换为字节、字符串或数字。

标签: python redis redisearch


【解决方案1】:

试试这个:

r.execute_command('FT.ADD', 'idx', 'doc', 1, 'REPLACE', 'FIELDS', 'parameter', 'a');

【讨论】:

    猜你喜欢
    • 2020-12-26
    • 2023-01-13
    • 2022-11-25
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 2019-03-17
    • 1970-01-01
    相关资源
    最近更新 更多