ZIncrBy increases the score of an existing member in a sorted set stored at specified key by the increment `incBy` provided. If member does not exist, ErrKeyNotFound error is returned. If the key does not exist, it treats it as an empty sorted set and returns an error. The method accepts three para
(key string, member string, incBy int)
| 879 | // if there's an issue with node insertion, |
| 880 | // if unable to set ZSet to DB post increment operation |
| 881 | func (zs *ZSetStructure) ZIncrBy(key string, member string, incBy int) error { |
| 882 | if err := checkKey(key); err != nil { |
| 883 | return err |
| 884 | } |
| 885 | keyBytes := stringToBytesWithKey(key) |
| 886 | |
| 887 | zSet, err := zs.getZSetFromDB(keyBytes) |
| 888 | if err != nil { |
| 889 | return fmt.Errorf("failed to get or create ZSet from DB with key '%v': %w", key, err) |
| 890 | } |
| 891 | |
| 892 | if v, ok := zSet.dict[member]; ok { |
| 893 | if err = zSet.InsertNode(v.score+incBy, member, v.value); err != nil { |
| 894 | return err |
| 895 | } |
| 896 | if err = zs.setZSetToDB(keyBytes, zSet); err != nil { |
| 897 | return err |
| 898 | } |
| 899 | return zs.setZSetToDB(keyBytes, zSet) |
| 900 | } |
| 901 | |
| 902 | return _const.ErrKeyNotFound |
| 903 | } |
| 904 | |
| 905 | // getOrCreateZSet attempts to retrieve a sorted set by a key, or creates a new one if it doesn't exist. |
| 906 | func (zs *ZSetStructure) getOrCreateZSet(key string) (*FZSet, error) { |
nothing calls this directly
no test coverage detected