Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion increment() creates new keys.
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
gf pro  
View profile  
 More options Jul 17 2009, 4:32 am
From: gf pro <kak.serpom.po.yait...@gmail.com>
Date: Fri, 17 Jul 2009 12:32:05 +0400
Local: Fri, Jul 17 2009 4:32 am
Subject: Re: increment() creates new keys.

while (!redis.INCR(foo)) {redis.SETNX(foo,1);}

2009/7/17 Ian Holsman <kry...@gmail.com>

> gf wrote:
> > Just SETNX ;-)

> similar issues.
> you end up with this.

> if (!redis.INCR(foo) {
>    if ( !redis.SETNX(foo,1) ) {
>       redis.INCR(foo)
>    }
> }
> as 2 people could be incrementing the counter (and failing) at the same
> time, and trying to set it to 1 at the same time (with 1 failing).
> fugly.
> > On 16 июл, 04:32, Ian Holsman <kry...@gmail.com> wrote:

> >> gf wrote:

> >>> Hello.
> >>> "INCR notexists" returns 1, but I think it has to return "false".

> >> but if you do that the code around incrementing it would look quite
> >> fugly no?

> >> cnt = redis.INCR("foo");
> >> if ( cnt is boolean && cnt == false ) {
> >>     redis.SET("foo",1);

> >> }

> >> ?
> >> this also leads to the problem of thread races where multiple people are
> >> executing the same logic. you might have n threads/clients running
> >> through this code at the same time.
> >> and you would end up with 'foo' being 1. instead of n.
> >> so your logic would then need to be something like

> >> redis.lock("foo")
> >> cnt = redis.INCR("foo");
> >> if ( cnt is boolean && cnt == false ) {
> >>     redis.SET("foo",1);}

> >> redis.unlock("foo")


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.