-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCppRedisTest.cpp
More file actions
60 lines (51 loc) · 1.58 KB
/
Copy pathCppRedisTest.cpp
File metadata and controls
60 lines (51 loc) · 1.58 KB
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
#include "CppRedisTest.h"
CppRedisTest::CppRedisTest(QObject *parent) :
QObject(parent),
_redisInterface(new RedisInterface("http://localhost:7379/", this)),
_timer(new QTimer())
{
_redisInterface->subscribeToEvent("event:from:redis", "eventFromRedis");
_redisInterface->publishEvent("eventFromCpp", "event:from:cpp");
_redisInterface->publishProperty("propertyFromCpp", "property:from:cpp");
_redisInterface->subscribeToProperty("property:from:redis", "propertyFromRedis");
_timer->setInterval(1000);
_timer->setSingleShot(false);
connect(_timer, SIGNAL(timeout()), this, SLOT(update()));
_timer->start();
}
QString CppRedisTest::propertyFromCpp() const
{
return _propertyFromCpp;
}
QString CppRedisTest::propertyFromRedis() const
{
return _propertyFromRedis;
}
void CppRedisTest::eventFromRedis()
{
qDebug() << "(C++) eventFromRedis() called";
}
void CppRedisTest::setPropertyFromCpp(QString arg)
{
if (_propertyFromCpp != arg) {
_propertyFromCpp = arg;
emit propertyFromCppChanged(arg);
}
}
void CppRedisTest::setPropertyFromRedis(QString arg)
{
if (_propertyFromRedis != arg) {
_propertyFromRedis = arg;
emit propertyFromRedisChanged(arg);
}
}
void CppRedisTest::update()
{
emit eventFromCpp();
setPropertyFromCpp(QString(rand()));
_redisInterface->get("test:meta:value", RedisInterface::getSlot(this, "getRequestResponse(QString, QVariant)"));
}
void CppRedisTest::getRequestResponse(QString key, QVariant value)
{
qDebug() << "(C++) Get request response:" << key << "==" << value;
}