Skip to content

Commit 2d92bc7

Browse files
committed
refactor: drop trailing colon from redis key namespaces; tighten test fixture
1 parent fc17043 commit 2d92bc7

4 files changed

Lines changed: 23 additions & 25 deletions

File tree

libs/server-sdk-redis-source/src/redis_big_segment_store.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ namespace {
1414

1515
// Schema strings from the LaunchDarkly Big Segments spec; must match what
1616
// Relay writes byte-for-byte.
17-
constexpr char kIncludeKeyPrefix[] = "big_segment_include:";
18-
constexpr char kExcludeKeyPrefix[] = "big_segment_exclude:";
17+
//
18+
// Membership keys are three-part: {user-prefix}:{namespace}:{context-hash},
19+
// where each membership state has its own namespace. Sync-time is two-part:
20+
// {user-prefix}:big_segments_synchronized_on.
21+
constexpr char kIncludeKeyNamespace[] = "big_segment_include";
22+
constexpr char kExcludeKeyNamespace[] = "big_segment_exclude";
1923
constexpr char kSyncTimeKey[] = "big_segments_synchronized_on";
2024

21-
std::string PrefixedKey(std::string const& prefix, std::string const& base) {
22-
return prefix + ":" + base;
23-
}
24-
2525
} // namespace
2626

2727
tl::expected<std::unique_ptr<RedisBigSegmentStore>, std::string>
@@ -40,16 +40,16 @@ RedisBigSegmentStore::RedisBigSegmentStore(
4040
std::string prefix)
4141
: redis_(std::move(redis)),
4242
prefix_(std::move(prefix)),
43-
sync_time_key_(PrefixedKey(prefix_, kSyncTimeKey)) {}
43+
sync_time_key_(prefix_ + ":" + kSyncTimeKey) {}
4444

4545
RedisBigSegmentStore::~RedisBigSegmentStore() = default;
4646

4747
IBigSegmentStore::GetMembershipResult RedisBigSegmentStore::GetMembership(
4848
std::string const& context_hash) const {
4949
std::string const include_key =
50-
PrefixedKey(prefix_, kIncludeKeyPrefix + context_hash);
50+
prefix_ + ":" + kIncludeKeyNamespace + ":" + context_hash;
5151
std::string const exclude_key =
52-
PrefixedKey(prefix_, kExcludeKeyPrefix + context_hash);
52+
prefix_ + ":" + kExcludeKeyNamespace + ":" + context_hash;
5353

5454
std::vector<std::string> included;
5555
std::vector<std::string> excluded;

libs/server-sdk-redis-source/tests/redis_big_segment_store_test.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ class RedisBigSegmentTests : public ::testing::Test {
3333

3434
void AddIncludes(std::string const& context_hash,
3535
std::vector<std::string> const& refs) {
36-
auto const key = prefix_ + ":big_segment_include:" + context_hash;
36+
AddIncludesUnderPrefix(prefix_, context_hash, refs);
37+
}
38+
39+
void AddIncludesUnderPrefix(std::string const& prefix,
40+
std::string const& context_hash,
41+
std::vector<std::string> const& refs) {
42+
auto const key = prefix + ":big_segment_include:" + context_hash;
3743
for (auto const& ref : refs) {
3844
client_.sadd(key, ref);
3945
}
@@ -48,8 +54,11 @@ class RedisBigSegmentTests : public ::testing::Test {
4854
}
4955

5056
void SetSyncTime(std::int64_t millis) {
51-
client_.set(prefix_ + ":big_segments_synchronized_on",
52-
std::to_string(millis));
57+
SetSyncTimeRaw(std::to_string(millis));
58+
}
59+
60+
void SetSyncTimeRaw(std::string const& value) {
61+
client_.set(prefix_ + ":big_segments_synchronized_on", value);
5362
}
5463

5564
protected:
@@ -58,8 +67,6 @@ class RedisBigSegmentTests : public ::testing::Test {
5867
private:
5968
std::string const uri_;
6069
std::string const prefix_;
61-
62-
protected:
6370
sw::redis::Redis client_;
6471
};
6572

@@ -113,8 +120,7 @@ TEST_F(RedisBigSegmentTests, GetMembershipInclusionWinsOverExclusion) {
113120

114121
TEST_F(RedisBigSegmentTests, GetMembershipIsPrefixScoped) {
115122
// Write under a different prefix; same-named test store should not see it.
116-
auto const other_prefix_key = "otherprefix:big_segment_include:alice";
117-
client_.sadd(other_prefix_key, "seg1.g1");
123+
AddIncludesUnderPrefix("otherprefix", "alice", {"seg1.g1"});
118124

119125
auto const result = store_->GetMembership("alice");
120126
ASSERT_TRUE(result);
@@ -132,8 +138,7 @@ TEST_F(RedisBigSegmentTests, GetMetadataReturnsSyncTime) {
132138
}
133139

134140
TEST_F(RedisBigSegmentTests, GetMetadataRejectsMalformedSyncTime) {
135-
client_.set(std::string("testprefix:big_segments_synchronized_on"),
136-
"not-a-number");
141+
SetSyncTimeRaw("not-a-number");
137142

138143
auto const result = store_->GetMetadata();
139144
ASSERT_FALSE(result);

libs/server-sdk/include/launchdarkly/server_side/integrations/big_segments/big_segment_store_types.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class Membership {
5050
[[nodiscard]] std::optional<bool> CheckMembership(
5151
std::string const& segment_ref) const;
5252

53-
Membership() = default;
54-
5553
private:
5654
explicit Membership(std::unordered_map<std::string, bool> entries);
5755

libs/server-sdk/tests/big_segment_store_types_test.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,3 @@ TEST(MembershipTests, DifferentGenerationsAreDistinct) {
3737
ASSERT_EQ(m.CheckMembership("seg.g1"), false);
3838
ASSERT_EQ(m.CheckMembership("seg.g2"), true);
3939
}
40-
41-
TEST(MembershipTests, DefaultConstructedIsEmpty) {
42-
Membership const m;
43-
ASSERT_FALSE(m.CheckMembership("seg.g1").has_value());
44-
}

0 commit comments

Comments
 (0)