예제 #1
0
void test_zsets_union(Ardb& db)
{
    DBID dbid = 0;
    db.ZClear(dbid, "myzset1");
    db.ZClear(dbid, "myzset2");
    db.ZAdd(dbid, "myzset1", ValueData((int64) 1), "one");
    db.ZAdd(dbid, "myzset1", ValueData((int64) 2), "two");
    db.ZAdd(dbid, "myzset2", ValueData((int64) 1), "one");
    db.ZAdd(dbid, "myzset2", ValueData((int64) 2), "two");
    db.ZAdd(dbid, "myzset2", ValueData((int64) 3), "three");
    SliceArray keys;
    keys.push_back("myzset1");
    keys.push_back("myzset2");
    WeightArray ws;
    ws.push_back(10);
    ws.push_back(4);
    db.ZUnionStore(dbid, "myzset3", keys, ws);

    CHECK_FATAL(db.ZCard(dbid, "myzset3") != 3, "Fail:");
    ZSetQueryOptions options;
    options.withscores = true;
    ValueDataArray values;
    db.ZRange(dbid, "myzset3", 0, -1, values, options);
    std::string str;
    CHECK_FATAL(values.size() != 6, "Fail:%zu", values.size());
    CHECK_FATAL(values[0].ToString(str) != "three", "Fail:%s", values[0].ToString(str).c_str());
    CHECK_FATAL(values[2].ToString(str) != "one", "Fail:%s", values[2].ToString(str).c_str());
    CHECK_FATAL(values[4].ToString(str) != "two", "Fail:%s", values[4].ToString(str).c_str());
}
예제 #2
0
void test_zsets_inter(Ardb& db)
{
    DBID dbid = 0;
    db.ZClear(dbid, "myzset1");
    db.ZClear(dbid, "myzset2");
    db.ZAdd(dbid, "myzset1", ValueData((int64) 1), "one");
    db.ZAdd(dbid, "myzset1", ValueData((int64) 2), "two");
    db.ZAdd(dbid, "myzset2", ValueData((int64) 1), "one");
    db.ZAdd(dbid, "myzset2", ValueData((int64) 2), "two");
    db.ZAdd(dbid, "myzset2", ValueData((int64) 3), "three");
    SliceArray keys;
    keys.push_back("myzset1");
    keys.push_back("myzset2");
    WeightArray ws;
    ws.push_back(20);
    ws.push_back(4);
    db.ZInterStore(dbid, "myzset3", keys, ws);

    int zcard = db.ZCard(dbid, "myzset3");
    CHECK_FATAL(zcard != 2, "Fail:%d", zcard);
    ZSetQueryOptions options;
    options.withscores = true;
    ValueDataArray values;
    db.ZRange(dbid, "myzset3", 0, -1, values, options);
    std::string str;
    CHECK_FATAL(values.size() != 4, "Fail:%zu", values.size());
    CHECK_FATAL(values[0].ToString(str) != "one", "Fail:");
}
예제 #3
0
void test_zsets_addrem(Ardb& db)
{
    DBID dbid = 0;
    db.ZClear(dbid, "myzset");

    db.ZAdd(dbid, "myzset", ValueData((int64) 3), "v0");
    db.ZAdd(dbid, "myzset", ValueData((int64) 2), "v1");
    db.ZAdd(dbid, "myzset", ValueData((int64) 1), "v2");
    CHECK_FATAL(db.ZCard(dbid, "myzset") != 3, "zadd myzset failed:%d", db.ZCard(dbid, "myzset"));
    ValueData score((int64) 0);
    db.ZScore(dbid, "myzset", "v1", score);
    CHECK_FATAL(score.NumberValue() != 2, "zscore myzset failed:%f", score.NumberValue());

    db.ZAdd(dbid, "myzset", ValueData((int64) 0), "v2");
    CHECK_FATAL(db.ZCard(dbid, "myzset") != 3, "zadd myzset failed:%d", db.ZCard(dbid, "myzset"));
    db.ZRem(dbid, "myzset", "v2");
    CHECK_FATAL(db.ZCard(dbid, "myzset") != 2, "zrem myzset failed:%d", db.ZCard(dbid, "myzset"));
    ValueDataArray values;
    ZSetQueryOptions options;
    db.ZRange(dbid, "myzset", 0, -1, values, options);
    std::string str;
    CHECK_FATAL(values.size() != 2, "Fail:%zu", values.size());
    CHECK_FATAL(values[0].ToString(str) != "v1", "Fail:%s", values[0].ToString(str).c_str());
    CHECK_FATAL(values[1].ToString(str) != "v0", "Fail:%s", values[1].ToString(str).c_str());
}
예제 #4
0
void test_zsets_zrange(Ardb& db)
{
    DBID dbid = 0;
    db.ZClear(dbid, "myzset");
    db.ZAdd(dbid, "myzset", ValueData((int64) 1), "one");
    db.ZAdd(dbid, "myzset", ValueData((int64) 1), "uno");
    db.ZAdd(dbid, "myzset", ValueData((int64) 2), "two");
    db.ZAdd(dbid, "myzset", ValueData((int64) 3), "two");
    ZSetQueryOptions options;
    options.withscores = true;
    ValueDataArray values;
    db.ZRange(dbid, "myzset", 0, -1, values, options);
    std::string str;
    CHECK_FATAL(values.size() != 6, "Fail:%zu", values.size());
    CHECK_FATAL(values[0].ToString(str) != "one", "Fail:%s", values[0].ToString(str).c_str());
    CHECK_FATAL(values[2].ToString(str) != "uno", "Fail:%s", values[1].ToString(str).c_str());
    values.clear();
    db.ZRangeByScore(dbid, "myzset", "-inf", "+inf", values, options);
    CHECK_FATAL(values.size() != 6, "Fail:%zu", values.size());
    CHECK_FATAL(values[0].ToString(str) != "one", "Fail:%s", values[0].ToString(str).c_str());
    CHECK_FATAL(values[2].ToString(str) != "uno", "Fail:%s", values[1].ToString(str).c_str());
    values.clear();
    db.ZRangeByScore(dbid, "myzset", "(1", "3", values, options);
    CHECK_FATAL(values.size() != 2, "Fail:%zu", values.size());
    CHECK_FATAL(values[0].ToString(str) != "two", "Fail:%s", values[0].ToString(str).c_str());

    db.ZClear(dbid, "myzset");
    uint32 maxzsetsize = 1000;
    for (uint32 i = 0; i < maxzsetsize; i++)
    {
        char value[16];
        sprintf(value, "value%u", i);
        db.ZAdd(dbid, "myzset", ValueData((int64) i), value);
    }
    options.withscores = false;
    values.clear();
    db.ZRange(dbid, "myzset", 1, 10, values, options);
    CHECK_FATAL(values.size() != 10, "Fail:%zu", values.size());
}
예제 #5
0
void test_zsets_incr(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");
    ValueData score;
    db.ZIncrby(dbid, "myzset", ValueData((int64) 2), "one", score);
    ZSetQueryOptions options;
    options.withscores = true;
    ValueDataArray values;
    db.ZRange(dbid, "myzset", 0, -1, values, options);
    std::string str;
    CHECK_FATAL(values.size() != 4, "Fail:%zu", values.size());
    CHECK_FATAL(values[0].ToString(str) != "two", "Fail:%s", values[0].ToString(str).c_str());
}