https://github.com/avencera/distributed_kv
A simple genserver + ets + pg2 that lets you create a distributed kv store
https://github.com/avencera/distributed_kv
Last synced: about 2 months ago
JSON representation
A simple genserver + ets + pg2 that lets you create a distributed kv store
- Host: GitHub
- URL: https://github.com/avencera/distributed_kv
- Owner: avencera
- Created: 2018-10-19T06:20:45.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-13T03:57:34.000Z (about 6 years ago)
- Last Synced: 2025-05-17T17:08:01.574Z (5 months ago)
- Language: Elixir
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DistributedKV
** Expirement / Learning **
** WORK IN PROGRESS **
A simple genserver + ets + pg2 that lets you create a distributed kv
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `distributed_kv` to your list of dependencies in `mix.exs`:```elixir
def deps do
[
{:distributed_kv, "~> 0.1.0"}
]
end
```## Usage
1. Start one or many instances of the DistributedKV in the supervision tree, ex:
```elixir
Supervisor.child_spec({DistributedKV.Server, MyApp.Registry},
id: :myapp_registry
),
```2. Create `MyApp.Registry` and implement functions that handles inserting, dumping and retrieving
```elixir
defmodule MyApp.Registry do
@name __MODULE__def dump() do
GenServer.call(@name, :dump)
enddef register(key, identifier) do
GenServer.cast(@name, {:insert, key, identifier})
enddef retrieve() do
case :ets.lookup(@name, key) do
[{^key, identifier}] -> identifier
_ -> nil
end
end
end```
Note: `@name` should be the name you provided in supervision tree (ex: `MyApp.Registry`)