DEV Community

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

Posted on

1 2

#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

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay