RememberMe (remember_me v1.0.4)

RememberMe is a robust but simple state memory machine organizer. you can assimilate it like a Redis, but the difference is that you can schedule and define the number of times a function will be executed and of course save any values ​​from an assimilated key.

Installation

RememberMe can be installed by adding it as a dependency in your mix.exs file:

defp deps do
  [
    {:remember_me, "~> 0.0.1"}
  ]
end

Examples

iex> RememberMe.guard("text_deleted", %{"user" => "Foo", "text" => "A any message"}, min: 2) :ok

iex> RememberMe.find_value("text_deleted") %{

"user" => "Foo",
"text" => "A any message"

}

iex> RememberMe.exec_func(fn -> IO.puts "Hello World!" end, [sec: 10, repeat: 3]) :ok

20:13:59.336 [info] function_scheduled 20:14:09.336 [info] function_execution_started Hello World!

Important to note that if no opts are passed, the default value for time will be 3 minutes and the repeat will default to 1 time.

Summary

Functions

Deletes a value from memory before its configured expiration.

will queue a specified amount of functions in memory to be executed in the given time

Will get value saved in memory from key

Will save a value in RAM memory with a key to get it later

Lists the active memory keys in alphabetical order.

Changes a value's expiration without replacing the value.

Functions

Link to this function

delete_value(name_state)

@spec delete_value(binary()) :: :ok

Deletes a value from memory before its configured expiration.

It is safe to call this function when the key does not exist.

Examples

iex> RememberMe.delete_value("text_deleted")
:ok
Link to this function

exec_func(fun, opts \\ [])

@spec exec_func(
  function(),
  keyword()
) :: :ok

will queue a specified amount of functions in memory to be executed in the given time

Parameters

  • fun: Function that will executed
  • opts: Sets a time to stay in memory, can be sec, min or hour - default: 3 minutes and defines the number of times the function should be repeated, default is 1

Examples

iex> RememberMe.exec_func(fn -> IO.puts "Hello World!" end, [sec: 10, repeat: 3]) :ok 20:13:59.336 [info] function_scheduled 20:14:09.336 [info] function_execution_started Hello World!

Link to this function

find_value(name_state)

@spec find_value(binary()) :: any()

Will get value saved in memory from key

Parameters

  • name_state: String that represents the name of the key.

Examples

iex> RememberMe.find_value("text_deleted") %{

"user" => "Foo",
"text" => "A any message"

}

Link to this function

guard(name_state, value, opts \\ [])

@spec guard(binary(), any(), keyword()) :: :ok

Will save a value in RAM memory with a key to get it later

Parameters

  • name_state: String that represents the name of the key.
  • value: Any value
  • opts: Sets a time to stay in memory, can be sec, min or hour - default: 3 minutes

Examples

iex> RememberMe.guard("text_deleted", %{"user" => "Foo", "text" => "A any message"}, min: 2)
:ok

iex> RememberMe.guard("text_deleted", %{"user" => "Foo", "text" => "Another message"}, min: 2)
:ok

Note that if you pass a key equal to the previous one to the guard(), it will simply replace the value with the current value.

@spec list_keys() :: [binary()]

Lists the active memory keys in alphabetical order.

Link to this function

update_ttl(name_state, opts)

@spec update_ttl(
  binary(),
  keyword()
) :: :ok | {:error, :not_found}

Changes a value's expiration without replacing the value.

It returns {:error, :not_found} when the key is not stored.

Examples

iex> RememberMe.update_ttl("text_deleted", min: 5)
:ok
Link to this macro

validate_params_fun(value, opts)

(macro)
@spec validate_params_fun(any(), any()) ::
  {:__block__ | {:., [], [:andalso | :erlang, ...]}, [],
   [{:= | {any(), any(), any()}, list(), [...]}, ...]}
Link to this macro

validate_params_guard(name_state, value, opts)

(macro)
@spec validate_params_guard(String.t(), any(), Atom) ::
  {:__block__ | {:., [], [:andalso | :erlang, ...]}, [],
   [{:= | {any(), any(), any()}, list(), [...]}, ...]}