![]() |
Sorted sets are sets with some additional functionalities that is they can be sorted in some ways, allowing more control over the data that is stored in sets. Sorted sets maintain an ordered collection of unique elements, associated with scores (unique no). Some of the best use cases of it are making a leaderboard, ranking systems, etc. Its actual Data structure is a combination of a list and hash table having characteristics of both sets and sorted lists. These sorted sets contain a unique score that allows the elements to be sorted in ascending or descending order. Syntax and Commands of Redis Sorted Sets1. “zadd” command:Makes a sorted set, and adds elements to it
Output: 2. “zrange” command:Shows the elements present in sorted set according to the range you specify
Output: 3. “zrange” command (zrange command with Core no.):
Output: 4. “zcard” command:Shows length of sorted set
Output: 5. “zcount” command: Counts no of elements
Output: 6. “zcount” command (Counts elements with their core no.):
Output: 7. “zrem” command:Removes an element from the set
Output: 8. “zrevrange” command: Reverses the elements in the set
Output: 9. “zscore” command: Returns Core no. of a particular element present in that set
Output: 10. “zrevrangebyscore” command: Reverses the list by core no.
Output: 11. “zremrangebyscore” command:Removes the elements from set in particular Core no. range
Output: 12. “zremrangebyrank” command: Removes the elements by their index/rank
Output: Performance of Sorted Sets in Redis:Time Complexity of Sorted Sets operations is generally O(log(N)), where N is the number of members, but be careful while using the ZRANGE command with large number of return values because the time complexity of this command is O(log(N) + M), where M is the number of results returned by the command |
Reffered: https://www.geeksforgeeks.org
System Design |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |