summaryrefslogtreecommitdiff
path: root/include/modules/redis.h
blob: 82ce5c0adbe10a6322ae4fd2b5ba1127ffc7c611 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 *
 * (C) 2003-2023 Anope Team
 * Contact us at team@anope.org
 *
 * Please read COPYING and README for further details.
 */

namespace Redis
{
	struct Reply
	{
		enum Type
		{
			NOT_PARSED,
			NOT_OK,
			OK,
			INT,
			BULK,
			MULTI_BULK
		}
		type;

		Reply() { Clear(); }
		~Reply() { Clear(); }

		void Clear()
		{
			type = NOT_PARSED;
			i = 0;
			bulk.clear();
			multi_bulk_size = 0;
			for (unsigned j = 0; j < multi_bulk.size(); ++j)
				delete multi_bulk[j];
			multi_bulk.clear();
		}

		int64_t i;
		Anope::string bulk;
		int multi_bulk_size;
		std::deque<Reply *> multi_bulk;
	};

	class Interface
	{
	 public:
		Module *owner;

		Interface(Module *m) : owner(m) { }
		virtual ~Interface() { }

		virtual void OnResult(const Reply &r) = 0;
		virtual void OnError(const Anope::string &error) { Log(owner) << error; }
	};

	class Provider : public Service
	{
	 public:
		Provider(Module *c, const Anope::string &n) : Service(c, "Redis::Provider", n) { }

		virtual bool IsSocketDead() = 0;

		virtual void SendCommand(Interface *i, const std::vector<Anope::string> &cmds) = 0;
		virtual void SendCommand(Interface *i, const Anope::string &str) = 0;

		virtual bool BlockAndProcess() = 0;

		virtual void Subscribe(Interface *i, const Anope::string &pattern) = 0;
		virtual void Unsubscribe(const Anope::string &pattern) = 0;

		virtual void StartTransaction() = 0;
		virtual void CommitTransaction() = 0;
	};
}