MCPcopy Index your code
hub / github.com/ByteStorage/FlyDB / ZIncrBy

Method ZIncrBy

structure/zset.go:881–903  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

879// if there's an issue with node insertion,
880// if unable to set ZSet to DB post increment operation
881func (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.
906func (zs *ZSetStructure) getOrCreateZSet(key string) (*FZSet, error) {

Callers

nothing calls this directly

Calls 5

getZSetFromDBMethod · 0.95
setZSetToDBMethod · 0.95
checkKeyFunction · 0.85
stringToBytesWithKeyFunction · 0.85
InsertNodeMethod · 0.80

Tested by

no test coverage detected