hincrbyex

Increment a value in a hash only if it exists

Returns New counter value if found, otherwise nil
Keys
  1. A Hash containing a field to be used as a counter
Args
  1. The field within the Hash to use as a counter
  2. The amount to increment the counter by

Example

> evalsha 3cb0d65c399fda8a1d4eb93b2fe85311671bc969 1 guests sally 1
(nil)
> hset guests sally 8
(integer) 1
> evalsha 3cb0d65c399fda8a1d4eb93b2fe85311671bc969 1 guests sally 1
(integer) 9
> evalsha 3cb0d65c399fda8a1d4eb93b2fe85311671bc969 1 guests sally 1
(integer) 10

Source

if redis.call("HEXISTS", KEYS[1], ARGV[1]) == 1 then
  return redis.call("HINCRBY", KEYS[1], ARGV[1], ARGV[2])
else
  return nil
end

SHA

3cb0d65c399fda8a1d4eb93b2fe85311671bc969

Explore Your Redis Memory Usage with an Interactive Map

RedisMonitor from RedisGreen shows you large keys, memory leaks, old keys, and other potential problems quickly. Try it now, no credit card required!

Last updated 31 Jul 2014.

← More scripts from the RedisGreen Library

License

All scripts on this site are in the public domain, unless otherwise noted, and are provided without warranty express or implied. RedisGreen make no claim for the effectiveness, safety, security or quality of the scripts contained within.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.