Logo

dev-resources.site

for different kinds of informations.

#TIR: Build a Simple Persistent Key-Value Store in Elixir, using Logs - Part 1

Published at
12/9/2018
Categories
elixir
tir
Author
chenge
Categories
2 categories in total
elixir
open
tir
open
Author
6 person written this
chenge
open
#TIR: Build a Simple Persistent Key-Value Store in Elixir, using Logs - Part 1

link-->

Today I read it from Awesome Elixir Newsletter. Nice for learning Elixir.

def lookup(key) do
  GenServer.call(__MODULE__, {:lookup, key})
end

def handle_call({:lookup, key}, _from, index_map) do
  {:reply, get_key_offset_size(key, index_map), index_map}
end

defp get_key_offset_size(key, index_map) do
  case Map.get(index_map, key) do
    {_offset, _size} = offset_size -> {:ok, offset_size}
    nil -> {:error, :not_found}
  end
end

Featured ones: