ZRevRank calculates the reverse rank of a member in a ZSet (Sorted Set) associated with a given key. ZSet exploits the Sorted Set data structure of Redis with O(log(N)) time complexity for Fetching the rank. Parameters: key: This is a string that serves as the key of a ZSet stored in the datab
(key string, member string)
| 703 | // |
| 704 | // Note: The reverse rank is calculated as 'size - rank', and the ranks start from 1. |
| 705 | func (zs *ZSetStructure) ZRevRank(key string, member string) (int, error) { |
| 706 | if err := checkKey(key); err != nil { |
| 707 | return 0, err |
| 708 | } |
| 709 | keyBytes := stringToBytesWithKey(key) |
| 710 | |
| 711 | zSet, err := zs.getZSetFromDB(keyBytes) |
| 712 | if err != nil { |
| 713 | return 0, fmt.Errorf("failed to get or create ZSet from DB with key '%v': %w", key, err) |
| 714 | } |
| 715 | if v, ok := zSet.dict[member]; ok { |
| 716 | rank := zSet.skipList.getRank(v.score, member) |
| 717 | return (zSet.size) - rank + 1, nil |
| 718 | } |
| 719 | |
| 720 | // rank zero means no rank found |
| 721 | return 0, _const.ErrKeyNotFound |
| 722 | } |
| 723 | |
| 724 | // ZRange retrieves a specific range of elements from a sorted set (ZSet) denoted by a specific key. |
| 725 | // It returns a slice of ZSetValue containing the elements within the specified range (inclusive), and a nil error when successful. |
nothing calls this directly
no test coverage detected