feat(server): Add support for PFADD and PFCOUNT (#1152)

* feat(server): Add support for PFADD and PFCOUNT

This version does not create sparse-encoded HLLs, however it is fully compatible with such ones created by Redis as it converts them to the dense encoding.

Note that PFMERGE is not yet implemented.

* Set small string optimization to be 2^13 instead of 2^15.

This will allow dense-encoded HLL to *not* fit within the small string,
which will make it contiguous in memory, thus GetSlice() will not
allocate.

---------

Signed-off-by: chakaz <chakaz@chakaz>
Co-authored-by: chakaz <chakaz@chakaz>
This commit is contained in:
Chaka 2023-04-30 00:50:11 +03:00 committed by GitHub
parent b09a36d553
commit fa39c1890d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 1509 additions and 5 deletions

View file

@ -346,4 +346,30 @@ TEST_F(RdbTest, JsonTest) {
}
}
// hll.rdb has 2 keys: "key-dense" and "key-sparse", both are HLL with a single added value "1".
class HllRdbTest : public RdbTest, public testing::WithParamInterface<string> {};
TEST_P(HllRdbTest, Hll) {
io::FileSource fs = GetSource("hll.rdb");
RdbLoader loader{service_.get()};
// must run in proactor thread in order to avoid polluting the serverstate
// in the main, testing thread.
auto ec = pp_->at(0)->Await([&] { return loader.Load(&fs); });
ASSERT_FALSE(ec) << ec.message();
EXPECT_EQ(CheckedInt({"pfcount", GetParam()}), 1);
EXPECT_EQ(CheckedInt({"pfcount", GetParam(), "non-existing"}), 1);
EXPECT_EQ(CheckedInt({"pfadd", "key2", "2"}), 1);
EXPECT_EQ(CheckedInt({"pfcount", GetParam(), "key2"}), 2);
EXPECT_EQ(CheckedInt({"pfadd", GetParam(), "2"}), 1);
EXPECT_EQ(CheckedInt({"pfcount", GetParam()}), 2);
}
INSTANTIATE_TEST_SUITE_P(HllRdbTest, HllRdbTest, Values("key-sparse", "key-dense"));
} // namespace dfly