In DynamoDB I use a composite key to model the one-to-many relationship in a table:
User (Key) - Order (Range)
A typical set of records there is like:
John - Burger
John - Fries
Sue - Pizza
Sue - Soda
Looks like Redis only supports primary keys in which case this won't work because primary keys are unique. Is there a way to implement the above in Redis?
Redis supports two different data types which you can use to model your one-to-many relationship:
To some extents, one could even use Redis lists , which are linked lists of string values.
Is there a way to implement the above in Redis?
Yes and it depends on how you are going to use that relationship. Here is how you can do that with Redis sets, for example:
SADD users:John Burger Fries
> 2
SADD users:Sue Pizza Soda
> 2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.