| 490 | } |
| 491 | |
| 492 | void Server::UnsubscribeChannel(const std::string &channel, redis::Connection *conn) { |
| 493 | std::lock_guard<std::mutex> guard(pubsub_channels_mu_); |
| 494 | |
| 495 | auto iter = pubsub_channels_.find(channel); |
| 496 | if (iter == pubsub_channels_.end()) { |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | for (const auto &conn_ctx : iter->second) { |
| 501 | if (conn->GetFD() == conn_ctx.fd && conn->Owner() == conn_ctx.owner) { |
| 502 | iter->second.remove(conn_ctx); |
| 503 | if (iter->second.empty()) { |
| 504 | pubsub_channels_.erase(iter); |
| 505 | } |
| 506 | break; |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | void Server::GetChannelsByPattern(const std::string &pattern, std::vector<std::string> *channels) { |
| 512 | std::lock_guard<std::mutex> guard(pubsub_channels_mu_); |