SetIfGreater

20 views
Skip to first unread message

Damanjit Singh

unread,
Oct 23, 2016, 4:12:39 PM10/23/16
to Redis DB
Hi,

Just wondering if it would be easy enough for Redis folks for add an API like 'SetIfGreater'. That is only set if the value being set is greater than the current value. 

It would sure be super useful for clients.

Thanks,
Daman

Jan-Erik Rediger

unread,
Oct 23, 2016, 5:08:02 PM10/23/16
to redi...@googlegroups.com
Sounds more like a very specific feature to your use case.
You could easily build it with a short Lua script inside Redis.
> --
> 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 https://groups.google.com/group/redis-db.
> For more options, visit https://groups.google.com/d/optout.

CharSyam

unread,
Oct 23, 2016, 9:36:02 PM10/23/16
to redi...@googlegroups.com, Jan-Erik Rediger
make redis module :) redis supports module from 3.2

2016년 10월 24일 월요일, Jan-Erik Rediger<jan...@fnordig.de>님이 작성한 메시지:

Damanjit Singh

unread,
Oct 26, 2016, 11:51:02 PM10/26/16
to Redis DB, jan...@fnordig.de
I do use Redis transactions (multi/exec) to achieve it. I guess Lua code would be similar. But the problem with this approach is that - if a lot of these operations are done in parallel, it causes most of them to fail, because of optimistic locking. And then, one needs to retry the failed ones. It would much better if REDIS provided this function inherently (similar to SETNX), in which case it would be much faster.

My use case is that I want to make sure that update only happens for newer entries, thus I compare timestamps and only update if the timestamp is greater. I guess that would be a pretty common use case and would benefit many.
 
Reply all
Reply to author
Forward
0 new messages