/** * * @file RedisSubscriberImpl.h * @author Nitromelon * * Copyright 2022, Nitromelon. All rights reserved. * https://github.com/drogonframework/drogon * Use of this source code is governed by a MIT license * that can be found in the License file. * * Drogon * */ #pragma once #include #include "RedisConnection.h" #include "SubscribeContext.h" #include #include #include #include namespace drogon::nosql { class RedisSubscriberImpl : public RedisSubscriber, public std::enable_shared_from_this { public: ~RedisSubscriberImpl() override; void subscribe(const std::string &channel, RedisMessageCallback &&messageCallback) noexcept override; void psubscribe(const std::string &pattern, RedisMessageCallback &&messageCallback) noexcept override; void unsubscribe(const std::string &channel) noexcept override; void punsubscribe(const std::string &pattern) noexcept override; // Set a connected connection to subscriber. void setConnection(const RedisConnectionPtr &conn); // Clear connection and task queue. void clearConnection(); // Subscribe next channel in task queue. void subscribeNext(); // Subscribe all channels. void subscribeAll(); private: RedisConnectionPtr conn_; std::unordered_map> subContexts_; std::unordered_map> psubContexts_; std::list>> tasks_; std::mutex mutex_; }; } // namespace drogon::nosql