Redis compare and set atomic










0















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?










share|improve this question






















  • 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















0















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?










share|improve this question






















  • 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













0












0








0








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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












1 Answer
1






active

oldest

votes


















2














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.






share|improve this answer























  • Thank you, will try it!

    – Aleksandr Filichkin
    Nov 15 '18 at 20:51











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
);



);













draft saved

draft discarded


















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









2














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.






share|improve this answer























  • Thank you, will try it!

    – Aleksandr Filichkin
    Nov 15 '18 at 20:51















2














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.






share|improve this answer























  • Thank you, will try it!

    – Aleksandr Filichkin
    Nov 15 '18 at 20:51













2












2








2







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3