@@ -1296,6 +1296,61 @@ static int simple_test_cmd_hdel(vire_instance *vi)
1296
1296
return 0 ;
1297
1297
}
1298
1298
1299
+ static int simple_test_cmd_pfadd_pfcount (vire_instance * vi )
1300
+ {
1301
+ char * key = "test_cmd_pfadd_pfcount-key" ;
1302
+ char * value = "test_cmd_pfadd_pfcount-value" ;
1303
+ char * MESSAGE = "PFADD/PFCOUNT simple test" ;
1304
+ redisReply * reply = NULL ;
1305
+ int n = 0 , count = 20329 , repeat ;
1306
+
1307
+ while (repeat < 2 ) {
1308
+ int expect_count ;
1309
+ reply = redisCommand (vi -> ctx , "pfadd %s %s%d" , key , value , n ++ );
1310
+ if (reply == NULL || reply -> type != REDIS_REPLY_INTEGER ) {
1311
+ goto error ;
1312
+ }
1313
+ freeReplyObject (reply );
1314
+ if (n >= count ) {
1315
+ repeat ++ ;
1316
+ n = 0 ;
1317
+ }
1318
+
1319
+ if (repeat == 0 ) {
1320
+ expect_count = n ;
1321
+ } else {
1322
+ expect_count = count ;
1323
+ }
1324
+
1325
+ reply = redisCommand (vi -> ctx , "pfcount %s" , key );
1326
+ if (reply == NULL || reply -> type != REDIS_REPLY_INTEGER ) {
1327
+ goto error ;
1328
+ }
1329
+ if (reply -> integer != (long long )expect_count ) {
1330
+ float mistake = ((float )expect_count - (float )reply -> integer )/(float )expect_count ;
1331
+ if (mistake < -0.02 || mistake > 0.02 ) {
1332
+ vrt_scnprintf (errmsg , LOG_MAX_LEN , "pfadd %d different elements is not approximated pfcount returned %lld, mistake %f" ,
1333
+ expect_count , reply -> integer , mistake );
1334
+ goto error ;
1335
+ }
1336
+ }
1337
+ freeReplyObject (reply );
1338
+ }
1339
+
1340
+ show_test_result (VRT_TEST_OK ,MESSAGE ,errmsg );
1341
+
1342
+ return 1 ;
1343
+
1344
+ error :
1345
+
1346
+ if (reply ) freeReplyObject (reply );
1347
+
1348
+ show_test_result (VRT_TEST_ERR ,MESSAGE ,errmsg );
1349
+ errmsg [0 ] = '\0' ;
1350
+
1351
+ return 0 ;
1352
+ }
1353
+
1299
1354
int simple_test (void )
1300
1355
{
1301
1356
vire_instance * vi ;
@@ -1331,6 +1386,8 @@ int simple_test(void)
1331
1386
ok_count += simple_test_cmd_hget_hset (vi ); all_count ++ ;
1332
1387
ok_count += simple_test_cmd_hlen (vi ); all_count ++ ;
1333
1388
ok_count += simple_test_cmd_hdel (vi ); all_count ++ ;
1389
+ /* HyperLogLog */
1390
+ ok_count += simple_test_cmd_pfadd_pfcount (vi ); all_count ++ ;
1334
1391
1335
1392
vire_instance_destroy (vi );
1336
1393
0 commit comments