I am reading through using genserver and redix try to understand how both can work together. I havent been able to find a resource that just explains the marriage between the two. Here is my use case:
I have data that is already stored in the database and my goal is to read the data and save it on a redix cache. The redix documentation is really clear on the functions I can use to set stata, start link but I am just not sure where to marry the two. This should be done via the genserver so that I can ensure fault tolerance. Below is what I have so far
A module database that uses genserver and has a set function that has a handle cast that sets a user to a key in redix. Within the handle_cast I am calling the redix
defmodule Database
use Genserver
.
.
.
def set({pid, key, value}) do
GenServer.cast(pid, {:set, key, value})
end
def handle_cast({:set, key, value}, _from, state) do
Redix.command(state, ["SET", key, value])
{:no_reply, }
end
.
.
.
end
I know that redix has a start link function and my genserver Database module also has a start link. When and where do I use either of them?