About this chapter
Redis is, at its core, a giant dictionary of keys and values. In this chapter you will learn how that model works, how to name your keys so you can find them later, and how to make a key expire on its own - the trick that turns Redis into a cache.
Lessons from courses
- 1 Keys and values Learn the Redis SET and GET commands: how storing and reading works, what overwriting a key does, and why every Redis key is just a string.
- 2 Key naming conventions Name Redis keys with colon namespaces like user:42:profile. Learn the convention that keeps keys searchable, groupable, and easy to invalidate.
- 3 Expiration and TTL Set Redis key expiration so keys delete themselves with EXPIRE, SETEX and SET EX. Read a key's TTL and remove expiry with PERSIST - the basis of caching.
- 4 Deleting and checking keys Delete Redis keys with DEL, check them with EXISTS, rename with RENAME, and learn why KEYS can freeze a production server - use SCAN instead.
- 5 Atomic counters Build race-free Redis atomic counters with INCR, DECR, INCRBY and DECRBY. Count page views safely under load and combine counters with EXPIRE.