Alternative to JSON.MERGE command

170 views Asked by At

We are using ElasticCache with Redis. As of requirement, we want to merge new JSON string (contain single/multiple new member(s)) into a redis cached JSON string.

For example:

Cached JSON in Redis:--------
{
    "nm": null,
    “Count”: 10,
    "srvData": {}
}

JSON String to Merge:---------

{
    “srvData”: {
        “bsc”: 10000,
        “blk”: {
              “pps”:   {
                         “players”: [30]
                 },
               “c”: 32
         }
     }
}

Expectation:-----------

{
    "nm": null,
    “Count”: 10,
    “srvData”: {
        “bsc”: 10000,
        “blk: {
              “pps”:   {
                         “players”: [30]
                 },
               “c”: 32
         }
     }
} 

As per """"https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/json-list-commands.html """" page, AWS ElasticCache doesn’t support JSON.Merge command. Although, JSON.Merge is supported by Redis.IO.

Is there anything else, we can use?

We have tried JSON.SET with option “NX” but it isn’t a solution. JSON.SET replaces the whole cached JSON string with new JSON string.

The other performance killer option would be to

  1. JSON.GET the entire JSON,
  2. perform merge operation in LUA (programmatically), and
  3. JSON.SET back to ElasticCache. which we want to avoid.
0

There are 0 answers