Redis as a cache stores data temporarily to speed up access to frequently used information, reducing the need to fetch from slower databases.
Redis uses its Pub/Sub feature to send messages between clients, enabling it to work as a message broker.
SET user:1 "Alice" EX 10
TTL user:1
SET user:1 "Alice" EX 10 TTL user:1
The SET command with EX 10 sets the key to expire in 10 seconds. TTL returns the remaining time to live, which is 10 seconds immediately after setting.
The PUBLISH command syntax is: PUBLISH channel message. Quotes are not needed unless the client requires them, but Redis CLI accepts unquoted simple strings.
Using Redis as a primary data store fits scenarios needing fast, reliable access to data that cannot be lost, like real-time leaderboards.
