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

Method IncrementInt8

pkg/util/cache/cache.go:299–316  ·  view source on GitHub ↗

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

(k string, n int8)

Source from the content-addressed store, hash-verified

297// not an int8, or if it was not found. If there is no error, the incremented
298// value is returned.
299func (c *cache) IncrementInt8(k string, n int8) (int8, error) {
300 c.mu.Lock()
301 v, found := c.items[k]
302 if !found || v.Expired() {
303 c.mu.Unlock()
304 return 0, fmt.Errorf("Item %s not found", k)
305 }
306 rv, ok := v.Object.(int8)
307 if !ok {
308 c.mu.Unlock()
309 return 0, fmt.Errorf("The value for %s is not an int8", k)
310 }
311 nv := rv + n
312 v.Object = nv
313 c.items[k] = v
314 c.mu.Unlock()
315 return nv, nil
316}
317
318// Increment an item of type int16 by n. Returns an error if the item's value is
319// not an int16, or if it was not found. If there is no error, the incremented

Callers 1

TestIncrementInt8Function · 0.80

Calls 3

LockMethod · 0.80
ExpiredMethod · 0.80
ErrorfMethod · 0.80

Tested by 1

TestIncrementInt8Function · 0.64