M
M
Mykola Ivashchuk2019-07-30 11:02:50
Redis
Mykola Ivashchuk, 2019-07-30 11:02:50

How to use Atomic Locks in Redis?

There is a set of videos. [a,b,c,d]
There are multiple users. [1,2,3]
If a user made a request to receive a video, then within time N it should be returned only to him, and not to other users.
I see an option to cache an associative array that which user has taken, and make a selection based on it, but perhaps there is a more beautiful solution? I looked in the direction of Atomic Locks but did not fully understand what it was for

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2019-07-30
@mykolaim

How to use Atomic Locks in Redis?

In different libraries, the interface and implementation of locks are different, you need to look at examples for a specific client.
Possibly, depending on requirements.
Atomic locks are needed to organize exclusive access to some resource. As an example, to solve the problem of races when trying to "take" one video at once by several users. First, a lock is obtained: this ensures that the rest of the applicants will wait for her release. Then the necessary actions are performed, for example, manipulations with an associative array. At the end, the lock must be released.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question