44StringKeyModel::StringKeyModel (
55 QSharedPointer<RedisClient::Connection> connection, QByteArray fullPath,
66 int dbIndex, long long ttl)
7- : KeyModel(connection, fullPath, dbIndex, ttl) {}
7+ : KeyModel(connection, fullPath, dbIndex, ttl), m_type( " string " ) {}
88
9- QString StringKeyModel::type () { return " string " ; }
9+ QString StringKeyModel::type () { return m_type ; }
1010
1111QStringList StringKeyModel::getColumnNames () {
1212 return QStringList (); // Single value type - No columns
@@ -19,7 +19,7 @@ QHash<int, QByteArray> StringKeyModel::getRoles() {
1919}
2020
2121QVariant StringKeyModel::getData (int rowIndex, int dataRole) {
22- if (!isRowLoaded (rowIndex)) return QVariant ();
22+ if (rowIndex > 0 || !isRowLoaded (rowIndex)) return QVariant ();
2323 if (dataRole == Roles::Value) return m_rowsCache[rowIndex];
2424
2525 return QVariant ();
@@ -48,7 +48,17 @@ void StringKeyModel::updateRow(int rowIndex, const QVariantMap& row,
4848}
4949
5050void StringKeyModel::addRow (const QVariantMap& row, Callback c) {
51- updateRow (0 , row, c);
51+ if (m_type == " hyperloglog" ) {
52+ QByteArray value = row.value (" value" ).toByteArray ();
53+
54+ executeCmd (
55+ {" PFADD" , m_keyFullPath, value}, [this , c](const QString& err) {
56+ m_rowCount++;
57+ return c (err);
58+ });
59+ } else {
60+ updateRow (0 , row, c);
61+ }
5262}
5363
5464void StringKeyModel::loadRows (QVariant, unsigned long ,
@@ -59,9 +69,25 @@ void StringKeyModel::loadRows(QVariant, unsigned long,
5969
6070 auto responseHandler = [this , callback](RedisClient::Response r, Callback) {
6171 m_rowsCache.clear ();
62- m_rowsCache.push_back (r.value ().toByteArray ());
6372
64- callback (QString (), 1 );
73+ QByteArray value = r.value ().toByteArray ();
74+
75+ m_rowsCache.push_back (value);
76+ m_rowCount = 1 ;
77+
78+ // Detect HyperLogLog
79+ if (value.startsWith (" HYLL" )) {
80+ executeCmd (
81+ {" PFCOUNT" , m_keyFullPath}, [callback](const QString&) { callback (QString (), 1 ); },
82+ [this , callback](RedisClient::Response r, Callback) {
83+ m_type = " hyperloglog" ;
84+ m_rowCount = r.value ().toUInt ();
85+ callback (QString (), m_rowCount);
86+ },
87+ RedisClient::Response::Integer);
88+ } else {
89+ callback (QString (), 1 );
90+ }
6591 };
6692
6793 executeCmd ({" GET" , m_keyFullPath}, onConnectionError, responseHandler,
0 commit comments