title: How to have one Redis client wait for all the other Redis clients to respond?
body: <p>I have one Redis server, and multiple Redis clients. Each Redis client is a WebSocket+HTTP server that, amongst others, manages WebSocket connections. These WebSocket+HTTP servers are hidden behind a load balancer.</p>
  
  <p>The WebSocket+HTTP servers provide a <code>GET /health</code> HTTP endpoint. I would like this endpoint to provide the total number of current WebSocket connections, across the whole cluster.</p>
  
  <p>When one hits <code>GET /health</code>, then obviously, the load balancer will dispatch the request to only one WebSocket+HTTP server instance.</p>
  
  <p>How can I make one WebSocket+HTTP server instance ask for all the other instances how many WebSocket connections they currently manage?</p>
  
  <hr>
  
  <p>I thought of the following steps:</p>
  
  <ol>
  <li>The instance uses <a href="https://redis.io/commands/client-list" rel="nofollow noreferrer"><code>CLIENT LIST</code></a> to know how many Redis clients there currently are (say <code>n</code>);</li>
  <li>The instance then publishes <code>WEBSOCKET_CONNECTION_COUNT_REQUEST</code> to Redis (with the assumption that all Redis clients are subscribed to this event);</li>
  <li>The instance finally waits for <code>n</code> <code>WEBSOCKET_CONNECTION_COUNT_RESPONSE</code>s, sums up the counts, and returns it over HTTP.</li>
  </ol>
  
  <p>What do you think about the above approach? Isn't it a bit too convoluted? I have the feeling I'm maybe a bit overengineering...</p>
  
  <hr>
  
  <p>I initially thought that instances could <code>INCR</code>/<code>DECR</code> a count inside the Redis storage, but I'm not sure how to handle instances being killed (as the count should then be decremented accordingly). I think an ad-hoc solution would be preferable. Still open to ideas though.</p>