https://github.com/peillis/memcachir
Elixir memcached client
https://github.com/peillis/memcachir
elixir memcached memcached-clients
Last synced: 2 months ago
JSON representation
Elixir memcached client
- Host: GitHub
- URL: https://github.com/peillis/memcachir
- Owner: peillis
- License: mit
- Created: 2017-05-03T10:32:27.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-08-23T15:54:32.000Z (almost 4 years ago)
- Last Synced: 2025-03-26T23:04:45.126Z (3 months ago)
- Topics: elixir, memcached, memcached-clients
- Language: Elixir
- Size: 239 KB
- Stars: 8
- Watchers: 1
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Memcachir
[](http://travis-ci.org/peillis/memcachir)
[](https://hex.pm/packages/memcachir)
[](https://hexdocs.pm/memcachir/)
[](https://hex.pm/packages/memcachir)
[](https://github.com/peillis/memcachir/blob/master/LICENSE.md)
[](https://github.com/peillis/memcachir/commits/master)Memcached client for Elixir. It supports clusters and AWS Elasticache.
## Installation
```elixir
defp deps() do
...
{:memcachir, "~> 3.3"},
...
enddefp application() do
[applications: [:logger, :memcachir, ...]]
end
``````elixir
config :memcachir,
hosts: "localhost"
```The `hosts` config allows multiple variants:
```elixir
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:
```elixir
config :memcachir,
elasticache: "your-config-endpoint.cache.amazonaws.com"
```## Configuration
Complete configuration options with default values:
```elixir
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:
```elixir
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
```elixir
iex> Memcachir.set("hello", "world")
{:ok}
iex> Memcachir.get("hello")
{:ok, "world"}
```Example with ttl (in seconds)
```elixir
iex> Memcachir.set("hello", "world", ttl: 5)
{:ok}
iex> Memcachir.get("hello")
{:ok, "world"}
iex> :timer.sleep(5001)
:ok
iex> Memcachir.get("hello")
{:error, "Key not found"}
```## Copyright and License
Copyright (c) 2017 Enrique Martinez
This library licensed under the [MIT license](./LICENSE.md).