本文整理汇总了C++中Ardb::ZRange方法的典型用法代码示例。如果您正苦于以下问题:C++ Ardb::ZRange方法的具体用法?C++ Ardb::ZRange怎么用?C++ Ardb::ZRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ardb
的用法示例。
在下文中一共展示了Ardb::ZRange方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_zsets_union
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: test_zsets_inter
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: test_zsets_addrem
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: test_zsets_zrange
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: test_zsets_incr
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());
}