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"}
]
endExamples
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
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
exec_func(fun, opts \\ [])
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!
find_value(name_state)
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"}
guard(name_state, value, opts \\ [])
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)
:okNote that if you pass a key equal to the previous one to the guard(), it will simply replace the value with the current value.
list_keys()
@spec list_keys() :: [binary()]
Lists the active memory keys in alphabetical order.
update_ttl(name_state, opts)
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