SORTEDSET data Structures SortedSet and set types are very similar, and they are all collections of strings that do not allow duplicate members to appear in a set collection. The main difference between them is that each member of the SortedSet will have a fraction (score) associated with it, and Redis is the sort of the large to the small for the members of the set by the score. However, it is important to note that although the members of the SortedSet must be unique, the scores are repeatable. Adding, deleting, or updating a member in SortedSet is a very quick operation. Its time complexity is the logarithm of the number of members in the collection. Because the members in the SortedSet are in an orderly position in the collection. Therefore, even accessing the members in the middle of the collection is still very efficient.
Application scenarios: Game Rankings, microblogging topics such as the use of the scene
Frequently used commands add elements zadd key score1 member1 score2 member2. . The scores of all members and the members are stored in the SortedSet. If the element already exists, the score is replaced with the original score, and the returned value is the number of elements that are added to the collection, and does not contain the previously existing elements.
Gets the element Zscore key member gets the fraction of the specified members
Zcard Key gets the number of members in the collection
Delete element Zrem key Member1 member2 ... . To remove a specified member from a collection, you can specify more than one member
The range query Zrange key start [withscores] Gets the member in the collection that is labeled Stert to end, and the member returned by the [Withscore] parameter table name contains its score.
Zrevrange key start stop [withscores] returns all of the elements from start to stop in the order of element fractions from big to small, containing the elements at both ends, and the member returned by the [Withscore] parameter table name contains its score.
Zremrangebyrank key start stop deletes elements by ranking range
Zremrangebyscore key start stop deletes elements by fraction range
Zrangebyscore key min Max [withscores] [limit offset count] returns the fraction of members in [Min,max] and sorts by fractions from low to high. [Withscores] indicates that the score is displayed, and the ofsfet in [limit offset count] represents the beginning of the element with the subscript offset and returns the Count member.
Zincrby Key increment member sets the increased fraction of the specified members, and the return value is the changed score
Zcount Key min Max gets the fraction of the members between [Min,max]
Zrank Key member returns the number of members in the collection from small to large Zrevrank key member from large to small returns the ranking of members in the collection
Working with scenes
Keys general operation keys pattern gets all field pattern matching key,* represents any one or more fields. Represents a character, keys * keys my* keys?? List keys my???
Del key1 Key2 ... Deletes the specified key
Exists key to determine if the key exists, 1 represents the presence, and 0 does not exist
Rename key Newkey to rename the current key
Expire key sets the expiration time, the unit is the second TTL key to get the timeout of the key, if no timeout is set, return-1, if return-2 means timeout does not exist
Type key gets the type of the specified key, which is returned in the form of a string, string, Lsit, set, hash, Zset. Returns none if key does not exist.