Redis Sorted Set (ZSET) Management Guide
What Will You Learn in This Guide?
In this guide, you will learn the Redis Sorted Set data type.
You will sort and filter the data by their scores.
You will create new data sets by combining multiple clusters.
🧠 Technical Summary
Main topic: Redis Sorted Set (ZSET) management.
Solved problem: Point-based sequential and unique data storage.
Steps followed: Adding, listing, analyzing, deleting and merging data.
1. Creating an Ordered Set and Adding Elements
In the Sorted Set, each element is stored with a score.
Elements are unique, points can be shared.
Adding a Single Element
ZADD gitarist_listesi 1 "Joe Pass"
- This command creates a new ZSET or adds elements to an existing set.
Adding Multiple Elements
ZADD gitarist_listesi 4 "Stephen" 2 "Rosetta" 3 "Bola" 8 "Elizabeth"
- Points do not have to be consecutive.
Increase Element Points
ZINCRBY gitarist_listesi 5 "Stephen"
- If there is no element, it is added automatically.
2. Listing and Filtering Data
Sort Ascending
ZRANGE gitarist_listesi 0 3
- Sorts from low score to high.
Listing with Points
ZRANGE gitarist_listesi 0 -1 WITHSCORES
- Brings all elements with their scores.
Reverse Sort
ZREVRANGE gitarist_listesi 0 2
- Lists the highest scoring elements.
Filter by Score Range
ZRANGEBYSCORE gitarist_listesi 2 4
- The use of parentheses excludes outliers.
3. Getting Information About the Cluster
Total Number of Elements
ZCARD gitarist_listesi
- Returns the size of the cluster.
Element Order
ZRANK gitarist_listesi "Joe Pass"
- Sorting starts from 0.
Element Points
ZSCORE gitarist_listesi "Bola"
- If there is no element, nil is returned.
4. Element Deletions
- Deleting a Single Element
ZREM gitarist_listesi "Bola"
- Removes the specified element completely.
- Deletion by Score Range
ZREMRANGEBYSCORE gitarist_listesi 4 6
- Deletes elements within a certain score range.
Delete by Order
ZREMRANGEBYRANK gitarist_listesi 0 2
- Removes lowest order elements.
5. Merge Sets and Get Intersections
Union (UNION)
ZUNIONSTORE yeni_grup 2 liste1 liste2
- Creates a non-repetitive combination.
Intersection (INTERSECTION)
ZINTERSTORE ortak_grup 2 liste1 liste2
- Retrieves only common elements.
❓ Frequently Asked Questions (FAQ)
1. How are elements with the same score sorted? In alphabetical (lexicographic) order.
2. Can points be decimal? Yes, float values are supported.
3. What happens if an element is added again? Its current score is updated.
4. What does index -1 mean? It represents the last element of the set.
🎯 Result
With this guide, you have used the Redis Sorted Set structure effectively. You have sorted and analyzed the scored data. You've done advanced filtering and merging.
You can immediately try these ZSET structures on high-performance Redis servers on the GenixNode infrastructure.

