Redis is in-memory data structure server.
Strings¶
SET user:1:name 'John'
GET user:1:name
INCR page:views
SETEX session:abc 3600 '{...}'
Hashes¶
HSET user:1 name 'John' email 'john@ex.com'
HGETALL user:1
Lists¶
LPUSH queue:tasks '{...}'
RPOP queue:tasks
Sorted Sets¶
ZADD leaderboard 1000 'player1' 950 'player2'
ZREVRANGE leaderboard 0 9 WITHSCORES
HyperLogLog¶
PFADD visitors 'u1' 'u2' 'u3'
PFCOUNT visitors
Practical Usage Patterns¶
Each Redis data structure has specific use cases. Strings with TTL (SETEX) are the foundation for session management and caching. Hashes efficiently store objects — one hash per user profile instead of dozens of string keys. Lists function as FIFO queues for task processing (LPUSH + BRPOP).
Sorted Sets are Redis’s most unique structure — they enable sorted collections with O(log N) operations. Typical uses include leaderboards, rate limiting (sliding window), priority queues, and time-based indexes. HyperLogLog is a probabilistic structure for counting unique elements with constant memory (~12 KB) and a maximum error of 0.81%. It is ideal for counting unique visitors or distinct values in streams.
Redis = Powerful Structures¶
Strings=cache, Hashes=objects, Lists=queues, ZSets=leaderboards.