Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Redis Overview

Data Structures

TypeUse CaseExample
StringCache, counter, sessionSET user:1 '{"name":"Alice"}'
ListQueue, recent itemsLPUSH queue task1
SetTags, unique itemsSADD tags python web
Sorted SetLeaderboard, rankingZADD leaderboard 100 alice
HashObject fieldsHSET user:1 name Alice age 30
StreamEvent log, messagingXADD events * type click page /home
HyperLogLogCardinality estimationPFADD visitors user1 user2
BitmapFeature flags, bitfieldsSETBIT flags:1 0 1

Key Commands

# Strings
SET key value [EX 3600]     # Set with TTL
GET key
INCR counter                # Atomic increment
MGET key1 key2              # Multi-get

# Lists
LPUSH queue item            # Push to head
RPOP queue                  # Pop from tail (queue behavior)
LRANGE queue 0 -1           # Get all

# Sets
SADD myset member1
SISMEMBER myset member1
SINTER set1 set2            # Intersection
SUNION set1 set2            # Union

# Sorted Sets
ZADD leaderboard 100 alice
ZRANGE leaderboard 0 -1 WITHSCORES
ZRANK leaderboard alice     # Position

# Hashes
HSET user:1 name Alice age 30
HGET user:1 name
HGETALL user:1

# Streams
XADD events * type click page /home
XREAD COUNT 10 STREAMS events 0

References