2

我正在考虑使用redis的批量插入功能。虽然没有找到任何参考这样做。

是否有解决方法可以将redis mass insertRedisJson一起使用?

4

1 回答 1

1

这可以像标准批量插入一样通过 redis-cli 完成

$ cat data.txt 
JSON.SET foo . '{"bar": "baz"}'
JSON.SET yo . '{"bar": "biz"}'

$ cat data.txt  | redis-cli --pipe
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 2

$ redis-cli JSON.GET yo
"{\"bar\":\"biz\"}"

如果您希望通过 python 执行此操作,请使用 Redis 管道,驱动程序的文档脚本上有一个示例。

我通常会做类似的事情:

rj = Client(host='localhost', port=6379, decode_responses=True)
pipe = rj.pipeline()

row_count = 0 
for x in mydata:
    pipe.jsonset(x[0], Path('.cost'), x[1])
    row_count += 1
    if row_count % 500 == 0:
        pipe.execute()

pipe.execute()

于 2021-12-09T16:52:03.420 回答