advancedTop 30 Scenario-Based Questions
Design an e-commerce cart using Redis that persists across sessions.
Redis Hash per cart: 1) Cart structure: HSET cart:{userId} {productId} {quantity}. Example: HSET cart:42 prod:100 2 prod:200 1. 2) Add item: HINCRBY cart:{userId} {productId} 1. 3) Remove item: HDEL cart:{userId} {productId}. 4) Get cart: HGETALL cart:{userId} → {prod:100:2, prod:200:1}. 5) Total items: HLEN cart:{userId}. 6) TTL: EXPIRE cart:{userId} 604800 (7 days). 7) Persistence: AOF ensures c
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.
Design an e-commerce cart using Redis that persists across sessions.