K
K
komarevtsev2016-04-10 10:19:02
Redis
komarevtsev, 2016-04-10 10:19:02

Transactions in redis?

There is an application on node js that I run through cluster. In child processes there is a certain request to an external api, I want to do it through a proxy.
I'm trying to implement a proxy queue system, that is, use each one in turn. I made an array of proxies and write the proxy number in redis. At the next request, I take this number, increase it by one and take the next proxy. But let's say that we have 2 requests simultaneously for child processes, they both access redis and get the same value, so the proxy will be used 2 times in a row. What is the correct way to solve this problem, because transactions in redis do not give the opportunity to block the read thread?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sh84, 2016-04-14
@sh84

What prevents you from using the lock separately (something like SET key NX PX 1000)? Get the lock, increment the counter, release the lock.

E
Elena Stepanova, 2016-05-16
@Insolita

[b]rpoplpush

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question