Implemented parsing of bulk replies and added test for data storage.
This commit is contained in:
parent
e049215a70
commit
45e7ada7dc
|
|
@ -54,6 +54,20 @@ bool ClientPrivate::readInteger()
|
||||||
|
|
||||||
bool ClientPrivate::readBulk()
|
bool ClientPrivate::readBulk()
|
||||||
{
|
{
|
||||||
|
/* Check if the reply contains \r\n. */
|
||||||
|
int pos = buffer.indexOf("\r\n");
|
||||||
|
if(pos != -1)
|
||||||
|
{
|
||||||
|
int length = buffer.mid(1, pos -1).toInt();
|
||||||
|
if(buffer.size() >= pos + length + 4)
|
||||||
|
{
|
||||||
|
emit queue.dequeue()->bulk(buffer.mid(pos + 2, length));
|
||||||
|
|
||||||
|
buffer.remove(0, pos + length + 4);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,3 +27,20 @@ void TestClient::testPing()
|
||||||
QCOMPARE(spy.count(), 1);
|
QCOMPARE(spy.count(), 1);
|
||||||
QCOMPARE(spy[0][0].toString(), QString("PONG"));
|
QCOMPARE(spy[0][0].toString(), QString("PONG"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestClient::testStorage()
|
||||||
|
{
|
||||||
|
QRedis::Request * request1 = client.sendCommand("SET value 10");
|
||||||
|
QSignalSpy spy1(request1, SIGNAL(status(QString)));
|
||||||
|
|
||||||
|
QVERIFY(request1->waitForReply());
|
||||||
|
QCOMPARE(spy1.count(), 1);
|
||||||
|
QCOMPARE(spy1[0][0].toString(), QString("OK"));
|
||||||
|
|
||||||
|
QRedis::Request * request2 = client.sendCommand("GET value");
|
||||||
|
QSignalSpy spy2(request2, SIGNAL(bulk(QByteArray)));
|
||||||
|
|
||||||
|
QVERIFY(request2->waitForReply());
|
||||||
|
QCOMPARE(spy2.count(), 1);
|
||||||
|
QCOMPARE(spy2[0][0].toByteArray(), QByteArray("10"));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ class TestClient : public QObject
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
|
|
||||||
void testPing();
|
void testPing();
|
||||||
|
void testStorage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue