Exemple #1
0
void test_zsets_zcount(Ardb& db)
{
    DBID dbid = 0;
    db.ZClear(dbid, "myzset");
    db.ZAdd(dbid, "myzset", ValueData((int64) 1), "one");
    db.ZAdd(dbid, "myzset", ValueData((int64) 2), "two");
    db.ZAdd(dbid, "myzset", ValueData((int64) 3), "three");
    int count = db.ZCount(dbid, "myzset", "-inf", "+inf");
    CHECK_FATAL(count != 3, "Fail:%d", count);
    count = db.ZCount(dbid, "myzset", "(1", "3");
    CHECK_FATAL(count != 2, "Fail:%d", count);
}
Exemple #2
0
void test_zsets_zrank(Ardb& db)
{
    DBID dbid = 0;
    db.ZClear(dbid, "myzset");
    db.ZAdd(dbid, "myzset", ValueData((int64) 1), "one");
    db.ZAdd(dbid, "myzset", ValueData((int64) 2), "two");
    db.ZAdd(dbid, "myzset", ValueData((int64) 3), "three");
    db.ZCount(dbid, "myzset", "-inf", "+inf");
    int rank = db.ZRank(dbid, "myzset", "three");
    CHECK_FATAL(rank != 2, "Fail:%d", rank);

    db.ZClear(dbid, "myzset");
    uint32 maxzsetsize = 100000;
    uint64 start = get_current_epoch_millis();
    for (uint32 i = 0; i < maxzsetsize; i++)
    {
        char value[16];
        sprintf(value, "value%u", i);
        db.ZAdd(dbid, "myzset", ValueData((int64) i), value);
    }
    uint64 end = get_current_epoch_millis();
    INFO_LOG("Cost %lldms to write %u zset elements", (end - start), maxzsetsize);
    start = get_current_epoch_millis();
    rank = db.ZRank(dbid, "myzset", "value50001");
    CHECK_FATAL(rank != 50001, "Fail:%d", rank);
    end = get_current_epoch_millis();
    INFO_LOG("Cost %lldms to rank.", (end - start));
}