Memcachex is an advanced Memcached client tailored for Go applications that demand high performance and predictable latency. Utilizing an event-loop-driven I/O engine and async-first APIs, it provides explicit control over execution and backpressure while minimizing allocations. Ideal for infrastructure-grade workloads, memcachex prioritizes measurable behavior under load.
memcachex is a high-performance Memcached client for Go designed for environments where factors such as latency predictability, allocation behavior, and execution control are paramount. This advanced client leverages a custom event-loop–driven I/O engine that provides asynchronous APIs and explicit management of request lifecycles, thus ensuring transparent and measurable performance under load.
To create a memcachex client, the following code can be used to establish a connection:
cl, err := memcachex.NewClient(
memcachex.WithAddr("localhost:11211"),
)
if err != nil {
panic(err)
}
Clients can be configured through functional options or a ClientOptions struct. Here’s an example using functional options:
client, err := memcachex.NewClient(
memcachex.WithAddr("127.0.0.1:11211"),
memcachex.WithNumEventLoops(1),
memcachex.WithNumEventLoopSockets(2),
memcachex.WithRingSize(8192),
memcachex.WithNumEnqueueRetries(2),
memcachex.WithLockOSThread(false),
)
A comprehensive overview of configuration options can be found in the README. Each default value is optimized for typical usage, making alterations unnecessary for most applications unless operating under specific conditions.
Utilize the synchronous APIs for straightforward operations:
val, err := cl.Get([]byte("key"))
err := cl.Set(&proto.Item{
Key: []byte("key"),
Value: []byte("value"),
Expiration: 10,
})
For non-blocking requests, leverage the asynchronous capabilities:
err := cl.GetAsync([]byte("key"), func(v any, err error) {
if err != nil {
return
}
val := v.(*proto.Value)
fmt.Println(string(val.Value))
})
memcachex is ideal for developers and systems that prioritize:
This library is classified as experimental, with anticipated changes to the APIs as optimization efforts continue and insights are refined. The design prioritizes stability, efficiency, and performance, making it suitable for demanding infrastructure-grade workloads.
No comments yet.
Sign in to be the first to comment.