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 Compare-and-swap
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
 
Josiah Carlson  
View profile  
 More options Oct 4 2012, 12:01 pm
From: Josiah Carlson <josiah.carl...@gmail.com>
Date: Thu, 4 Oct 2012 09:01:15 -0700
Local: Thurs, Oct 4 2012 12:01 pm
Subject: Re: Compare-and-swap
This has been discussed before.

Prior answers:
1. Use a lock (written in the standard watch/multi/exec (this can be
tricky) or Lua)
2. Use Lua to write your compare-and-swap

Either of these lets you express *exactly* what you want without
having to guess.

If you have a limitation that you need to use a version of Redis
before scripting, or need it *now* and can't run one of the Redis
release candidates, then your option is basically to use a lock. Read
my article from January about building a correct lock:
http://dr-josiah.blogspot.com/2012/01/creating-lock-with-redis.html
... because incorrect locks can destroy data.

Regards,
 - Josiah

On Thu, Oct 4, 2012 at 8:21 AM, Garry Shutler

<ga...@robustsoftware.co.uk> wrote:
> Hi,

> I'm been looking at using redis to synchronize work between multiple
> processes and I was surprised to see there wasn't a compare-and-swap
> http://en.wikipedia.org/wiki/Compare-and-swap method available.

> It's a well understood mechanism for synchronization and would make the
> locking process described in http://redis.io/commands/setnx a bit better as
> taking an expired lock would be done via CAS rather than GETSET which may
> replace a lock someone else has put in place (and avoid two people taking
> the same lock if they took it in the same millisecond). Also, it would make
> expiring a lock you hold safer as you wouldn't delete a newly created lock
> (had your lock expired), instead you could CAS the expiry date you set with
> one in the past.

> Does that make sense? Is this a desirable feature? Is there something I'm
> overlooking?

> I can look into creating a PR for this if needed but I don't know C so it
> might take me a while.

> Cheers,

> Garry Shutler

> www.robustsoftware.co.uk | @gshutler

> --
> You received this message because you are subscribed to the Google Groups
> "Redis DB" group.
> To post to this group, send email to redis-db@googlegroups.com.
> To unsubscribe from this group, send email to
> redis-db+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/redis-db?hl=en.


 
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.