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

Method Decr

structure/string.go:269–289  ·  view source on GitHub ↗

Decr decrements the integer value of a key by 1

(key string, ttl int64)

Source from the content-addressed store, hash-verified

267
268// Decr decrements the integer value of a key by 1
269func (s *StringStructure) Decr(key string, ttl int64) error {
270 // Get the old value
271 oldValue, err := s.Get(key)
272 if err != nil {
273 return err
274 }
275
276 // Convert the old value to an integer
277 intValue, err := convertToInt(oldValue)
278 if err != nil {
279 return err
280 }
281
282 // Decrement the integer value
283 newIntValue := intValue - 1
284
285 newValue := strconv.Itoa(newIntValue)
286
287 // Set the value
288 return s.Set(key, newValue, ttl)
289}
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 {

Callers

nothing calls this directly

Calls 3

GetMethod · 0.95
SetMethod · 0.95
convertToIntFunction · 0.85

Tested by

no test coverage detected