Redis Data Types Cheat Sheet

High-value Redis commands for lists, sets, hashes, and sorted sets used in queues, objects, tags, and leaderboards.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Lists
Push to head of list
LPUSH jobs pending-1 pending-2

# Insert one or more elements at the head.

Push to tail of list
RPUSH jobs pending-1 pending-2

# Insert one or more elements at the tail.

Pop from head
LPOP jobs

# Remove and return the first element.

Pop from tail
RPOP jobs

# Remove and return the last element.

Blocking pop from one or more lists
BLPOP jobs urgent:jobs 30

# Wait up to 30 seconds for a new element.

Blocking pop from tail
BRPOP jobs 30

# Block until an element is available at the tail.

List length
LLEN jobs

# Return the number of elements in a list.

Read a slice of a list
LRANGE jobs 0 9

# Get a range of list elements.

Read one element by index
LINDEX jobs 0

# Return a list element by zero-based index.

Overwrite a list element
LSET jobs 0 urgent-1

# Replace an element at a specific index.

Trim a list to a window
LTRIM jobs 0 99

# Keep only a selected range of elements.

Remove matching elements
LREM jobs 0 duplicate-job

# Remove occurrences of a value.

Move from one list to another
RPOPLPUSH source processing

# Atomically move an item between lists.

Move between lists with direction control
LMOVE source destination RIGHT LEFT

# Generalized replacement for RPOPLPUSH.

Blocking LMOVE
BLMOVE source destination RIGHT LEFT 30

# Block until an element can be moved between lists.

Find index of a list element
LPOS jobs urgent-1

# Find the first index of a matching element.

## Sets
Add members to a set
SADD tags:post:1 redis cache database

# Insert unique set members.

Remove members from a set
SREM tags:post:1 cache

# Remove members from a set.

List all members
SMEMBERS tags:post:1

# Return every member of a set.

Get set size
SCARD tags:post:1

# Return the number of unique members.

Check membership
SISMEMBER tags:post:1 redis

# Return whether a member exists in the set.

Check multiple memberships
SMISMEMBER tags:post:1 redis cache nosql

# Test several possible members at once.

Pop random members
SPOP queue:set 2

# Remove and return random set members.

Read random members
SRANDMEMBER queue:set 3

# Return random members without removing them.

Move member between sets
SMOVE online-users offline-users user:1

# Move a member atomically.

Union sets
SUNION set:a set:b

# Return members from either set.

Intersect sets
SINTER set:a set:b

# Return members common to all sets.

Difference of sets
SDIFF set:a set:b

# Return members in the first set but not others.

Store union result
SUNIONSTORE result:set set:a set:b

# Write the union into a destination set.

Store intersection result
SINTERSTORE result:set set:a set:b

# Write the intersection into a destination set.

Store difference result
SDIFFSTORE result:set set:a set:b

# Write the difference into a destination set.

Incrementally scan a set
SSCAN tags:post:1 0 MATCH re* COUNT 100

# Cursor-based iteration over large sets.

## Hashes
Set one or more hash fields
HSET user:1 name Alice email alice@example.com

# Create or update hash fields.

Get one hash field
HGET user:1 name

# Read one field from a hash.

Get multiple fields
HMGET user:1 name email

# Read several fields in one call.

Get all fields and values
HGETALL user:1

# Read the full hash.

List field names
HKEYS user:1

# Return all field names in a hash.

List field values
HVALS user:1

# Return all values in a hash.

Count fields
HLEN user:1

# Return how many fields exist.

Check whether a field exists
HEXISTS user:1 email

# Return 1 if the field exists.

Delete fields
HDEL user:1 email phone

# Delete one or more fields.

Increment integer field
HINCRBY counters:api hits 1

# Atomically increment a numeric field.

Increment float field
HINCRBYFLOAT account:1 balance 9.99

# Atomically increment a float field.

Set a field only if absent
HSETNX user:1 created_at 2026-03-06

# Write a field only if it does not exist.

Get random fields
HRANDFIELD user:1 2 WITHVALUES

# Sample random fields from a hash.

Incrementally scan a hash
HSCAN user:1 0 MATCH meta:* COUNT 100

# Cursor-based iteration over hash fields.

Get field value length
HSTRLEN user:1 name

# Return the string length of a field value.

## Sorted sets
Add scored members
ZADD leaderboard 100 alice 95 bob

# Insert or update sorted-set scores.

Get a member score
ZSCORE leaderboard alice

# Read a member's numeric score.

Increment member score
ZINCRBY leaderboard 10 alice

# Add to a member's score.

Read by rank
ZRANGE leaderboard 0 9 WITHSCORES

# Get members by ascending rank.

Read highest-ranked members
ZREVRANGE leaderboard 0 9 WITHSCORES

# Get members by descending rank.

Read by score interval
ZRANGEBYSCORE leaderboard 90 100 WITHSCORES

# Get members in a score range.

Read by score descending
ZREVRANGEBYSCORE leaderboard +inf 90 WITHSCORES

# Get members by descending score interval.

Find ascending rank
ZRANK leaderboard alice

# Return zero-based ascending rank.

Find descending rank
ZREVRANK leaderboard alice

# Return zero-based descending rank.

Remove members
ZREM leaderboard bob

# Delete members from a sorted set.

Trim by rank
ZREMRANGEBYRANK leaderboard 0 -101

# Remove all but top 100 members.

Trim by score
ZREMRANGEBYSCORE leaderboard -inf 49

# Remove low-scoring members.

Count members in score range
ZCOUNT leaderboard 80 100

# Count how many members fall within a score range.

Count all members
ZCARD leaderboard

# Return sorted-set cardinality.

Store union of sorted sets
ZUNIONSTORE combined 2 board:daily board:weekly

# Combine multiple sorted sets into a destination key.

Store intersection of sorted sets
ZINTERSTORE common 2 board:a board:b

# Intersect sorted sets into a destination key.

Incrementally scan a sorted set
ZSCAN leaderboard 0 MATCH a* COUNT 100

# Cursor-based scan over zset members and scores.

Recommended next

No recommendations yet.