Node.js › Caching with Redis

What Redis data structures beyond simple string values are useful for a Node.js application, and what are they typically used for?

Intermediate

Answer

Beyond simple key-value strings, Redis supports Hashes (field-value maps within a single key, efficient for representing an object like a user profile), Lists (ordered collections, useful for simple queues via LPUSH/RPOP), Sets (unordered unique collections, useful for tracking things like unique online user IDs), Sorted Sets (unique members each with a score, ideal for leaderboards or rate-limiting windows), and Streams (an append-only log, useful for simple event/message processing).
// Hash: representing a user profile efficiently
await client.hSet('user:123', { name: 'Alice', email: 'alice@example.com' });
const name = await client.hGet('user:123', 'name');

// Sorted set: a leaderboard
await client.zAdd('leaderboard', { score: 4500, value: 'user:123' });
const top10 = await client.zRangeWithScores('leaderboard', 0, 9, { REV: true });
Real-world example A gaming platform uses a Redis Sorted Set to maintain a real-time leaderboard, letting it efficiently query 'top 10 players' or 'this player's current rank' with a single fast command, rather than repeatedly sorting a large dataset from a traditional database.

Common follow-ups: What's the time complexity of common Sorted Set operations, and why does that matter for a real-time leaderboard at scale?;How would you implement a simple sliding-window rate limiter using a Sorted Set?