-
Notifications
You must be signed in to change notification settings - Fork 3
/
qReadisTest.cpp
105 lines (79 loc) · 3.23 KB
/
qReadisTest.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "qReadisTest.h"
qReadisTest::qReadisTest(QObject *parent) : QObject(parent)
{}
qReadisTest::~qReadisTest()
{
delete redis;
}
void qReadisTest::slotMessage(qRedis::Reply reply)
{
QTime time;
qDebug() << time.currentTime();
qDebug() << "Channel:" << reply.channel << "Pattern:" << reply.pattern;
qDebug() << reply.value.toString();
}
void qReadisTest::startTest()
{
redis = new qRedis("localhost",6379);
connect(redis, SIGNAL(returnData(qRedis::Reply)), this, SLOT(slotMessage(qRedis::Reply)));
qRedis::Reply reply;
if (!redis->openConnection())
{
qDebug() << "Could not connect to server...";
exit(0);
}
qDebug() << "Connected to server...";
//qDebug() << "AUTH:" << redis->auth("redisZzZ");
QString values = " {\"id:5411113430101\",\" filepath\":\"/home/bxd/0000.jpg\",\" externsion\":\"jpg\"}";
qDebug()<<"LPUSH"<<redis->lpush("bxd",values);
// Set and Get example
qDebug() << "SET:" << redis->set("key", "\"Hello World\"");
qDebug() << "GET:" << redis->get("key");
// Append to Key example
qDebug() << "SET:" << redis->set("key", "\"Hello\"");
qDebug() << "EXISTS:" << redis->exists("key");
qDebug() << "GET:" << redis->get("key");
qDebug() << "APPEND:" << redis->append("key", "\" World\"");
qDebug() << "GET:" << redis->get("key");
// Multi Set and Get example
QMap<QString,QVariant> keypairs;
keypairs["key1"] = QString("\"Hello\"");
keypairs["key2"] = QString("\" world\"");
qDebug() << "MSET:" << redis->mset(keypairs);
qDebug() << "MGET:" << redis->mget("key1 key2 nonexisting");
// Incr, incrby decr, decrby example.
qDebug() << "SET:" << redis->set("count", "10");
qDebug() << "INCR:" << redis->incr("count");
qDebug() << "GET:" << redis->get("count");
qDebug() << "INCRBY:" << redis->incrby("count",5);
qDebug() << "GET:" << redis->get("count");
qDebug() << "DECR:" << redis->decr("count");
qDebug() << "GET:" << redis->get("count");
qDebug() << "DECRBY:" << redis->decrby("count",5);
qDebug() << "GET:" << redis->get("count");
// SET and GET Range examples
qDebug() << "SETRANGE:" << redis->setrange("key",6 ,"Redis");
qDebug() << "GET:" << redis->get("key");
qDebug() << "GETRANGE:" << redis->getrange("key",-5 ,-1);
qDebug() << "GETRANGE:" << redis->getrange("key",0 ,4);
qDebug() << "GETRANGE:" << redis->getrange("key",0 ,-1);
//Hashmap example
qDebug() << "HSET:" << redis->hset("hashmap","key1" ,"value1");
qDebug() << "HSET:" << redis->hset("hashmap","key2" ,"value2");
qDebug() << "HSET:" << redis->hset("hashmap","key3" ,"value3");
qDebug() << "HGETALL:";
QMap<QString,QVariant> hashmap = redis->hgetall("hashmap");
QMapIterator<QString, QVariant> mi(hashmap);
while (mi.hasNext())
{
mi.next();
qDebug() << mi.key() << "=" << mi.value().toString();
}
// Raw Command example
reply = redis->command("GET key");
qDebug() << "RAW:" << "("<< reply.type << ")" << reply.value.toString();
redis->subscribe("notifications");
redis->psubscribe("news.*");
//reply = redis->command("SUBSCRIBE notifications");
//qDebug() << "("<< reply.type << ")" << reply.value.toStringList();
}