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

Method IncrBy

structure/string.go:224–242  ·  view source on GitHub ↗

IncrBy increments the integer value of a key by the given amount

(key string, amount int, ttl int64)

Source from the content-addressed store, hash-verified

222
223// IncrBy increments the integer value of a key by the given amount
224func (s *StringStructure) IncrBy(key string, amount int, ttl int64) error {
225 // Get the old value
226 oldValue, err := s.Get(key)
227 if err != nil {
228 return err
229 }
230
231 // Convert the old value to an integer
232 intValue, err := convertToInt(oldValue)
233 if err != nil {
234 return err
235 }
236
237 newIntValue := intValue + amount
238
239 newValue := strconv.Itoa(newIntValue)
240
241 return s.Set(key, newValue, ttl)
242}
243
244// IncrByFloat increments the float value of a key by the given amount
245func (s *StringStructure) IncrByFloat(key string, amount float64, ttl int64) error {

Callers

nothing calls this directly

Calls 3

GetMethod · 0.95
SetMethod · 0.95
convertToIntFunction · 0.85

Tested by

no test coverage detected