Imagine you store user data in Redis. Why should you use a consistent naming pattern for keys?
Think about how you find things in a messy room versus a tidy one.
Consistent key naming helps prevent accidentally overwriting data and makes it easier to retrieve related data by pattern matching keys.
Given these keys in Redis: 'user:1:name', 'user:2:name', 'session:1', 'user:1:email', what does the command KEYS user:1:* return?
The asterisk (*) matches any characters after 'user:1:'.
The pattern 'user:1:*' matches keys starting exactly with 'user:1:' followed by anything, so it returns keys for user 1 only.
Which option shows a Redis command with a syntax error?
Command: SET user:100 name 'Alice'
Remember the SET command syntax: SET key value
The SET command expects exactly two arguments: a key and a value. Option C has three arguments, which is invalid syntax.
You want to store session data for millions of users. Which key design is best to reduce memory usage?
Think about key length and data structure efficiency.
Short keys reduce memory overhead. Using hashes groups related fields under one key, saving space compared to many separate keys.
You set a key with SET user:123:name 'Bob' EX 3600. Later, you run DEL user:123:name and then SET user:123:name 'Bob' without expiration. But the key still expires after 1 hour. Why?
Check how Redis handles expiration when overwriting keys.
When you overwrite a key with SET without expiration, Redis removes the old TTL. But if you use commands like SETNX or certain scripts, TTL may persist. Here, DEL removes the key, so the new SET should not have TTL. The issue is likely the DEL did not succeed or was not executed properly.