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
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response