Skip to content
This repository was archived by the owner on Jun 10, 2022. It is now read-only.

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Make your systems distributed, replicated, scaled well, easily.

Hex VersionDocsHex downloadsGitHubMIT License

Tutorial

This is an example of a replicated GenServer.

defmoduleStorage.KVdouseGenServerdefstart_link()doGenServer.start_link(__MODULE__,[initial_state: %{}],name: __MODULE__.process_id())enddefinit(opts\\[])do{:ok,Keyword.get(opts,:initial_state,%{})}enddefprocess_id()doStorage.KVenddefhandle_cast({:set,key,value},state)do{:noreply,Map.put(state,key,value)}enddefhandle_call({:get,key,default},_from,state)do{:reply,Map.get(state,key,default),state}enddefhandle_call({:has,key},_from,state)do{:reply,Map.has_key?(state,key),state}enddefhandle_call({:pop,key,default},_from,state)do{value,new_state}=Map.pop(state,key,default){:reply,value,new_state}enddefget(key,default\\nil)doDistributed.Scaler.GenServer.call(__MODULE__.process_id(),{:get,key,default})enddefset(key,value)do{_node_name,result}=Distributed.Replicator.GenServer.cast(__MODULE__.process_id(),{:set,key,value})|>List.first()resultenddefhas?(key)doDistributed.Scaler.GenServer.call(__MODULE__.process_id(),{:has,key})enddefpop(key,default\\nil)do{_node_name,result}=Distributed.Replicator.GenServer.call(__MODULE__.process_id(),{:pop,key,default})|>List.first()resultendend

You can see the example as a small project on ertgl/storage repository.

Installation:

If you have Hex, the package can be installed by adding :distributed to your list of dependencies in mix.exs:

defapplicationdo[extra_applications: [:distributed,],]enddefdepsdo[{:distributed,"~> 0.1.3"},]end

About

Distributed is a wrapper module that helps developers to make distributed, scaled, replicated and fault-tolerant (with takeover ability) leader-follower systems.

Topics

Resources

Stars

25 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages