Redis
Installation
SKILL.md
Expiration (Memory Leaks)
- Keys without TTL live forever—set expiry on every cache key:
SET key value EX 3600 - Can't add TTL after SET without another command—use
SETEXorSET ... EX EXPIREresets on key update by default—SETremoves TTL; useSET ... KEEPTTL(Redis 6+)- Lazy expiration: expired keys removed on access—may consume memory until touched
SCANwith large database: expired keys still show until cleanup cycle runs
Data Structures I Underuse
- Sorted sets for rate limiting:
ZADD limits:{user} {now} {request_id}+ZREMRANGEBYSCOREfor sliding window - HyperLogLog for unique counts:
PFADD visitors {ip}uses 12KB for billions of uniques - Streams for queues:
XADD,XREAD,XACK—better than LIST for reliable queues - Hashes for objects:
HSET user:1 name "Alice" email "a@b.com"—more memory efficient than JSON string