How do I set a key for current user?

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
  #, {:get, key})
  # end

  def set(pid, key, value) do
    GenServer.cast(pid, {:set, key, value})

  def handle_cast({:set, key, value}, _from, state) do
    user = Redix.command!(state, key, value)
    {:no_reply, user, state}

  def userone(pid, id) do, {:userone, id})

  def list(pid) do, :list)

  def handle_call(:list, _from, state) do
    my_models = Accounts.list_users()

    {:reply, my_models, state}

  def handle_call({:userone, id}, _from, state) do
    users = Accounts.get_user!(id)
    {:reply, users, state}

Your question doesn’t get more clear by repeating it 5 times.

What exactly do you mean by “setting up a key for that user”?

Like in Redis you set a key and value. What I want is to set a key and by calling that key it will give a current user. Is that clear?

I think he is very clear.

What does giving a key a user mean?

You have become better at GenServer, but You could make it nicer…

How many user/s?

Now You need to read Redix docs, because this is not the good syntax.

1 Like

I think he is asking about how he can use “SET” and “GET” in Redix.

Like for set you do this
Redix.command(conn, [“SET”, “mykey”, “foo”])

So set will be some key and value will be that user. I’m not sure


Thanks. Yes sure. Doing that only

@Maxtonx gave You the good syntax