void pruneMissingPeers() {
    prunePeersTimer.record(() -> {
      final Set<String> peerIds = presenceCluster.withCluster(
          connection -> connection.sync().smembers(MANAGER_SET_KEY));
      peerIds.remove(managerId);

      for (final String peerId : peerIds) {
        final boolean peerMissing = presenceCluster.withCluster(
            connection -> connection.sync().publish(getManagerPresenceChannel(peerId), "ping") == 0);

        if (peerMissing) {
          log.debug("Presence manager {} did not respond to ping", peerId);

          final String connectedClientsKey = getConnectedClientSetKey(peerId);

          String presenceKey;

          while ((presenceKey = presenceCluster.withCluster(connection -> connection.sync().spop(connectedClientsKey)))
              != null) {
            clearPresenceScript.execute(List.of(presenceKey), List.of(peerId));
            pruneClientMeter.increment();
          }

          presenceCluster.useCluster(connection -> {
            connection.sync().del(connectedClientsKey);
            connection.sync().srem(MANAGER_SET_KEY, peerId);
          });
        }
      }
    });
  }
@Test
  void testPruneMissingPeers() {
    final String presentPeerId = UUID.randomUUID().toString();
    final String missingPeerId = UUID.randomUUID().toString();

    REDIS_CLUSTER_EXTENSION.getRedisCluster().useCluster(connection -> {
      connection.sync().sadd(ClientPresenceManager.MANAGER_SET_KEY, presentPeerId);
      connection.sync().sadd(ClientPresenceManager.MANAGER_SET_KEY, missingPeerId);
    });

    for (int i = 0; i < 10; i++) {
      addClientPresence(presentPeerId);
      addClientPresence(missingPeerId);
    }

    clientPresenceManager.getPubSubConnection().usePubSubConnection(
        connection -> connection.sync().upstream().commands()
            .subscribe(ClientPresenceManager.getManagerPresenceChannel(presentPeerId)));
    clientPresenceManager.pruneMissingPeers();

    assertEquals(1, (long) REDIS_CLUSTER_EXTENSION.getRedisCluster().withCluster(
        connection -> connection.sync().exists(ClientPresenceManager.getConnectedClientSetKey(presentPeerId))));
    assertTrue(REDIS_CLUSTER_EXTENSION.getRedisCluster().withCluster(
        (Function<StatefulRedisClusterConnection<String, String>, Boolean>) connection -> connection.sync()
            .sismember(ClientPresenceManager.MANAGER_SET_KEY, presentPeerId)));

    assertEquals(0, (long) REDIS_CLUSTER_EXTENSION.getRedisCluster().withCluster(
        connection -> connection.sync().exists(ClientPresenceManager.getConnectedClientSetKey(missingPeerId))));
    assertFalse(REDIS_CLUSTER_EXTENSION.getRedisCluster().withCluster(
        (Function<StatefulRedisClusterConnection<String, String>, Boolean>) connection -> connection.sync()
            .sismember(ClientPresenceManager.MANAGER_SET_KEY, missingPeerId)));
  }