-
Redis key is:
- a unique identifier (string) that points to a value in Redis.
- Redis is best thought of as:
key -> typed value(string/hash/list/set/zset/stream…).
-
The key naming pattern
- Standard format
namespace:entity:id[:subtype][:dimension...]- Example
qa:v1:{docId}:{questionHash},user:{userId}:session,rank:doc:{docId}
- Rules
- Use namespaces (
qa:,user:,rank:,idx:,ratelimit:,lock:). - Use colons
:to separate segments. - Put high-cardinality parts last (hash/uuid/timestamp).
- Don’t put raw user input in keys → normalize + hash.
- Add a version when logic may change (
v1,v2).
- Use namespaces (
- Example
- Standard format
-
Keys and data types (type safety)
- A key has one type forever until deleted.
-
TTL and expiration
- TTL controls how long a key lives.
-
Delete keys safely
- use iterative
SCAN 0 MATCH qa:* COUNT 1000(iterative, safer)
- use iterative
-
Key design for your Doc QA cache