Redis compare and set atomic

Viewed 5503

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?

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.

Related