如何在redis中表示product_id和product属性数据

时间:2018-04-30 18:58:23

标签: redis

我有多个产品的数据,Product_id:1和Product_attributes:Vitamin_A - > 200,维生素D - > 400 Product_id:2和Product_attributes:Vitamin_A - > 200,维生素D - > 400 .... 在Redis商店中存储这个的最佳方法是什么?我在考虑HMSET,但我不知道是否可以通过它访问每个单独的属性(例如Vitamin_A)?

1 个答案:

答案 0 :(得分:1)

Redis中的哈希是一个完美的用例。您可以抓取执行HGET product_id:1 Vitamin_A的哈希中的单个字段,或使用HGETALL product_id:1获取所有属性。看一下at the hash commands了解更多信息。