node.jsjsonredisredisjson

RedisJSON add TTL on specific Value in JSON Object


Hey working with redisJSON NodeJS package npm Redis 4.3.1

Key (userID):(Country) with values Json

Example

data = { "info": { "name":"test", "email": "test@test,test" }, "suppliers": { "s1": 1, "s2": 22 }, "suppliersCap": { "s1": 0, "s2": 10 } }

redis.json.set('22:AU', '.', data);

now I try to add TTL for 5 minutes on the specific key in the JSON for example on this key

22:AU .data.suppliersCap.s2, after 5 minutes the cap will be 0;

bit this not works

redis.json.set(22:AU, '.data.suppliersCap.s2', { EX: 300 });


Solution

  • NX and XX are the only valid modifiers for the command:

    redisClient.json.set(
      key: string, 
      path: string, 
      json: RedisJSON, 
      options?: NX | XX | undefined
    ): Promise<"OK" | null>
    

    enter image description here