August 2025
Intermediate to advanced
272 pages
6h 14m
English
Right now, our client can’t deal with two callers checking out the socket simultaneously. We’re about to address this issue.
First and foremost, let’s verify that this is an actual issue. We can use Task to spawn two processes that send a command to Redis through the client at the same time.
Fire up IEx and type this in:
| | iex> {:ok, client} = RedisClient.start_link(host: ~c"localhost", port: 6379) |
| | iex> for _ <- 1..2 do |
| | ...> Task.async(fn -> RedisClient.command(client, ["PING"]) end) |
| | ...> end |
You will likely see some error, such as a FunctionClauseError or a CaseClauseError. Our client code is full of race conditions that occur when dealing with multiple callers!
The problem is that we’re ...
Read now
Unlock full access