void test_bitcount(client &c) { c.flushdb(); c.set("mykey", "foobar"); assert(c.bitcount("mykey")==26); assert(c.bitcount("mykey", {0,0})==4); assert(c.bitcount("mykey", {1,1})==6); assert(c.bitcount("nonexist", {8,12})==0); }
void test_sort(client &c) { c.flushdb(); c.lpush("mylist", {"c"}); c.lpush("mylist", {"b", "a"}); assert((c.sort("mylist", client::sort_criteria().alpha())==std::list<std::string> {"a", "b", "c"})); assert((c.sort("mylist", client::sort_criteria().alpha().desc())==std::list<std::string> {"c", "b", "a"})); assert(c.sort("mylist", client::sort_criteria().alpha().desc(), "mylist2")==3); assert((c.lrange("mylist2", 0, 100)==std::list<std::string> {"c", "b", "a"})); }
void test_get_set(client &c) { c.flushdb(); c.set("k1", "v1"); assert(*c.get("k1")=="v1"); c.set("k1", "v2"); assert(*c.get("k1")=="v2"); assert(!c.get("nonexist")); c.set("mykey", "10.5"); c.incrbyfloat("mykey", "0.1"); assert(*(c.get("mykey"))=="10.6"); }
void test_sscan(client &c) { c.flushdb(); std::set<std::string> expected; for (int i=42; i<442; i++) { std::string k("key"); k+=boost::lexical_cast<std::string>(i); c.sadd("myset", {k}); expected.insert(k); } std::set<std::string> keys; for(auto i=c.sscan("myset"); i!=c.end(); ++i) { keys.insert(*i); } assert(keys==expected); }
void test_zscan(client &c) { c.flushdb(); std::set<std::string> expected; for (int i=42; i<442; i++) { std::string k("key"); k+=boost::lexical_cast<std::string>(i); c.zadd("myzset", {{1.2, k}}); expected.insert(k); } std::set<std::string> keys; for(auto i=c.zscan("myzset"); i!=c.end(); ++i) { keys.insert(*i); assert(i.score()==1.2); } assert(keys==expected); }
void test_hscan(client &c) { c.flushdb(); std::set<std::string> expected; for (int i=42; i<442; i++) { std::string k("key"); k+=boost::lexical_cast<std::string>(i); std::string v("key"); v+=boost::lexical_cast<std::string>(i); c.hset("myhash", k, v); expected.insert(k); } std::set<std::string> keys; for(auto i=c.hscan("myhash"); i!=c.end(); ++i) { keys.insert(*i); } assert(keys==expected); }