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

Method Incr

structure/string.go:201–221  ·  view source on GitHub ↗

Incr increments the integer value of a key by 1

(key string, ttl int64)

Source from the content-addressed store, hash-verified

199
200// Incr increments the integer value of a key by 1
201func (s *StringStructure) Incr(key string, ttl int64) error {
202 // Get the old value
203 oldValue, err := s.Get(key)
204 if err != nil {
205 return err
206 }
207
208 intValue, err := convertToInt(oldValue)
209 if err != nil {
210 return err
211 }
212
213 // Increment the integer value
214 newIntValue := intValue + 1
215
216 // Convert the new integer value to a byte slice
217 newValue := strconv.Itoa(newIntValue)
218
219 // Set the value
220 return s.Set(key, newValue, ttl)
221}
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 {

Callers

nothing calls this directly

Calls 3

GetMethod · 0.95
SetMethod · 0.95
convertToIntFunction · 0.85

Tested by

no test coverage detected