MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / IncrByFloat

Method IncrByFloat

structure/string.go:245–266  ·  view source on GitHub ↗

IncrByFloat increments the float value of a key by the given amount

(key string, amount float64, ttl int64)

Source from the content-addressed store, hash-verified

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 {
246 // Get the old value
247 oldValue, err := s.Get(key)
248 if err != nil {
249 return err
250 }
251
252 // Convert the old value to a byte slice
253 floatValue, err := convertToFloat(oldValue)
254 if err != nil {
255 return err
256 }
257
258 // Increment the float value
259 newFloatValue := floatValue + amount
260
261 // Convert the new float value to a byte slice
262 newValue := strconv.FormatFloat(newFloatValue, 'f', -1, 64)
263
264 // Set the value
265 return s.Set(key, newValue, ttl)
266}
267
268// Decr decrements the integer value of a key by 1
269func (s *StringStructure) Decr(key string, ttl int64) error {

Callers

nothing calls this directly

Calls 3

GetMethod · 0.95
SetMethod · 0.95
convertToFloatFunction · 0.85

Tested by

no test coverage detected