Name: mcd
Owner: Pinterest
Description: Fast memcached protocol client in pure Erlang
Created: 2015-04-22 00:05:15.0
Updated: 2017-08-11 18:04:01.0
Pushed: 2016-09-01 23:58:50.0
Size: 300
Language: Erlang
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This library is an incompatible fork of EchoTeam/mcd with very minor changes, designed to play well in a heterogeneous environment where multiple languages are reading and writing to memcache. It only handles binaries as keys and values and sets them in memcache unchanged, all encoding of keys and values is up to you. This library's dependecies have also been updated to use a more modern version of lager.
Now on to the regularly scheduled docs.
This library provides two ways of working with memcached servers. One way is to use a single server, as described in #1. Another way is to use a number of memcached servers in a consistent hash ring mode. This is described in #2.
The following will start an anonymous mcd client, addressable by the returned pid().
{ok, Pid} = mcd:start_link(["localhost", 11211]).
The next one will connect to the memcached server on the local host, and will also register the mcd instance under the 'myMcd' name. See #3. The mcd API can use the returned pid() and the registered name interchangeably.
mcd:start_link(myMcd, []).
mcd:set(myMcd, a, b).
mcd:get(myMcd, a).
{local_memcache,
{mcd, start_link, ['myMcd', ["localhost", 11211]]},
permanent, 10000, worker, [mcd] }
mcd_cluster starts a set of mcd processess and a dispatcher attached to them. All mcd processess and the dispatcher are linked to form a proper exit hierarchy.
mcd_cluster:start_link(mainCluster, [
{host1, ["localhost", 11211], 10},
{host2, ["localhost", 11211], 20}
]).
{mainCluster,
{mcd_cluster, start_link, [mainCluster, [
{host1, ["localhost"], 10},
{host2, ["localhost"], 20}
]]},
permanent, 60000, worker, [mcd_cluster]}
Note: the default port for “localhost” is 11211.
application:set_env(mcd, mcd_hosts, [{localhost, ["localhost"]}]).
application:set_env(mcd, mcd_buckets, [
{cluster1, {localhost, 11211}},
{cluster2, {localhost, 11211}}
]).
application:start(mcd).
{error, notfound} = mcd:get(cluster1, foo).
{error, notfound} = mcd:get(cluster2, foo).
{ok, b} = mcd:set(mainCluster, a, b).
{ok,<<"b">>} = mcd:get(mainCluster, a).
{error, notfound} = mcd:get(mainCluster, foo).
{ok,"*"} = mcd:set(mainCluster, <<"bar">>, [42]).
{ok,<<"*">>} = mcd:get(mainCluster, <<"bar">>).
{ok,[{<<"a">>,<<"b">>},{<<"bar">>,<<"*">>}]} = mcd:get_multi(mainCluster, [a, <<"bar">>]).
See CHANGELOG.md