diff --git a/libs/server-sdk-redis-source/include/launchdarkly/server_side/integrations/redis/redis_source.hpp b/libs/server-sdk-redis-source/include/launchdarkly/server_side/integrations/redis/redis_source.hpp index 98ef99445..2cb094b87 100644 --- a/libs/server-sdk-redis-source/include/launchdarkly/server_side/integrations/redis/redis_source.hpp +++ b/libs/server-sdk-redis-source/include/launchdarkly/server_side/integrations/redis/redis_source.hpp @@ -16,7 +16,6 @@ class Redis; } namespace launchdarkly::server_side::integrations { - /** * @brief RedisDataSource represents a data source for the Server-Side SDK * backed by Redis. It is meant to be used in place of the standard @@ -47,7 +46,7 @@ class RedisDataSource final : public ISerializedDataReader { * * @return A RedisDataSource, or an error if construction failed. */ - static tl::expected, std::string> Create( + static tl::expected, std::string> Create( std::string uri, std::string prefix); @@ -57,8 +56,6 @@ class RedisDataSource final : public ISerializedDataReader { [[nodiscard]] std::string const& Identity() const override; [[nodiscard]] bool Initialized() const override; - ~RedisDataSource(); - private: RedisDataSource(std::unique_ptr redis, std::string prefix); @@ -70,5 +67,4 @@ class RedisDataSource final : public ISerializedDataReader { std::string const inited_key_; std::unique_ptr redis_; }; - } // namespace launchdarkly::server_side::integrations diff --git a/libs/server-sdk-redis-source/src/redis_source.cpp b/libs/server-sdk-redis-source/src/redis_source.cpp index 0e8ccdf46..fa8504bf4 100644 --- a/libs/server-sdk-redis-source/src/redis_source.cpp +++ b/libs/server-sdk-redis-source/src/redis_source.cpp @@ -3,11 +3,10 @@ #include namespace launchdarkly::server_side::integrations { - -tl::expected, std::string> +tl::expected, std::string> RedisDataSource::Create(std::string uri, std::string prefix) { try { - return std::shared_ptr(new RedisDataSource( + return std::unique_ptr(new RedisDataSource( std::make_unique(std::move(uri)), std::move(prefix))); } catch (sw::redis::Error const& e) { @@ -26,8 +25,6 @@ RedisDataSource::RedisDataSource(std::unique_ptr redis, inited_key_(prefix_ + ":$inited"), redis_(std::move(redis)) {} -RedisDataSource::~RedisDataSource() = default; - ISerializedDataReader::GetResult RedisDataSource::Get( ISerializedItemKind const& kind, std::string const& itemKey) const { @@ -54,7 +51,6 @@ ISerializedDataReader::AllResult RedisDataSource::All( items.emplace(key, SerializedItemDescriptor::Present(0, val)); } return items; - } catch (sw::redis::Error const& e) { return tl::make_unexpected(Error{e.what()}); } @@ -72,5 +68,4 @@ bool RedisDataSource::Initialized() const { return false; } } - } // namespace launchdarkly::server_side::integrations diff --git a/libs/server-sdk-redis-source/tests/redis_source_test.cpp b/libs/server-sdk-redis-source/tests/redis_source_test.cpp index b54c87aa7..1064d8a4f 100644 --- a/libs/server-sdk-redis-source/tests/redis_source_test.cpp +++ b/libs/server-sdk-redis-source/tests/redis_source_test.cpp @@ -405,6 +405,13 @@ TEST_F(RedisTests, FlagAndSegmentCanCoexistWithSameKey) { serialize(boost::json::value_from(segment_in))); } +TEST_F(RedisTests, CanConvertRedisDataSourceToDataReader) { + auto maybe_source = RedisDataSource::Create("tcp://foobar:1000", "prefix"); + ASSERT_TRUE(maybe_source); + + std::shared_ptr reader = std::move(*maybe_source); +} + TEST(RedisErrorTests, InvalidURIs) { std::vector const uris = {"nope, not a redis URI", "http://foo", @@ -433,11 +440,11 @@ TEST(RedisErrorTests, ValidURIs) { } TEST(RedisErrorTests, GetReturnsErrorAndNoExceptionThrown) { - auto const maybe_source = RedisDataSource::Create( + auto maybe_source = RedisDataSource::Create( "tcp://foobar:1000" /* no redis service here */, "prefix"); ASSERT_TRUE(maybe_source); - auto const source = *maybe_source; + auto const source = std::move(*maybe_source); auto const get_initialized = source->Initialized(); ASSERT_FALSE(get_initialized);