Is it possible to check for keys existance and increment in one command?

645 views
Skip to first unread message

S Ahmed

unread,
Oct 4, 2013, 4:41:16 PM10/4/13
to redi...@googlegroups.com
Is it possible to check if a key exists, and if it does, increment it in a single command?

They important thing is, if the key does NOT exist, I want to know about that in the return value so I can take action on that fact.

Felix Gallo

unread,
Oct 4, 2013, 4:46:36 PM10/4/13
to redi...@googlegroups.com
Depends on your use case.  

INCR will return 1 if the key did not exist or if it was 0 to start with.

If you are OK with the case of the key existing and being 0 being handled the same way as the key not existing, then that will work for you.  Otherwise I'd use a lua script.

F.


On Fri, Oct 4, 2013 at 1:41 PM, S Ahmed <sahme...@gmail.com> wrote:
Is it possible to check if a key exists, and if it does, increment it in a single command?

They important thing is, if the key does NOT exist, I want to know about that in the return value so I can take action on that fact.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/groups/opt_out.

S Ahmed

unread,
Oct 4, 2013, 5:06:49 PM10/4/13
to redi...@googlegroups.com
Yeah 0 isn't enough, I was hoping to get a another state back.  

NULL - didn't exist, so didn't increment
> 0 - existed, incremented

I guess lua is the only way then thanks.
Reply all
Reply to author
Forward
0 new messages