Bouncer.Adapters.Redis

The Redis adapter is used by Bouncer.Token to save and retrieve generated tokens and associated data.

Summary

Functions

Adds item(s) to a Redis list identified by the given key

Retrieves a user’s collection of tokens given their ID

Deletes a given key from Redis

Sets the TTL (time-to-live in seconds) of the given key

Retrieves data from Redis using a given key

Removes a item from the Redis list identified by a given key

Saves data to Redis using a given key. If ttl is not nil, the value will be converted from seconds to miliseconds and set as the key’s time-to-live

Functions

add(id, token)

Adds item(s) to a Redis list identified by the given key.

Examples

iex> Bouncer.Adapters.Redis.add 1, "Arcadia"
{:ok, 1}
all(id)

Retrieves a user’s collection of tokens given their ID.

Examples

iex> Bouncer.Adapters.Redis.add 2, "divine_hammer"
...> Bouncer.Adapters.Redis.all 2
{:ok, ["divine_hammer"]}
iex> Bouncer.Adapters.Redis.all 3
{:ok, []}
delete(keys)

Deletes a given key from Redis.

Examples

iex> Bouncer.Adapters.Redis.save %{id: 1}, "UdOnTkNoW", nil
...> Bouncer.Adapters.Redis.delete "UdOnTkNoW"
{:ok, "UdOnTkNoW"}
iex> Bouncer.Adapters.Redis.delete "Arcadia"
{:error, "Key 'Arcadia' not found"}
expire(key, ttl)

Sets the TTL (time-to-live in seconds) of the given key.

Examples

iex> Bouncer.Adapters.Redis.save %{id: 1}, "UdOnTkNoW", nil
...> Bouncer.Adapters.Redis.expire "UdOnTkNoW", 1
{:ok, "UdOnTkNoW"}
iex> Bouncer.Adapters.Redis.expire "Arcadia", 1
{:error, "Could not set TTL, key 'Arcadia' not found"}
get(key)

Retrieves data from Redis using a given key.

Examples

iex> Bouncer.Adapters.Redis.save %{id: 1},"UdOnTkNoW", nil
...> Bouncer.Adapters.Redis.get "UdOnTkNoW"
{:ok, %{id: 1}}
iex> Bouncer.Adapters.Redis.get "Arcadia"
{:error, nil}
remove(key, items)

Removes a item from the Redis list identified by a given key.

save(data, key, ttl)

Saves data to Redis using a given key. If ttl is not nil, the value will be converted from seconds to miliseconds and set as the key’s time-to-live.

Examples

iex> Bouncer.Adapters.Redis.save %{id: 1}, "UdOnTkNoW", nil
{:ok, "UdOnTkNoW"}