Redis compare and set atomic
I want to store in redis some int that will show the current load(pending request count).
I need this counter in redis to check if app should send request to underline service or not.
For example I have threshold 50 pending request. And if app already sent 50 request I have to throttle my request. Something similar to distributed semaphore.
I see that Redis has transaction. But it cannot return the value.
Can Redis help me with such case?
java redis nosql semaphore amazon-elasticache
add a comment |
I want to store in redis some int that will show the current load(pending request count).
I need this counter in redis to check if app should send request to underline service or not.
For example I have threshold 50 pending request. And if app already sent 50 request I have to throttle my request. Something similar to distributed semaphore.
I see that Redis has transaction. But it cannot return the value.
Can Redis help me with such case?
java redis nosql semaphore amazon-elasticache
You mean you would like to Atomically "compare the value and increment it by 1" or "compare the value and set a new value"?
– Bandi Kishore
Nov 15 '18 at 19:35
Yeap. Compare and set.
– Aleksandr Filichkin
Nov 15 '18 at 19:38
add a comment |
I want to store in redis some int that will show the current load(pending request count).
I need this counter in redis to check if app should send request to underline service or not.
For example I have threshold 50 pending request. And if app already sent 50 request I have to throttle my request. Something similar to distributed semaphore.
I see that Redis has transaction. But it cannot return the value.
Can Redis help me with such case?
java redis nosql semaphore amazon-elasticache
I want to store in redis some int that will show the current load(pending request count).
I need this counter in redis to check if app should send request to underline service or not.
For example I have threshold 50 pending request. And if app already sent 50 request I have to throttle my request. Something similar to distributed semaphore.
I see that Redis has transaction. But it cannot return the value.
Can Redis help me with such case?
java redis nosql semaphore amazon-elasticache
java redis nosql semaphore amazon-elasticache
asked Nov 15 '18 at 19:26
Aleksandr FilichkinAleksandr Filichkin
123112
123112
You mean you would like to Atomically "compare the value and increment it by 1" or "compare the value and set a new value"?
– Bandi Kishore
Nov 15 '18 at 19:35
Yeap. Compare and set.
– Aleksandr Filichkin
Nov 15 '18 at 19:38
add a comment |
You mean you would like to Atomically "compare the value and increment it by 1" or "compare the value and set a new value"?
– Bandi Kishore
Nov 15 '18 at 19:35
Yeap. Compare and set.
– Aleksandr Filichkin
Nov 15 '18 at 19:38
You mean you would like to Atomically "compare the value and increment it by 1" or "compare the value and set a new value"?
– Bandi Kishore
Nov 15 '18 at 19:35
You mean you would like to Atomically "compare the value and increment it by 1" or "compare the value and set a new value"?
– Bandi Kishore
Nov 15 '18 at 19:35
Yeap. Compare and set.
– Aleksandr Filichkin
Nov 15 '18 at 19:38
Yeap. Compare and set.
– Aleksandr Filichkin
Nov 15 '18 at 19:38
add a comment |
1 Answer
1
active
oldest
votes
We had a similar requirement where we had to "Compare a value and increment it by 1" Atomically. We ended up using LUA script.
This maybe similar to what you're looking for.
Thank you, will try it!
– Aleksandr Filichkin
Nov 15 '18 at 20:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326639%2fredis-compare-and-set-atomic%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
We had a similar requirement where we had to "Compare a value and increment it by 1" Atomically. We ended up using LUA script.
This maybe similar to what you're looking for.
Thank you, will try it!
– Aleksandr Filichkin
Nov 15 '18 at 20:51
add a comment |
We had a similar requirement where we had to "Compare a value and increment it by 1" Atomically. We ended up using LUA script.
This maybe similar to what you're looking for.
Thank you, will try it!
– Aleksandr Filichkin
Nov 15 '18 at 20:51
add a comment |
We had a similar requirement where we had to "Compare a value and increment it by 1" Atomically. We ended up using LUA script.
This maybe similar to what you're looking for.
We had a similar requirement where we had to "Compare a value and increment it by 1" Atomically. We ended up using LUA script.
This maybe similar to what you're looking for.
answered Nov 15 '18 at 19:52
Bandi KishoreBandi Kishore
3,5311832
3,5311832
Thank you, will try it!
– Aleksandr Filichkin
Nov 15 '18 at 20:51
add a comment |
Thank you, will try it!
– Aleksandr Filichkin
Nov 15 '18 at 20:51
Thank you, will try it!
– Aleksandr Filichkin
Nov 15 '18 at 20:51
Thank you, will try it!
– Aleksandr Filichkin
Nov 15 '18 at 20:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326639%2fredis-compare-and-set-atomic%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You mean you would like to Atomically "compare the value and increment it by 1" or "compare the value and set a new value"?
– Bandi Kishore
Nov 15 '18 at 19:35
Yeap. Compare and set.
– Aleksandr Filichkin
Nov 15 '18 at 19:38