feat(services/memcached): Add TLS support for AWS ElastiCache #5499
+120
−93
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add TLS Support for AWS ElastiCache Memcached
This PR adds TLS support for Memcached connections, particularly targeting AWS ElastiCache serverless instances which require TLS connections. Instead of using plain TCP conn
This pull request introduces several changes to the
core/src/services/memcached
module to add support for TLS connections, which is required for AWS ElastiCache Memcached serverless instances. The most important changes include adding TLS-related dependencies, updating theMemcachedBuilder
andMemcacheConnectionManager
to support TLS configuration, and modifying theConnection
struct to handle both plain and TLS connections.TLS Support:
core/src/services/memcached/backend.rs
: Addedtokio_native_tls
dependencies and updatedMemcachedBuilder
to include methods for enabling TLS and setting the CA certificate file path. [1] [2]core/src/services/memcached/backend.rs
: ModifiedMemcacheConnectionManager
to handle TLS connections by addingenable_tls
andca_cert
fields and updating theconnect
method to establish a TLS connection if enabled. [1] [2]core/src/services/memcached/config.rs
: UpdatedMemcachedConfig
to includeenable_tls
andca_cert
fields for TLS configuration.Connection Handling:
core/src/services/memcached/backend.rs
: RefactoredAdapter
to use a connection pool instead of managing individual connections, and updated theBuilder
implementation to create the connection pool with the newMemcacheConnectionManager
. [1] [2]core/src/services/memcached/binary.rs
: Modified theConnection
struct to use a dynamic stream (Box<dyn AsyncRead + AsyncWrite + Send + Unpin>
) to support both plain and TLS connections, and updated related methods to work with the new stream type. [1] [2] [3] ections (telnet
), users can now establish secure TLS connections (openssl s_client
) with their Memcached instances.Changes
1. Configuration Options
Added new configuration options to
MemcachedConfig
:2. Builder Methods
Added new builder methods to
MemcachedBuilder
:3. TLS Connection Handling
tokio-native-tls
Usage Example
Implementation Details
Connection
to use a boxed trait object that can handle both TLS and non-TLS streams:MemcacheConnectionManager
:Testing
Dependencies
Added
tokio-native-tls
for TLS support:Related Issues
#5419
@killme2008 @drmingdrmer @jayvdb @viirya @qrilka @Xuanwo