How to model compound keys (or tuples) in Redis to ease getting one value knowing the other

270 Views Asked by At

I have a key containing an array of IDs like:

glid-ids -> 
1 625f15db2ea61be36f694b73
2 625f15db2ea61be36f694b76
3 625f15db2ea61be36f694b78
4 ...

But I want to associate each ID with a parent (think of it like a category, knowing a category generally has multiple IDs, but one ID could have few categories too. Like the following (if I had to store tuples, or compound keys like the following):

glid-ids -> 
1 625f15db2ea61be36f694b73, gls-20-9
2 625f15db2ea61be36f694b76, gls-10-3
3 625f15db2ea61be36f694b78, gls-20-5
4 ...
5 625f15db2ea61be36f694b73, gls-10-3

625f15db2ea61be36f694b73 parent categories are gls-20-9 and gls-10-3.

The question is how to store this, to later be able to search quickly for all categories (gls-...) of a particular ID.

(I am very new to Redis and I'm using ioredis, but any hints regardless in JS or not is welcome !)

0

There are 0 best solutions below