anchor

High-Performance Erlang Memcached Client

Build Status

Requirements

Features

API

Function reference on hexdocs

Environment variables

NameTypeDefaultDescription
backlog_sizepos_integer()1024maximum number of concurrent requests per connection
iplist()"127.0.0.1"server ip
pool_sizepos_integer()16number of connections
pool_strategyrandom | round_robinrandomconnection selection strategy
portpos_integer()9042server port
reconnectboolean()truereconnect closed connections
reconnect_time_maxpos_integer() | infinity120000upper bound on the reconnect backoff (ms)
reconnect_time_minpos_integer()1000lower bound on the reconnect backoff (ms)
socket_options[gen_tcp:connect_option()] [binary, {buffer, 65535}, {nodelay, true}, {packet, raw}, {send_timeout, 50}, {send_timeout_close, true}] options passed to the socket

Examples

1> anchor_app:start().
{ok, [shackle, anchor]}

2> anchor:get(<<"foo">>).
{error, key_not_found}

3> anchor:set(<<"foo">>, <<"bar">>, 3600).
ok

4> anchor:get(<<"foo">>).
{ok, <<"bar">>}

5> anchor:delete(<<"foo">>).
ok

6> {ok, Ref} = anchor:async_get(<<"foo">>).
{ok, {anchor_6, #Ref<0.0.1.1363>}}

7> anchor:receive_response(Ref, 1000).
{error, key_not_found}

Errors

All anchor:* calls return ok | {ok, term()} | {error, error_reason()} where error_reason/0 (exported, added in 0.3.8) enumerates:

The closed sum lets dialyzer catch typos in case patterns at call sites.

Telemetry

anchor emits one telemetry event at the request boundary. Attach handlers via telemetry:attach/4:

Event Measurements Metadata
[anchor, request, sent]count => 1operation, async

Fires from the two internal dispatch helpers (call/2 and cast/3), so all 77 exported public functions are covered without per-arity instrumentation. The operation metadata is the memcached op (get, set, add, replace, delete, flush, noop, quit, version, increment, decrement).

Per-request shackle lifecycle (queue / send / receive) remains observable via shackle's own telemetry — anchor's event surfaces the memcached-level intent without duplicating that work.

Tests

make test

License

The MIT License (MIT)

Copyright (c) 2014-2026 Louis-Philippe Gauthier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.