We are deploying to Heroku which as I understand doesn't support mnesia?
Can you use redis with pow for session storage?
Yeah, but you have to write a custom cache store module. Take a look at the current ETS and Mnesia modules for an idea how it works (they are based on GenServer, which you won't need for a Redis integration): https://github.com/danschultzer/pow/tree/master/lib/pow/store/backend
You'll need to implement the following methods:
Also you have to make sure that it uses the TTL and namespace configuration, but with Redis that would be easy. Remember to set the config:
cache_store_backend: MyApp.PowRedisCache
As a quick n dirty example to get you started using Redix:
defmodule MyApp.PowRedisCache do
@behaviour Pow.Store.Base
alias Pow.Config
def put(config, key, value) do
key = redis_key(config, key)
ttl = Config.get(config, :ttl)
{:ok, "OK"} = Redix.command(conn, ["SET", key, value])
if ttl, do: {:ok, "OK"} = Redix.command(conn, ["PTTL", key, ttl])
:ok
end
defp redis_key(config, key) do
namespace = Config.get(config, :namespace, "cache")
"#{namespace}:#{key}"
end
end
You'll probably need to serialize the value too in the above example.
Thank you, will take a look.
I've added a completely guide on how to set up Redis backend cache (#88): https://github.com/danschultzer/pow/blob/d5de1fdafe2049b78f24d930c21e9f876c14f7df/guides/REDIS_CACHE_STORE_BACKEND.md
Let me know if this works for you!
Amazing!!
This is great! Will it work if we use a custom controller? That’s been our issue.
Sent from my iPhone
On Feb 14, 2019, at 8:57 AM, Dan Schultzer notifications@github.com wrote:
I've added a completely guide on how to set up Redis backend cache (#88): https://github.com/danschultzer/pow/blob/3c116af73d140ee524ac3028fda766a46a0d536a/guides/REDIS_CACHE_STORE_BACKEND.md
Let me know if this works for you!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
Yeah, custom controller shouldn't affect the cache store backend. It's the plug methods that communicates with the store.
Hi @danschultzer, thanks for the great library! I use it multiple projects. May I ask why not to include the Redis implementation from your guide to the library?
Thanks, great to hear @minibikini!
I don't include it in Pow because there's no native support for Redis in erlang/elixir. I try to keep Pow at near zero dependencies.
I see, thanks!