JSON.NUMINCRBY - Amazon MemoryDB for Redis
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

JSON.NUMINCRBY

Increment the number values at the path by a given number.

Syntax

JSON.NUMINCRBY <key> <path> <number>
  • key (required) – Redis key of JSON document type

  • path (required) – a JSON path

  • number (required) – a number

Return

If the path is enhanced syntax:

  • Array of bulk Strings representing the resulting value at each path.

  • If a value is not a number, its corresponding return value is null.

  • WRONGTYPE error if the number cannot be parsed.

  • OVERFLOW error if the result is out of the range of 64-bit IEEE double.

  • NONEXISTENT if the document key does not exist.

If the path is restricted syntax:

  • Bulk String representing the resulting value.

  • If multiple values are selected, the command returns the result of the last updated value.

  • WRONGTYPE error if the value at the path is not a number.

  • WRONGTYPE error if the number cannot be parsed.

  • OVERFLOW error if the result is out of the range of 64-bit IEEE double.

  • NONEXISTENT if the document key does not exist.

Examples

Enhanced path syntax:

127.0.0.1:6379> JSON.SET k1 . '{"a":[], "b":[1], "c":[1,2], "d":[1,2,3]}' OK 127.0.0.1:6379> JSON.NUMINCRBY k1 $.d[*] 10 "[11,12,13]" 127.0.0.1:6379> JSON.GET k1 "{\"a\":[],\"b\":[1],\"c\":[1,2],\"d\":[11,12,13]}" 127.0.0.1:6379> JSON.SET k1 $ '{"a":[], "b":[1], "c":[1,2], "d":[1,2,3]}' OK 127.0.0.1:6379> JSON.NUMINCRBY k1 $.a[*] 1 "[]" 127.0.0.1:6379> JSON.NUMINCRBY k1 $.b[*] 1 "[2]" 127.0.0.1:6379> JSON.NUMINCRBY k1 $.c[*] 1 "[2,3]" 127.0.0.1:6379> JSON.NUMINCRBY k1 $.d[*] 1 "[2,3,4]" 127.0.0.1:6379> JSON.GET k1 "{\"a\":[],\"b\":[2],\"c\":[2,3],\"d\":[2,3,4]}" 127.0.0.1:6379> JSON.SET k2 $ '{"a":{}, "b":{"a":1}, "c":{"a":1, "b":2}, "d":{"a":1, "b":2, "c":3}}' OK 127.0.0.1:6379> JSON.NUMINCRBY k2 $.a.* 1 "[]" 127.0.0.1:6379> JSON.NUMINCRBY k2 $.b.* 1 "[2]" 127.0.0.1:6379> JSON.NUMINCRBY k2 $.c.* 1 "[2,3]" 127.0.0.1:6379> JSON.NUMINCRBY k2 $.d.* 1 "[2,3,4]" 127.0.0.1:6379> JSON.GET k2 "{\"a\":{},\"b\":{\"a\":2},\"c\":{\"a\":2,\"b\":3},\"d\":{\"a\":2,\"b\":3,\"c\":4}}" 127.0.0.1:6379> JSON.SET k3 $ '{"a":{"a":"a"}, "b":{"a":"a", "b":1}, "c":{"a":"a", "b":"b"}, "d":{"a":1, "b":"b", "c":3}}' OK 127.0.0.1:6379> JSON.NUMINCRBY k3 $.a.* 1 "[null]" 127.0.0.1:6379> JSON.NUMINCRBY k3 $.b.* 1 "[null,2]" 127.0.0.1:6379> JSON.NUMINCRBY k3 $.c.* 1 "[null,null]" 127.0.0.1:6379> JSON.NUMINCRBY k3 $.d.* 1 "[2,null,4]" 127.0.0.1:6379> JSON.GET k3 "{\"a\":{\"a\":\"a\"},\"b\":{\"a\":\"a\",\"b\":2},\"c\":{\"a\":\"a\",\"b\":\"b\"},\"d\":{\"a\":2,\"b\":\"b\",\"c\":4}}"

Restricted path syntax:

127.0.0.1:6379> JSON.SET k1 . '{"a":[], "b":[1], "c":[1,2], "d":[1,2,3]}' OK 127.0.0.1:6379> JSON.NUMINCRBY k1 .d[1] 10 "12" 127.0.0.1:6379> JSON.GET k1 "{\"a\":[],\"b\":[1],\"c\":[1,2],\"d\":[1,12,3]}" 127.0.0.1:6379> JSON.SET k1 . '{"a":[], "b":[1], "c":[1,2], "d":[1,2,3]}' OK 127.0.0.1:6379> JSON.NUMINCRBY k1 .a[*] 1 (error) NONEXISTENT JSON path does not exist 127.0.0.1:6379> JSON.NUMINCRBY k1 .b[*] 1 "2" 127.0.0.1:6379> JSON.GET k1 "{\"a\":[],\"b\":[2],\"c\":[1,2],\"d\":[1,2,3]}" 127.0.0.1:6379> JSON.NUMINCRBY k1 .c[*] 1 "3" 127.0.0.1:6379> JSON.GET k1 "{\"a\":[],\"b\":[2],\"c\":[2,3],\"d\":[1,2,3]}" 127.0.0.1:6379> JSON.NUMINCRBY k1 .d[*] 1 "4" 127.0.0.1:6379> JSON.GET k1 "{\"a\":[],\"b\":[2],\"c\":[2,3],\"d\":[2,3,4]}" 127.0.0.1:6379> JSON.SET k2 . '{"a":{}, "b":{"a":1}, "c":{"a":1, "b":2}, "d":{"a":1, "b":2, "c":3}}' OK 127.0.0.1:6379> JSON.NUMINCRBY k2 .a.* 1 (error) NONEXISTENT JSON path does not exist 127.0.0.1:6379> JSON.NUMINCRBY k2 .b.* 1 "2" 127.0.0.1:6379> JSON.GET k2 "{\"a\":{},\"b\":{\"a\":2},\"c\":{\"a\":1,\"b\":2},\"d\":{\"a\":1,\"b\":2,\"c\":3}}" 127.0.0.1:6379> JSON.NUMINCRBY k2 .c.* 1 "3" 127.0.0.1:6379> JSON.GET k2 "{\"a\":{},\"b\":{\"a\":2},\"c\":{\"a\":2,\"b\":3},\"d\":{\"a\":1,\"b\":2,\"c\":3}}" 127.0.0.1:6379> JSON.NUMINCRBY k2 .d.* 1 "4" 127.0.0.1:6379> JSON.GET k2 "{\"a\":{},\"b\":{\"a\":2},\"c\":{\"a\":2,\"b\":3},\"d\":{\"a\":2,\"b\":3,\"c\":4}}" 127.0.0.1:6379> JSON.SET k3 . '{"a":{"a":"a"}, "b":{"a":"a", "b":1}, "c":{"a":"a", "b":"b"}, "d":{"a":1, "b":"b", "c":3}}' OK 127.0.0.1:6379> JSON.NUMINCRBY k3 .a.* 1 (error) WRONGTYPE JSON element is not a number 127.0.0.1:6379> JSON.NUMINCRBY k3 .b.* 1 "2" 127.0.0.1:6379> JSON.NUMINCRBY k3 .c.* 1 (error) WRONGTYPE JSON element is not a number 127.0.0.1:6379> JSON.NUMINCRBY k3 .d.* 1 "4"