From 45e7ada7dca5448ea636293a34bd5f73a613e843 Mon Sep 17 00:00:00 2001 From: Nathan Osman Date: Thu, 4 Jul 2013 09:43:29 -0700 Subject: [PATCH] Implemented parsing of bulk replies and added test for data storage. --- src/client.cpp | 14 ++++++++++++++ tests/testclient.cpp | 17 +++++++++++++++++ tests/testclient.h | 1 + 3 files changed, 32 insertions(+) diff --git a/src/client.cpp b/src/client.cpp index b311d9c..5b46bc7 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -54,6 +54,20 @@ bool ClientPrivate::readInteger() 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; } diff --git a/tests/testclient.cpp b/tests/testclient.cpp index 4c10348..4802db0 100644 --- a/tests/testclient.cpp +++ b/tests/testclient.cpp @@ -27,3 +27,20 @@ void TestClient::testPing() QCOMPARE(spy.count(), 1); 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")); +} diff --git a/tests/testclient.h b/tests/testclient.h index 3e6b9d1..02235c1 100644 --- a/tests/testclient.h +++ b/tests/testclient.h @@ -15,6 +15,7 @@ class TestClient : public QObject void cleanupTestCase(); void testPing(); + void testStorage(); private: