Replacing a JSON key

54 views
Skip to first unread message

Luveh Keraph

unread,
Oct 28, 2023, 12:52:19 PM10/28/23
to redi...@googlegroups.com
I have a JSON key which I loaded into Redis by means of

redis-cli -x JSON.SET MyKey $ < DataFile.json

Later on, and using the same mechanism I loaded another JSON data file as a key named NewKey.
This new JSON data file is structured the same as the original one, with some of the fields in the new JSON data file having different values.

What I would like is for MyKey to end up pointing to the JSON data that has been uploaded as NewKey. That is,  when at the Redis CLI I do 

JSON.GET MyKey $
JSON.GET NewKey $

I get different things, for the data used to set MyKey was different from the data used to set NewKey. What I am asking is whether there is a Redis/JSON command such that, after it has been issued, the two JSON.GET commands above will print out exactly the same data, with the data originally assigned to MyKey presumably being lost in the process. 

Can this be done? One can obviously modify individual fields in MyKey with new values, as obtained from NewKey, but I wonder whether Redis/JSON provides a more powerful approach to do what I am asking.

Anshul Sharma

unread,
Oct 28, 2023, 2:02:45 PM10/28/23
to redi...@googlegroups.com
As I understand your requirement you want to get same data from get operation of both keys, but that does not make sense why do you want to do to that, if you want to get same data then why are you inserting it in 2 different keys, just use one key and override again and again.

Please correct me if I my understanding is wrong.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/redis-db/CAFy1yb0yDXzyh0aRH49JUOmPeo%3De-wg-odF9VKvt_B5xmhTNzQ%40mail.gmail.com.

Luveh Keraph

unread,
Oct 28, 2023, 2:51:43 PM10/28/23
to redi...@googlegroups.com
Your comment has made me realize that I can probably just do redis-cli -x JSON.SET MyKey $ < NewDataFile.json in order to achieve what I want.  I have tested this and that is indeed the way it works. Thanks - although you did not answer my question directly, you forced me to rethink my problem and so find the answer that I was looking for.

Reply all
Reply to author
Forward
0 new messages