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

Method DecrementInt64

pkg/util/cache/cache.go:727–744  ·  view source on GitHub ↗

Decrement 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 decremented value is returned.

(k string, n int64)

Source from the content-addressed store, hash-verified

725// not an int64, or if it was not found. If there is no error, the decremented
726// value is returned.
727func (c *cache) DecrementInt64(k string, n int64) (int64, error) {
728 c.mu.Lock()
729 v, found := c.items[k]
730 if !found || v.Expired() {
731 c.mu.Unlock()
732 return 0, fmt.Errorf("Item %s not found", k)
733 }
734 rv, ok := v.Object.(int64)
735 if !ok {
736 c.mu.Unlock()
737 return 0, fmt.Errorf("The value for %s is not an int64", k)
738 }
739 nv := rv - n
740 v.Object = nv
741 c.items[k] = v
742 c.mu.Unlock()
743 return nv, nil
744}
745
746// Decrement an item of type uint by n. Returns an error if the item's value is
747// not an uint, or if it was not found. If there is no error, the decremented

Callers 1

TestDecrementInt64Function · 0.80

Calls 3

LockMethod · 0.80
ExpiredMethod · 0.80
ErrorfMethod · 0.80

Tested by 1

TestDecrementInt64Function · 0.64