Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement lock using redis3m. #18

Closed
nidhijha opened this issue Feb 25, 2015 · 3 comments
Closed

How to implement lock using redis3m. #18

nidhijha opened this issue Feb 25, 2015 · 3 comments
Labels

Comments

@nidhijha
Copy link

Lets say my use case is, There are 2 processes trying to acquire lock on some key. One of them succeed, while other will just wait. Once first one is done updating the value it should release lock and then 2nd process can acquire lock if want or use the value updated by 1st one. I am talking about similar methods from StackExchange.Redis for c#

  1. LockTake
  2. LockRelease
  3. LockExtend
  4. LockQuery
@nidhijha nidhijha changed the title How to implement lock using redis3m. Lets say my use case is, There are 2 processes trying to acquire lock on some key. One of them succeed, while other will just wait. Once first one is done updating the value it should release lock and then 2nd process can acquire lock if want or use the value updated by 1st one. How to implement lock using redis3m. Feb 25, 2015
@luca3m
Copy link
Owner

luca3m commented Feb 25, 2015

Lock are implemented in Redis using SET command and its options. StackExchange.Redis does the same as I can see on their code. So you can issue these commands using redis3m too, for example the lockTake should look in this way:

using namespace redis3m;
connection::ptr_t conn = connection::create();
conn->run(command("SET") << "lockname" << "EX" << expiretime << "NX");
// if response is OK you have got the lock, otherwise you don't have it

I called these common features patterns. You can find some here, they are included on redis3m. If you want you can create a new one for locks and we can include it on redis3m.

@nidhijha
Copy link
Author

nidhijha commented Mar 6, 2015

Thanks, I have implemented lock using SET, MULTI, EXEC ,WATCH commands.

@luca3m
Copy link
Owner

luca3m commented Mar 6, 2015

Cool! :)

On 06 Mar 2015, at 08:15, nidhijha notifications@github.com wrote:

Thanks, I have implemented lock using SET, MULTI, EXEC ,WATCH commands.


Reply to this email directly or view it on GitHub.

@luca3m luca3m closed this as completed Aug 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants