2
0

Add specialized increment and decrement methods

This commit is contained in:
Patrick Mylund Nielsen
2013-04-18 14:24:30 -04:00
parent b5601e904d
commit d5d03c28d4
3 changed files with 1584 additions and 125 deletions
+133 -3
View File
@@ -119,13 +119,73 @@ func (c *Cache) Increment(k string, n int64) error
Increment an item of type int, int8, int16, int32, int64, uintptr, uint,
uint8, uint32, or uint64, float32 or float64 by n. Returns an error if the
item's value is not an integer, if it was not found, or if it is not
possible to increment it by n.
possible to increment it by n. To retrieve the incremented value, use one
of the specialized methods, e.g. IncrementInt64.
func (c *Cache) IncrementFloat(k string, n float64) error
Increment an item of type float32 or float64 by n. Returns an error if the
item's value is not floating point, if it was not found, or if it is not
possible to increment it by n. Pass a negative number to decrement the
value.
possible to increment it by n.
func (c *Cache) IncrementInt(k string, n int) (int, error)
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.
func (c *Cache) IncrementInt8(k string, n int8) (int8, error)
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.
func (c *Cache) IncrementInt16(k string, n int16) (int16, error)
Increment an item of type int16 by n. Returns an error if the item's value
is not an int16, or if it was not found. If there is no error, the
incremented value is returned.
func (c *Cache) IncrementInt32(k string, n int32) (int32, error)
Increment an item of type int32 by n. Returns an error if the item's value
is not an int32, or if it was not found. If there is no error, the
incremented value is returned.
func (c *Cache) IncrementInt64(k string, n int64) (int64, error)
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.
func (c *Cache) IncrementUint(k string, n uint) (uint, error)
Increment an item of type uint by n. Returns an error if the item's value
is not an uint, or if it was not found. If there is no error, the
incremented value is returned.
func (c *Cache) IncrementUint8(k string, n uint8) (uint8, error)
Increment an item of type uint8 by n. Returns an error if the item's value
is not an uint8, or if it was not found. If there is no error, the
incremented value is returned.
func (c *Cache) IncrementUint16(k string, n uint16) (uint16, error)
Increment an item of type uint16 by n. Returns an error if the item's value
is not an uint16, or if it was not found. If there is no error, the
incremented value is returned.
func (c *Cache) IncrementUint32(k string, n uint32) (uint32, error)
Increment an item of type uint32 by n. Returns an error if the item's value
is not an uint32, or if it was not found. If there is no error, the
incremented value is returned.
func (c *Cache) IncrementUint64(k string, n uint64) (uint64, error)
Increment an item of type uint64 by n. Returns an error if the item's value
is not an uint64, or if it was not found. If there is no error, the
incremented value is returned.
func (c *Cache) IncrementFloat32(k string, n float32) (float32, error)
Increment an item of type float32 by n. Returns an error if the item's value
is not an float32, or if it was not found. If there is no error, the
incremented value is returned.
func (c *Cache) IncrementFloat64(k string, n float64) (float64, error)
Increment an item of type float64 by n. Returns an error if the item's value
is not an float64, or if it was not found. If there is no error, the
incremented value is returned.
func (c *Cache) Decrement(k string, n int64) error
Decrement an item of type int, int8, int16, int32, int64, uintptr, uint,
@@ -133,6 +193,76 @@ func (c *Cache) Decrement(k string, n int64) error
item's value is not an integer, if it was not found, or if it is not
possible to decrement it by n.
func (c *Cache) DecrementFloat(k string, n float64) error
Decrement an item of type float32 or float64 by n. Returns an error if the
item's value is floating point, if it was not found, or if it is not
possible to decrement it by n.
func (c *Cache) DecrementInt(k string, n int) (int, error)
Decrement 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 decremented
value is returned.
func (c *Cache) DecrementInt8(k string, n int8) (int8, error)
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.
func (c *Cache) DecrementInt16(k string, n int16) (int16, error)
Decrement an item of type int16 by n. Returns an error if the item's value
is not an int16, or if it was not found. If there is no error, the
decremented value is returned.
func (c *Cache) DecrementInt32(k string, n int32) (int32, error)
Decrement an item of type int32 by n. Returns an error if the item's value
is not an int32, or if it was not found. If there is no error, the
decremented value is returned.
func (c *Cache) DecrementInt64(k string, n int64) (int64, error)
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.
func (c *Cache) DecrementUint(k string, n uint) (uint, error)
Decrement an item of type uint by n. Returns an error if the item's value
is not an uint, or if it was not found. If there is no error, the
decremented value is returned.
func (c *Cache) DecrementUintptr(k string, n uintptr) (uintptr, error)
Decrement an item of type uintptr by n. Returns an error if the item's value
is not an uintptr, or if it was not found. If there is no error, the
decremented value is returned.
func (c *Cache) DecrementUint8(k string, n uint8) (uint8, error)
Decrement an item of type uint8 by n. Returns an error if the item's value
is not an uint8, or if it was not found. If there is no error, the
decremented value is returned.
func (c *Cache) DecrementUint16(k string, n uint16) (uint16, error)
Decrement an item of type uint16 by n. Returns an error if the item's value
is not an uint16, or if it was not found. If there is no error, the
decremented value is returned.
func (c *Cache) DecrementUint32(k string, n uint32) (uint32, error)
Decrement an item of type uint32 by n. Returns an error if the item's value
is not an uint32, or if it was not found. If there is no error, the
decremented value is returned.
func (c *Cache) DecrementUint64(k string, n uint64) (uint64, error)
Decrement an item of type uint64 by n. Returns an error if the item's value
is not an uint64, or if it was not found. If there is no error, the
decremented value is returned.
func (c *Cache) DecrementFloat32(k string, n float32) (float32, error)
Decrement an item of type float32 by n. Returns an error if the item's value
is not an float32, or if it was not found. If there is no error, the
decremented value is returned.
func (c *Cache) DecrementFloat64(k string, n float64) (float64, error)
Decrement an item of type float64 by n. Returns an error if the item's value
is not an float64, or if it was not found. If there is no error, the
decremented value is returned.
func (c *Cache) Delete(k string)
Delete an item from the cache. Does nothing if the key does not exist in the
cache.