Hi,
what is the correct way to store a Json document and prevent duplicates?
doc = { “hash” : “fc02971b2415481499f7b5e376f4f582”, “abc”: “xyz” }
The “hash” value identifies the Json docs.
I’m uncertain how to to prevent storing the same Json doc multiple times.
I guess something like:
with r.pipeline() as pipe:
while True:
try:
pipe.watch("article:index")
id = int(pipe.incr("article:index"))
if r.ft().search(Query("fc02971b2415481499f7b5e376f4f582").return_field("$.hash", as_field="hash")).docs:
pipe.unwatch()
break
pipe.multi()
pipe.json().set(f"article:{id}", Path.root_path(), dict(doc))
pipe.execute()
except WatchError:
pass
Or should I use “hash” as key:
id = f"article:{hash}"
What is the preferred way to store Json docs and prevent duplicates?