simplecache v0.1.0 Simplecache.StoreRedis

A simple Redis wrapper for caching.

Link to this section Summary

Functions

Fetches the value for the given key from the cache. Note that a prefix ("simplecache") is appended to the key, i.e. the actual key in redis will be simplecache <> "_" <> key

Caches the given key-value pair Note that a prefix ("simplecache") is appended to the key, i.e. the actual key in redis will be simplecache <> "_" <> key

Link to this section Functions

Fetches the value for the given key from the cache. Note that a prefix ("simplecache") is appended to the key, i.e. the actual key in redis will be simplecache <> "_" <> key

Returns

{:ok, response}

{:error, _error}

Examples

iex> Simplecache.StoreRedis.read("my_key")
{:ok, "my_value"}

iex> Simplecache.StoreRedis.read("unset_key")
{:ok, nil}

iex> Simplecache.StoreRedis.read("unset_key")
{:error, error}
Link to this function

write(key, value, options \\ [])

Caches the given key-value pair Note that a prefix ("simplecache") is appended to the key, i.e. the actual key in redis will be simplecache <> "_" <> key

Returns

{:ok, "OK"}

{:error, _error}

Options

  • :ttl_seconds (positive integer) - the entry will be set to expire after the given number of seconds. If unset the entry will have no expiry.

Examples

iex> Simplecache.StoreRedis.write("my_key", "my_value")
{:ok, "OK"}

# Set with a TTL of 1 hour
iex> Simplecache.StoreRedis.write("my_key", "my_value", ttl_seconds: 3600)
{:ok, "OK"}