1.ZADD
Syntax: Zadd key Scroe
Member
Description: The time complexity of the operation is O (log (n)), where N is the number of elements in an ordered set. Adds an element with the specified Scroe to the ordered set corresponding to the key. If an element already exists in an ordered collection, the score of that element will be updated, and the elements will be reseated to the correct bit values to ensure the correct order. If the specified key does not exist, a new ordered collection with the unique element of member will be created. If the key exists, but its corresponding value is not an ordered collection, an error occurs. The Scroe value specified in the command should be a string that can be converted to a numeric value, and a double-precision floating-point type is accepted.
Return value: If the element is added, the return value is 1; If the element is already a member of an ordered collection and Scroe is updated, then the return value is 0.
This command is available since version 1.1.
2.ZCARD
Syntax: Zcard
Key
Description: The time complexity of the operation is O (1). Returns the number of elements stored in the ordered set corresponding to the key.
Return value: Returns the number of elements in an ordered set, and if key does not exist, the return value is 0.
This command is available since version 1.1.
3.ZCOUNT
Syntax: Zcount
Key min
Max
Description: The time complexity of the operation is O (log (N) +m), where N is the number of elements, and M is the number of elements between Min and Max. Returns the number of elements between Min and Max that the ordered set of keys corresponds to.
Return value: Returns the number of elements within the specified Scroe range.
This command is available from the 1.3.3 version.
4.ZINCRBY
Syntax: Zincrby
Key increment
Member
Note: The time complexity of the operation is O (Long (n)), where N is the number of elements in an ordered set. Scroe of the member element in the ordered set corresponding to the key plus increment. If the specified member does not exist, the element is added and its score initial value is increment. If key does not exist, a new ordered list will be created that contains the unique element of member. If the key corresponds to a value that is not a sequence table, an error occurs. The value of the specified score should be a string that can be converted to a numeric value and receive a double-precision floating-point number. At the same time, you can also provide a negative value, which will reduce score values.
Return value: Returns the value of the new score of member, represented as a string.
This command is available since version 1.1.
5.ZINTERSTORE
Syntax: Zinterstore
Destination Numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE
sum| min| MAX]
Note: In the worst case, the time complexity of the operation is O (n*k) +o (M*log (M)), where N is the smallest ordered set, K is the number of ordered sets, and M is the number of elements in the ordered set of results. Computes the intersection of an ordered set specified by the keys and stores the result in destination. Numkeys In this command, before you pass the input keys, you must provide the number of keys you enter and other optional parameters.
By default, the result of an element score is the score of all ordered sets of that element. For weights and aggregate options, refer to the Zunionstore command. If the target already exists, it will be rewritten.
Return value: Returns the number of elements in an ordered set of destination.
This command is available from the 1.3.10 version.
6.ZRANGE
Syntax: Zrange
Key Start stop
[Withscores]
Description: The time complexity of the operation is O (log (n) +m), where N is the number of elements in an ordered set, and M is the number of elements that will be returned. Returns the elements stored in the specified range on the key. The elements will be sorted in order from lowest to highest. For elements with the same score, they are sorted in dictionary order.
Refer to the Zrevrange command when you need to sort elements in order from highest to lowest. In the command, start and stop indexes start with 0, 0 for the first element, 1 for the second element, and so on. They can also be negative to specify an offset value from the end of an ordered set, at which point 1 represents the last element in the ordered set,-2 for the penultimate element, and so on. Index values that exceed the bounds will produce an error. If start exceeds the maximum index value of the ordered set, or the start
>
End, an empty set is returned. If the stop exceeds the maximum index of an ordered set, it is treated as the last element.
At the same time, you can pass the Withscores option to the command to bring its scores information when the element is returned. The return value list will now be value1,
Score1, ..., Valuen, Scoren, not value1, ...,
Valuen.
Return value: Returns the list of elements within the specified range.
This command is available since version 1.1.
7.ZRANGEBYSCORE
Syntax: Zrangebyscore
Key min Max [withscores] [limit offset
Count
Description: The time complexity of the operation is O (log (n) +m), where N is the number of elements in an ordered set, and M is the number of elements that will be returned. If M is constant, you can think of a time complexity of O (log (N)). Returns the score of all elements between Min and Max (Kit Harington score equals min or Max) in an ordered set corresponding to the key. Elements are arranged in the order of score from lowest to highest. If the elements have the same score, they are sorted in the dictionary order.
Optional options limit can be used to get a range of matching elements. If the offset value is large, the ordered collection needs to be traversed before obtaining the element to be returned, thus increasing the time complexity of O (N). Optional withscores can make the score of an element return at the same time that the element is returned, since the option Redis
Available after version 2.0.
Exclude interval endpoints and infinity values:
Min and Max can be-inf and +inf, so you can get all the elements within a certain range without knowing the score maximum or minimum value. By default, the interval specified by Min and Max is a closed interval. You can also specify an open interval (excluding the interval endpoint) by adding "(" prefix) before the score. For example:
Zrangebyscore
Zset (1 5
will return 1 < score <=
All elements of 5.
Return value: Specifies the list of all elements within the score interval.
This command is available since version 1.050.
8.ZRANK
Syntax: Zrank
Key
Member
Description: The time complexity of the operation is O (log (N)). Returns the index value of the member element in the ordered set corresponding to the key, in which the elements are arranged in score from lowest to highest. The rank value (or index) starts at 0, which means that the rank value of the element with the lowest score value is 0. Use Zrevrank to get rank (or index) of elements that are arranged from highest to lowest.
Return value: If member exists in an ordered set, the rank value of member is returned, if member does not exist, or if the specified key does not exist, then the return value is nil.
This command is available from the 1.3.4 version.
9.ZREM
Syntax: Zrem
Key
Member
Description: The time complexity of the operation is O (log (n)), where N is the number of elements in an ordered set. Removes the specified element from the ordered set corresponding to the key. If member is not an element in an ordered collection, no action is performed. If the key exists but its corresponding value is not an ordered collection, an error occurs.
Return value: If member is removed, then the return value is 1; If member is not an element in an ordered collection, then the return value is 0.
This command is available since version 1.1.
10.ZREMRANGEBYRANK
Syntax: Zremrangebyrank
Key start
Stop Description: The time complexity of the operation is O (log (n) +m), where N is the number of elements in an ordered set, and M is the number of elements that will be removed. Removes all elements in the ordered set corresponding to the key between start and stop. Start and stop start at 0, and both can be negative. When the index value is negative, it indicates that the offset value starts with the element with the highest score value in the ordered collection. For example: 1 represents the element with the highest score, and 2 represents the element with the secondary high score, and so on.
Return value: Returns the number of elements that will be removed.
This command is available from the 1.3.4 version.
11.ZREMRANGEBYSCORE
Syntax: Zremrangebyscore key min
Max
Description: The time complexity of the operation is O (log (n) +m), where N is the number of elements in an ordered set, and M is the number of elements that will be removed. Removes the Scroe element between Min and Max (which contains endpoints) in an ordered set of key equivalents. Starting with version 2.1.6, the interval endpoint min and Max can be excluded, as is the case with Zrangebyscore syntax.
Return value: Returns the number of elements that will be removed.
This command is available since version 1.1.
12.ZREVRANGE
Syntax: Zrevrange
Key Start stop
[Withscores]
Description: The time complexity of the operation is O (log (n) +m), where N is the number of elements in an ordered set, and M is the number of elements that will be returned. Returns all the elements of the specified interval in the ordered set of key equivalents. These elements are arranged in the order of score from highest to lowest. For elements with the same score, they will be sorted in descending dictionary order. This command is similar to Zrange, except that the elements in the command are arranged in a different order than the former.
Return value: The list of elements within the specified interval.
This command is available since version 1.1.
13.ZREVRANGEBYSCROE
Syntax: Zrevrangebyscore
Key Max min [withscores] [LIMIT offset
Count
Description: The time complexity of the operation is O (log (n) +m), where N is the number of elements in an ordered set, and M is the number of elements that will be returned. If M is a constant, then you can think of the time complexity of O (log (N)).
Returns all of the elements in the ordered set corresponding to the key between Max and Min (elements that contain score equals Max or min). Score The command sorts the elements in the order of score from highest to lowest. If two elements have the same score, they will be sorted in dictionary order. The Zrevrangebyscore command is the same as the Zrangebyscore command, except that the order of arrangement is different.
Return value: Specifies the list of elements within the score interval.
This command is available from the 2.1.6 version.
14.ZREVRANK
Syntax: Zrevrank
Key
Member
Description: The time complexity of the operation is O (log (N)). Returns the index value of member in the ordered set corresponding to the key, in which the elements are arranged in order from highest to lowest. The rank value (or index value) is counted starting at 0, so the rank value of the element with the highest score value is 0. You can use the Zrank command to get the rank value of an element in the order of Scroe values from low to high.
Return value: If member is present in an ordered collection, the return value is the rank value of member, and if member does not exist or the key does not exist, then the return value is nil.
This command is available from the 1.3.4 version.
15.ZSCORE
Syntax: Zscore
Key
Member
Description: The time complexity of the command is O (1). Returns the score value of member in the ordered set corresponding to the key. If member does not exist in an ordered collection, then nil is returned.
Return value: Returns the score value of member (a double-precision floating-point number), represented as a string.
This command is available since version 1.1.
16.ZUNIONSTORE
Syntax: Zunionstore
Destination Numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE
sum| min| MAX]
Note: The time complexity of the operation is O (n) +o (Mlog (M)), where N is the total size of the input ordered set, and M is the number of elements in the result set. Computes a collection of Numkeys ordered sets corresponding to the keys and stores the results in destination. You must provide the number of input keys and other optional parameters before passing the input keys. By default, the result of an element is score the score in all ordered sets that contain the element. If you use the weights option, you can specify an action factor for each ordered set. This means that the score of each element in each ordered set is multiplied by the factor before being passed to the aggregate function. When weights is not specified, the action factor defaults to 1.
Using the aggregate option, you can specify how the results of the intersection are aggregated. The default value for this option is sum, in which case all score values of an element are added. When the selected item is set to Min or Max, the result set will contain the maximum or minimum score value of an element. If destination already exists, then it will be rewritten.
Return value: The number of elements in the ordered set of objects.
This command is available from the 1.3.10 version.