MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / IncrementInt

Method IncrementInt

pkg/util/cache/cache.go:277–294  ·  view source on GitHub ↗

Increment an item of type int by n. Returns an error if the item's value is not an int, or if it was not found. If there is no error, the incremented value is returned.

(k string, n int)

Source from the content-addressed store, hash-verified

275// not an int, or if it was not found. If there is no error, the incremented
276// value is returned.
277func (c *cache) IncrementInt(k string, n int) (int, error) {
278 c.mu.Lock()
279 v, found := c.items[k]
280 if !found || v.Expired() {
281 c.mu.Unlock()
282 return 0, fmt.Errorf("Item %s not found", k)
283 }
284 rv, ok := v.Object.(int)
285 if !ok {
286 c.mu.Unlock()
287 return 0, fmt.Errorf("The value for %s is not an int", k)
288 }
289 nv := rv + n
290 v.Object = nv
291 c.items[k] = v
292 c.mu.Unlock()
293 return nv, nil
294}
295
296// Increment an item of type int8 by n. Returns an error if the item's value is
297// not an int8, or if it was not found. If there is no error, the incremented

Callers 2

TestIncrementIntFunction · 0.80
BenchmarkIncrementIntFunction · 0.80

Calls 3

LockMethod · 0.80
ExpiredMethod · 0.80
ErrorfMethod · 0.80

Tested by 2

TestIncrementIntFunction · 0.64
BenchmarkIncrementIntFunction · 0.64