本文整理汇总了C++中Ardb类的典型用法代码示例。如果您正苦于以下问题:C++ Ardb类的具体用法?C++ Ardb怎么用?C++ Ardb使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ardb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_strings_strlen
void test_strings_strlen(Ardb& db)
{
DBID dbid = 0;
db.Set(dbid, "skey", "abcabcabc");
int len = db.Strlen(dbid, "skey");
CHECK_FATAL(len != 9, "Strlen failed:%d", len);
}
示例2: main
int main(int argc, char** argv)
{
std::string dir;
if (argc >= 2)
{
int j = 1; /* First option to parse in argv[] */
char *dirfile = NULL;
/* Handle special options --help and --version */
if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)
version();
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0)
usage();
/* First argument is the config file name? */
if (argv[j][0] != '-' || argv[j][1] != '-')
{
dirfile = argv[j++];
dir = dirfile;
}
}
else
{
printf("Warning: no database dir specified to repair.\n");
return -1;
}
Ardb db;
return db.Repair(dir);
}
示例3: test_strings_getrange
void test_strings_getrange(Ardb& db)
{
DBID dbid = 0;
std::string v;
db.Set(dbid, "skey", "abcabc");
db.GetRange(dbid, "skey", 4, -1, v);
CHECK_FATAL(v != "bc", "GetRange failed");
}
示例4: test_strings_exists
void test_strings_exists(Ardb& db)
{
DBID dbid = 0;
db.Del(dbid, "intkey1");
CHECK_FATAL(db.Exists(dbid, "intkey1"), "Exists intkey1 failed");
db.Set(dbid, "intkey1", "123");
CHECK_FATAL(db.Exists(dbid, "intkey1") == false, "Exists intkey failed");
}
示例5: test_strings_setnx
void test_strings_setnx(Ardb& db)
{
DBID dbid = 0;
db.Set(dbid, "intkey1", "123");
CHECK_FATAL(db.SetNX(dbid, "intkey1", "2345") == 0, "SetNX intkey failed");
db.Del(dbid, "intkey1");
CHECK_FATAL(db.SetNX(dbid, "intkey1", "2345") != 0, "SetNX intkey failed");
}
示例6: test_strings_getset
void test_strings_getset(Ardb& db)
{
DBID dbid = 0;
std::string v;
db.Set(dbid, "skey", "abcabc");
db.GetSet(dbid, "skey", "edfgth", v);
CHECK_FATAL(v != "abcabc", "GetSet failed:%s", v.c_str());
}
示例7: test_strings_setrange
void test_strings_setrange(Ardb& db)
{
DBID dbid = 0;
std::string v;
db.Set(dbid, "skey", "abcabc");
db.SetRange(dbid, "skey", 3, "12345");
db.Get(dbid, "skey", v);
CHECK_FATAL(v != "abc12345", "SetRange failed:%s", v.c_str());
}
示例8: test_strings_expire
void test_strings_expire(Ardb& db)
{
DBID dbid = 0;
ValueData v;
db.Set(dbid, "intkey1", "123");
db.Expire(dbid, "intkey1", 1);
CHECK_FATAL(db.Exists(dbid, "intkey1") == false, "Expire intkey1 failed");
sleep(2);
CHECK_FATAL(db.Exists(dbid, "intkey1") == true, "Expire intkey failed");
}
示例9: test_set_expire
void test_set_expire(Ardb& db)
{
DBID dbid = 0;
db.SClear(dbid, "myset");
db.SAdd(dbid, "myset", "123");
db.Expire(dbid, "myset", 1);
CHECK_FATAL(db.Exists(dbid, "myset") == false, "Expire myset failed");
sleep(2);
CHECK_FATAL(db.Exists(dbid, "myset") == true, "Expire myset failed");
}
示例10: test_strings_decr
void test_strings_decr(Ardb& db)
{
DBID dbid = 0;
db.Set(dbid, "intkey", "10");
int64_t iv = 0;
db.Decr(dbid, "intkey", iv);
CHECK_FATAL(iv != 9, "Decr1 failed %"PRId64, iv);
db.Decrby(dbid, "intkey", 2, iv);
CHECK_FATAL(iv != 7, "Decrby failed: %"PRId64, iv);
}
示例11: test_zset_expire
void test_zset_expire(Ardb& db)
{
DBID dbid = 0;
db.ZClear(dbid, "myzset");
db.ZAdd(dbid, "myzset", ValueData((int64) 1), "one");
db.Expire(dbid, "myzset", 1);
CHECK_FATAL(db.Exists(dbid, "myzset") == false, "Expire myzset failed");
sleep(2);
CHECK_FATAL(db.Exists(dbid, "myzset") == true, "Expire myzset failed");
}
示例12: test_set_union
void test_set_union(Ardb& db)
{
DBID dbid = 0;
db.SClear(dbid, "myset1");
db.SClear(dbid, "myset2");
db.SClear(dbid, "myset3");
db.SAdd(dbid, "myset1", "a");
db.SAdd(dbid, "myset1", "b");
db.SAdd(dbid, "myset1", "c");
db.SAdd(dbid, "myset1", "d");
db.SAdd(dbid, "myset2", "c");
db.SAdd(dbid, "myset3", "a");
db.SAdd(dbid, "myset3", "c");
db.SAdd(dbid, "myset3", "e");
SliceArray keys;
keys.push_back("myset1");
keys.push_back("myset2");
keys.push_back("myset3");
ValueArray values;
db.SUnion(dbid, keys, values);
CHECK_FATAL(values.size() != 5, "SUnion failed:");
std::string str;
CHECK_FATAL( values.begin()->ToString(str) != "a", "SUnion store failed:");
db.SUnionStore(dbid, "myset2", keys);
CHECK_FATAL(db.SCard(dbid, "myset2") != 5, "SUnionStore myset2 failed:");
}
示例13: test_set_inter
void test_set_inter(Ardb& db)
{
DBID dbid = 0;
db.SClear(dbid, "myset1");
db.SClear(dbid, "myset2");
db.SClear(dbid, "myset3");
db.SAdd(dbid, "myset1", "a");
db.SAdd(dbid, "myset1", "b");
db.SAdd(dbid, "myset1", "c");
db.SAdd(dbid, "myset1", "d");
db.SAdd(dbid, "myset2", "c");
db.SAdd(dbid, "myset3", "a");
db.SAdd(dbid, "myset3", "c");
db.SAdd(dbid, "myset3", "e");
SliceArray keys;
keys.push_back("myset1");
keys.push_back("myset2");
keys.push_back("myset3");
ValueSet values;
db.SInter(dbid, keys, values);
std::string str;
CHECK_FATAL( values.size() != 1, "Sinter failed:");
CHECK_FATAL(values.begin()->ToString(str) != "c", "Sinter store failed:");
db.SInterStore(dbid, "myset2", keys);
CHECK_FATAL( db.SCard(dbid, "myset2") != 1, "SInterStore myset2 failed:");
}
示例14: test_set_diff
void test_set_diff(Ardb& db)
{
DBID dbid = 0;
db.SClear(dbid, "myset1");
db.SClear(dbid, "myset2");
db.SClear(dbid, "myset3");
db.SAdd(dbid, "myset1", "a");
db.SAdd(dbid, "myset1", "b");
db.SAdd(dbid, "myset1", "c");
db.SAdd(dbid, "myset1", "d");
db.SAdd(dbid, "myset2", "c");
db.SAdd(dbid, "myset3", "a");
db.SAdd(dbid, "myset3", "c");
db.SAdd(dbid, "myset3", "e");
std::string str;
SliceArray keys;
keys.push_back("myset1");
keys.push_back("myset2");
keys.push_back("myset3");
ValueSet values;
db.SDiff(dbid, keys, values);
CHECK_FATAL(values.size() != 2, "Sdiff failed:");
CHECK_FATAL(values.begin()->ToString(str) != "b", "Sdiff store failed:");
//CHECK_FATAL(FATAL, values[1] != "d") << "Sdiff store failed:";
int len = db.SDiffStore(dbid, "myset2", keys);
CHECK_FATAL(len != 2, "SDiffStore myset2 failed:%d", len);
len = db.SCard(dbid, "myset2");
CHECK_FATAL(len != 2, "SDiffStore myset2 failed:%d", len);
}
示例15: test_strings_incr
void test_strings_incr(Ardb& db)
{
DBID dbid = 0;
db.Set(dbid, "intkey", "12");
int64_t iv = 0;
db.Incrby(dbid, "intkey", 2, iv);
CHECK_FATAL(iv != 14, "Incrby failed");
double dv;
db.IncrbyFloat(dbid, "intkey", 1.23, dv);
CHECK_FATAL(dv != 15.23, "IncrbyFloat failed");
}