incr: Increment or decrement Redis values.

Description Usage Arguments Details Value Author(s) References See Also Examples

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

1
2
3
4
5
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).

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.

Value

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

Author(s)

B. W. Lewis

References

http://redis.io/commands

See Also

redisDecr

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## 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)

rredis documentation built on May 2, 2019, 2:02 p.m.