I have a genserver where I’m fetching all the information from the database and I’m using redis to cache my data. Now I have to set a key for a particular user and I’m fetching that user by userone function which takes the pid and id which fetches that particular user from the database. I have to set a key for that particular user
So how do I set a key for that particular user?
# def get(pid, key) do
# GenServer.call(storage_pid, {:get, key})
# end
def set(pid, key, value) do
GenServer.cast(pid, {:set, key, value})
end
def handle_cast({:set, key, value}, _from, state) do
user = Redix.command!(state, key, value)
{:no_reply, user, state}
end
def userone(pid, id) do
GenServer.call(pid, {:userone, id})
end
def list(pid) do
GenServer.call(pid, :list)
end
def handle_call(:list, _from, state) do
my_models = Accounts.list_users()
{:reply, my_models, state}
end
def handle_call({:userone, id}, _from, state) do
users = Accounts.get_user!(id)
{:reply, users, state}
end