Decrement 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 decremented value is returned.
(k string, n int8)
| 659 | // not an int8, or if it was not found. If there is no error, the decremented |
| 660 | // value is returned. |
| 661 | func (c *cache) DecrementInt8(k string, n int8) (int8, error) { |
| 662 | c.mu.Lock() |
| 663 | v, found := c.items[k] |
| 664 | if !found || v.Expired() { |
| 665 | c.mu.Unlock() |
| 666 | return 0, fmt.Errorf("Item %s not found", k) |
| 667 | } |
| 668 | rv, ok := v.Object.(int8) |
| 669 | if !ok { |
| 670 | c.mu.Unlock() |
| 671 | return 0, fmt.Errorf("The value for %s is not an int8", k) |
| 672 | } |
| 673 | nv := rv - n |
| 674 | v.Object = nv |
| 675 | c.items[k] = v |
| 676 | c.mu.Unlock() |
| 677 | return nv, nil |
| 678 | } |
| 679 | |
| 680 | // Decrement an item of type int16 by n. Returns an error if the item's value is |
| 681 | // not an int16, or if it was not found. If there is no error, the decremented |