【发布时间】:2022-01-14 07:40:19
【问题描述】:
我正在考虑使用 redis 的批量插入功能。虽然没有找到任何这样做的参考。
是否有解决方法可以将redis mass insert 与RedisJson 一起使用?
【问题讨论】:
我正在考虑使用 redis 的批量插入功能。虽然没有找到任何这样做的参考。
是否有解决方法可以将redis mass insert 与RedisJson 一起使用?
【问题讨论】:
这可以像标准批量插入一样通过 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 管道,example 位于驱动程序的文档脚本中。
我通常会这样做:
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()
【讨论】:
JSON.SET foo . '{"bar": "baz"}' 虽然 json 无效..