-
Notifications
You must be signed in to change notification settings - Fork 275
/
Copy pathpubsub.h
42 lines (32 loc) · 1.22 KB
/
pubsub.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include <map>
#include <deque>
#include <utility>
#include "dbconnector.h"
#include "select.h"
#include "redisselect.h"
namespace swss {
typedef std::pair<int, std::map<std::string, std::string> > MessageResultPair;
// This class is to emulate python redis-py class PubSub
// After SWIG wrapping, it should be used in the same way
class PubSub : protected RedisSelect
{
public:
explicit PubSub(DBConnector *other);
std::map<std::string, std::string> get_message(double timeout = 0.0, bool interrupt_on_signal = false);
std::map<std::string, std::string> listen_message(bool interrupt_on_signal = false);
void psubscribe(const std::string &pattern);
void punsubscribe(const std::string &pattern);
/* Read keyspace event from redis */
uint64_t readData() override;
bool hasData() override;
bool hasCachedData() override;
private:
/* Pop keyspace event from event buffer. Caller should free resources. */
std::shared_ptr<RedisReply> popEventBuffer();
MessageResultPair get_message_internal(double timeout = 0.0, bool interrupt_on_signal = false);
DBConnector *m_parentConnector;
Select m_select;
std::deque<std::shared_ptr<RedisReply>> m_keyspace_event_buffer;
};
}