0

Goal: make a table with composite with Redis database.

I have data stored in JSON in this format:

{
        "customer_id" : "C001",
        "order_id" : "O789",
        "product_code": "P007",
        "quantity": 1000,
}

My composite key would be customer_id and product_code. I tried to implement this in Redis-CLI with this Composite Primary Key equivalent in Redis

However, I am a bit lost how to use this in Python. Should I use ZADD() or something else?

1 Answers1

0

ZADD is used to add an entry (score/member) to a sorted set. You dont want to use a sorted set because there are no common score among productcode / quantity. You could use one if for example you wanted to store all orders of a client, storing orderid and their timestamps, making it easier to retrieve.

I think you should use a hash, this data structure is nice to hold keys/values inside a key. You could do :

HMSET C001:O789 product_code P007 quantity 1000

And get them :

HGET C001:O789 product_code //p007
HGET C001:O789 quantity //1000
HGETALL C001:O789 // p007, 1000
JeanJacquesGourdin
  • 1,496
  • 5
  • 25