RememberMe (remember_me v0.0.1)

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
  Hello World!

  20:13:59.336 [info] Started execute function
  Hello World!
  Hello World!
  20:14:29.342 [info] Finish Execute function
  iex>


  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

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

Functions

Link to this function

exec_func(fun, opts \\ [])

@spec exec_func((... -> any()), maybe_improper_list()) ::
  :ignore | :ok | {:error, any()}

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 Hello World!

20:13:59.336 [info] Started execute function Hello World! Hello World! 20:14:29.342 [info] Finish Execute function iex>

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()) :: :ignore | {:error, any()} | :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.

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(), [...]}, ...]}