Memlink is a high-performance TCP client library for sending and receiving ordered requests for memcached protocol, providing a robust and efficient way to interact with memcached servers. This can also be extended to support any tcp powered protocol.
- Generic TCP client with tls/mtls support as well
- Optimized for memcached protocol implementation
- Connection pooling and management
- High-performance message encoding/decoding
- Comprehensive test coverage
go get github.com/stripe/memlink
See the example directory for a comprehensive demonstration of how to use the memlink client with memcached instances.
For detailed information about the memcached protocol, refer to the official documentation.
-
Hash key passing: The connection pool currently uses an empty key for key hashing - i.e. it randomly assigns the key to a backend. If this is not desirable, you should consider forwarding the request to the right backend from either the server side or wait for the change to be officially supported.
-
Bulk operation fan-out: Similar to above, all the pipelined bulk requests will land on the same backend. Work is in progress to spread that out over the appropriate backend once #1 is completed.
-
Extra Go routines: Memlink creates 3 new goroutines per backend -- if you have
M
backends and connection pool size ofN
, then expectM*N*3
new goroutines created by using memlink, 1 of them being mostly quiet. -
Safe closing: Memlink doesn't actively monitor health of backends and remove them from rotation, so its users responsibility to safely remove the backend from connection pool if its no longer healthy / going to be replaced.
This implementation follows the memcached meta protocol, but there are important considerations:
-
Protocol compliance: The implementation is based on memcached meta protocol specifications, but may not cover all edge cases or newer protocol features.
-
Field ordering: The protocol has specific requirements about field ordering in requests (e.g., TTL must come before BlockTTL in arithmetic operations).
-
Protocol evolution: Memcached protocol may evolve, and this implementation may need updates to support newer features or changes.
Note: Always test thoroughly with your specific memcached version and configuration before using in production.