How it works...
First, we create a Lua script updatejson.lua. In the Lua script, KEY and ARGV are arguments for the EVAL command. At the beginning of this script, we get one KEY as the key that we'd like to process and one ARGV as the content that we'd like to update for the JSON string. After that, the JSON content passed into the script is deserialized.
Then, we retrieve the value of the specified key by calling the GET command using the redis.call() function, and then we look at the value returned by the GET command. If the value is false, which indicates the key doesn't exist, we set it as an empty table. Otherwise, we can decode the value as a JSON string.
Then, we start iterating the data to set the key and value in the retJson variable. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access