An overview of the
The general data structure in Redis is sufficient. For example, the commonly used string and hash can cover common scenarios, and the complexity of data read and write time is O(1). Because they’re all key value structures. But not when it comes to range lookups and sorts, which are a bit like database operations and a bit like indexing. Sorted Set is a data structure similar to binary tree indexes. It has a time complexity of O(LogN).
Data structure diagram
Redis overall structure diagram
The entry structure
Skiplist structure
1.Sorted Set is also a collection, with two underlying data structures, compressed lists and hoptables, as opposed to strings2.Skiplist acts as an index so that index-related operations such as sorting and range queries can be used.3.Skiplist time complexity is higher than hash String time complexity O(LogN)Copy the code
Usage scenarios
1.For simple key value operations, you are advised to use hash and string, which have low time complexity2.If you want to sort, range lookup. For example, like, comment, ranking, it is recommended to use Sorted SetCopy the code