Skip to content

Instantly share code, notes, and snippets.

@mbriggs mbriggs/redis.ex
Created Apr 12, 2016

Embed
What would you like to do?
redis client
defmodule Autobot.Redis do
import Exredis
def start_link do
Agent.start_link(fn ->
{:ok, client} = Exredis.start_link
client
end, name: __MODULE__)
end
def get(key), do: exec(["GET", key])
def get_json(key), do: get(key) |> Poison.decode!
def set(key, val), do: exec(["SET", key, val])
def set(key, val, expire), do: exec(["SETEX", key, expire, val])
def set_json(key, val), do: exec(["SET", key, Poison.encode!(val)])
def set_json(key, val, expire), do: exec(["SETEX", key, expire, Poison.encode!(val)])
def remove(key), do: exec(["DEL", key])
defp exec(args) do
Agent.get(__MODULE__, fn client ->
query(client, args)
end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.