beaker v1.3.0 Beaker.Counter
Beaker.Counter
is a signed bi-directional integer counter.
It can keep track of integers and increment and decrement them.
It is commonly used for metrics that keep track of some cumulative value.
Examples are:
- Total number of downloads
- Number of queued jobs
- Quotas
Summary
Functions
Retrieves all counters in the form of a map
Clears all counters stored in Beaker
Clears the specified counter from Beaker
Decrements the specified counter by 1
Decrements the specified counter by the specified amount
Retrieves the current value of the specified counter
Increments the specified counter by 1
Increments the specified counter by the specified amount
Sets the value of the specified counter to the specified value
Functions
Retrieves all counters in the form of a map.
Examples
iex> Beaker.Counter.clear
:ok
iex> Beaker.Counter.set("all_counter1", 10)
:ok
iex> Beaker.Counter.incr("all_counter2")
:ok
iex> Beaker.Counter.all
%{"all_counter1" => 10, "all_counter2" => 1}
Returns counters
where counters is a map of all the counters currently existing.
Clears all counters stored in Beaker.
Examples
iex> Beaker.Counter.clear
:ok
iex> Beaker.Counter.set("all_counter1", 10)
:ok
iex> Beaker.Counter.incr("all_counter2")
:ok
iex> Beaker.Counter.all
%{"all_counter1" => 10, "all_counter2" => 1}
iex> Beaker.Counter.clear
:ok
iex> Beaker.Counter.all
%{}
Returns :ok
.
Clears the specified counter from Beaker.
Parameters
key
: The name of the counter to clear.
Examples
iex> Beaker.Counter.clear
:ok
iex> Beaker.Counter.set("all_counter1", 10)
:ok
iex> Beaker.Counter.incr("all_counter2")
:ok
iex> Beaker.Counter.all
%{"all_counter1" => 10, "all_counter2" => 1}
iex> Beaker.Counter.clear("all_counter1")
:ok
iex> Beaker.Counter.all
%{"all_counter2" => 1}
Returns :ok
.
Decrements the specified counter by 1.
Parameters
key
: The name of the counter to decrement.
Examples
iex> Beaker.Counter.get("decr_counter")
nil
iex> Beaker.Counter.decr("decr_counter")
:ok
iex> Beaker.Counter.get("decr_counter")
-1
Returns :ok
.
Decrements the specified counter by the specified amount.
Parameters
key
: The name of the counter to decrement.amount
: The amount to decrement by.
Examples
iex> Beaker.Counter.get("decr_by_counter")
nil
iex> Beaker.Counter.decr_by("decr_by_counter", 10)
:ok
iex> Beaker.Counter.get("decr_by_counter")
-10
Returns :ok
.
Retrieves the current value of the specified counter.
Parameters
key
: The name of the counter to retrieve.
Examples
iex> Beaker.Counter.set("get_counter", 10)
:ok
iex> Beaker.Counter.get("get_counter")
10
Returns count
where count is an integer if the counter exists, else nil
.
Increments the specified counter by 1.
Parameters
key
: The name of the counter to increment.
Examples
iex> Beaker.Counter.get("incr_counter")
nil
iex> Beaker.Counter.incr("incr_counter")
:ok
iex> Beaker.Counter.get("incr_counter")
1
Returns :ok
.
Increments the specified counter by the specified amount.
Parameters
key
: The name of the counter to increment.amount
: The amount to increment by.
Examples
iex> Beaker.Counter.get("incr_by_counter")
nil
iex> Beaker.Counter.incr_by("incr_by_counter", 10)
:ok
iex> Beaker.Counter.get("incr_by_counter")
10
Returns :ok
.