Search code examples
redisredisjson

How to get a range of elements from an array in Redisjson?


I have a simple array as such :

[1,2,3,4,5]

and I wish to get a range for example from index 2 to index 4. I can get the last element of the array by :

json.get key .[-1]

However I cannot find anyway to return a specific results without trimming the array.

Is there anyway I can get a range of elements from a Redis json array?


Solution

  • The answer is :

    await Client.json.get("key" , {path : '$.[1:3]'})
    

    which gets index 1 to 3.