Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 775
Aleksandr Filichkin Avatar asked Mar 26 '26 14:03

Aleksandr Filichkin


1 Answers

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.

like image 93
Kishore Bandi Avatar answered Mar 28 '26 02:03

Kishore Bandi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!