Skip to content

Commit 0d9d8a5

Browse files
committed
Use async command execution in StringKey model
1 parent 4149606 commit 0d9d8a5

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

src/app/models/key-models/stringkey.cpp

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,23 @@ void StringKeyModel::addRow(const QVariantMap &row)
6868
}
6969

7070
void StringKeyModel::loadRows(unsigned long, unsigned long, std::function<void(const QString&)> callback)
71-
{
72-
if (loadValue()) {
73-
callback(QString());
71+
{
72+
try {
73+
m_connection->command({"GET", m_keyFullPath}, getConnector().data(),
74+
[this, callback](RedisClient::Response r, QString e)
75+
{
76+
if (r.getType() != RedisClient::Response::Bulk) {
77+
return callback(QString("Cannot load value"));
78+
}
79+
80+
m_rowsCache.clear();
81+
m_rowsCache.push_back(r.getValue().toByteArray());
82+
m_notifier->dataLoaded();
83+
84+
callback(QString());
85+
}, m_dbIndex);
86+
} catch (const RedisClient::Connection::Exception& e) {
87+
throw Exception("Connection error: " + QString(e.what()));
7488
}
7589
}
7690

@@ -79,24 +93,3 @@ void StringKeyModel::removeRow(int)
7993
m_rowCount--;
8094
setRemovedIfEmpty();
8195
}
82-
83-
bool StringKeyModel::loadValue()
84-
{
85-
RedisClient::Response result;
86-
try {
87-
result = m_connection->commandSync({"GET", m_keyFullPath}, m_dbIndex);
88-
} catch (const RedisClient::Connection::Exception& e) {
89-
throw Exception("Connection error: " + QString(e.what()));
90-
}
91-
92-
if (result.getType() != RedisClient::Response::Bulk) {
93-
return false;
94-
}
95-
96-
m_rowsCache.clear();
97-
m_rowsCache.push_back(result.getValue().toByteArray());
98-
99-
m_notifier->dataLoaded();
100-
101-
return true;
102-
}

src/app/models/key-models/stringkey.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class StringKeyModel : public KeyModel<QByteArray>
2121
void addLoadedRowsToCache(const QVariantList&, int) override {}
2222

2323
private:
24-
enum Roles { Value = Qt::UserRole + 1 };
25-
bool loadValue();
24+
enum Roles { Value = Qt::UserRole + 1 };
2625
};
2726

0 commit comments

Comments
 (0)