/memcachir

Elixir memcached client

Primary LanguageElixir

Memcachir

Build Status

Memcached client for Elixir. It supports clusters and AWS Elasticache.

Installation

defp deps() do
  ...
  {:memcachir, "~> 3.2"},
  ...
end

defp application() do
  [applications: [:logger, :memcachir, ...]]
end
config :memcachir,
  hosts: "localhost"

The hosts config allows multiple variants:

hosts: "localhost:11212"  # specify port
hosts: ["host1", "host2", "host3:11212"]  # cluster of servers
hosts: [{"host1", 10}, {"host2", 30}]  # cluster with weights

Alternatively you can use the elasticache config option:

config :memcachir,
  elasticache: "your-config-endpoint.cache.amazonaws.com"

Configuration

Complete configuration options with default values:

config :memcachir,
  hosts: "localhost",
  # memcached options
  ttl: 0,
  namespace: nil,
  # connection pool options
  pool: [
    strategy: :lifo,
    size: 10,
    max_overflow: 10]

Service Discovery

If you don't want to use the built in service discovery methods (host list, elasticache), you can implement the Herd.Discovery behavior, which just has a single nodes/0 callback. Then configure it in with:

config :memcachir, :service_discovery, MyMemcacheServiceDiscovery

(NB you'll need to delete the config :memcachir, :hosts and config :memcachir, :elasticache entries to use a custom service discovery module)

Example

iex> Memcachir.set("hello", "world")
{:ok}
iex> Memcachir.get("hello")
{:ok, "world"}