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

Method DecrBy

structure/string.go:292–312  ·  view source on GitHub ↗

DecrBy decrements the integer value of a key by the given amount

(key string, amount int, ttl int64)

Source from the content-addressed store, hash-verified

290
291// DecrBy decrements the integer value of a key by the given amount
292func (s *StringStructure) DecrBy(key string, amount int, ttl int64) error {
293 // Get the old value
294 oldValue, err := s.Get(key)
295 if err != nil {
296 return err
297 }
298
299 // Convert the old value to an integer
300 intValue, err := convertToInt(oldValue)
301 if err != nil {
302 return err
303 }
304
305 // Decrement the integer value
306 newIntValue := intValue - amount
307
308 newValue := strconv.Itoa(newIntValue)
309
310 // Set the value
311 return s.Set(key, newValue, ttl)
312}
313
314// Keys returns all keys matching pattern
315func (s *StringStructure) Keys(regx string) ([]string, error) {

Callers

nothing calls this directly

Calls 3

GetMethod · 0.95
SetMethod · 0.95
convertToIntFunction · 0.85

Tested by

no test coverage detected