title: Pattern for handling with Redis multiple simultaneous requests
body: <p>A have an API that executes a query that takes 1 minute to process. If someone makes a GET request to this API, I will execute the query and save the results in Redis.</p>
  <p>New requests to this API will use the cached data from Redis, avoiding doing this 1 minute query again.</p>
  <p>My problem is: at 8AM, my cache is dropped because new data is available in the database. The first API request will execute the 1 minute-long query. The second request will also execute the same 1 minute-long query, since the first one hasn't finished yet and Redis is empty.</p>
  <p>In the end, I have thousands of queries running and the database can't handle all of them, and no query can finish because the database stops to work.</p>
  <p>Is there a known pattern to handle this?</p>
  <p>What I'm doing to handle this is to set a flag &quot;isQueryRunning&quot; (thread-safe by a lock) to allow just one thread to execute per time, leaving the others waiting, but I would like to know if there are other known strategies.</p>