I am interested in creating several different redis based counters in my web application. A lot of this stuff is basically for metrics etc, but that doesn’t make a difference. My question is essentially the following, is it possible to avoid doing:
if $redis.get(key) != null
// increment key
else
// create key with a counter of 1
Ideally something like this would be more optimal
$redis.incr(key, 1) // increment key by 1, and if it does not exist, start it at the value 1
am I overlooking the redis documentation? Is there a way to do this currently?
there is a INCR command, which if the key does not exists sets the value of the key to 1
should work.
see http://redis.io/commands/incr