Learn R Programming

rredis (version 1.7.0)

Increment, Decrement functions: Increment or decrement Redis values.

Description

redisIncr increments the Redis string value corresponding to the specified key by one.

redisDecr decrements the Redis string value corresponding to the specified key by one.

The various *By functions increment or decrement values by a specified integer or numeric value.

Usage

redisIncr(key) redisIncrBy(key, value) redisIncrByFloat(key, value) redisDecr(key) redisDecrBy(key, value)

Arguments

key
A key corresponding to the value to increment.
value
The value to increment by (integer, numeric, or character).

Value

The new value of key after the increment. Note that the value is returned as a raw Redis string value.

Details

Note that they initial value must be a raw character value (a plain Redis string value), not a serialized R value. See the examples below.

The increment value may be an integer (redisIncrBy) or a numeric value (redisIncrByFloat), or a raw character representation of an integer or numeric value. If the key does not exist or contains a value of a wrong type, set the key to the value of "0" or similar string representation of an integer before running the function.

References

http://redis.io/commands

See Also

redisDecr

Examples

Run this code
## Not run: 
# redisSet('x',charToRaw('5'))  # Note the value must be a raw string!
# redisIncr('x')
# redisIncrBy('x','3')
# redisIncrBy('x',3)  # also works
# redisIncrByFloat('x',pi)
# redisDecr('x')
# redisDecrBy('x',3)
# ## End(Not run)

Run the code above in your browser using DataLab