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

Method IncrementInt64

pkg/util/cache/cache.go:365–382  ·  view source on GitHub ↗

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

(k string, n int64)

Source from the content-addressed store, hash-verified

363// not an int64, or if it was not found. If there is no error, the incremented
364// value is returned.
365func (c *cache) IncrementInt64(k string, n int64) (int64, error) {
366 c.mu.Lock()
367 v, found := c.items[k]
368 if !found || v.Expired() {
369 c.mu.Unlock()
370 return 0, fmt.Errorf("Item %s not found", k)
371 }
372 rv, ok := v.Object.(int64)
373 if !ok {
374 c.mu.Unlock()
375 return 0, fmt.Errorf("The value for %s is not an int64", k)
376 }
377 nv := rv + n
378 v.Object = nv
379 c.items[k] = v
380 c.mu.Unlock()
381 return nv, nil
382}
383
384// Increment an item of type uint by n. Returns an error if the item's value is
385// not an uint, or if it was not found. If there is no error, the incremented

Callers 1

TestIncrementInt64Function · 0.80

Calls 3

LockMethod · 0.80
ExpiredMethod · 0.80
ErrorfMethod · 0.80

Tested by 1

TestIncrementInt64Function · 0.64