Commit f8c03c61 authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Implement locator for lease keys

parent 6eea0e6b
......@@ -38,7 +38,8 @@ enum class KeyType : char {
kHash = 'b',
kSet = 'c',
kList = 'd',
kLocalityHash = 'e'
kLocalityHash = 'e',
kLease = 'f'
};
inline KeyType parseKeyType(char c) {
......
......@@ -245,6 +245,25 @@ private:
KeyBuffer keyBuffer;
};
class LeaseLocator {
public:
LeaseLocator(const std::string &redisKey) {
reset(redisKey);
}
void reset(const std::string &redisKey) {
keyBuffer.resize(redisKey.size() + 1);
keyBuffer[0] = char(KeyType::kLease);
memcpy(keyBuffer.data()+1, redisKey.data(), redisKey.size());
}
rocksdb::Slice toSlice() {
return keyBuffer.toSlice();
}
private:
KeyBuffer keyBuffer;
};
}
#endif
......@@ -847,6 +847,14 @@ TEST(LocalityIndexLocator, BasicSanity) {
ASSERT_EQ(revlocator.getOriginalKey().ToString(), "key##with##hashes");
}
TEST(LeaseLocator, BasicSanity) {
LeaseLocator locator1("my-key");
ASSERT_EQ(locator1.toSlice().ToString(), "fmy-key");
LeaseLocator locator2("my#key");
ASSERT_EQ(locator2.toSlice().ToString(), "fmy#key");
}
TEST(PatternMatching, BasicSanity) {
ASSERT_EQ(extractPatternPrefix("abc*"), "abc");
ASSERT_EQ(extractPatternPrefix("abc"), "abc");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment