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↑
| decr(key) | Decrements the specified counter by 1 |
| decr_by(key, amount) | Decrements the specified counter by the specified amount |
| get(key) | Retrieves the current value of the specified counter |
| incr(key) | Increments the specified counter by 1 |
| incr_by(key, amount) | Increments the specified counter by the specified amount |
| set(key, value) | Sets the value of the specified counter to the specified value |
Functions
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.
Sets the value of the specified counter to the specified value.
Parameters
key: The name of the counter to set the value for.value: The value to set to the counter.
Examples
iex> Beaker.Counter.set("set_counter", 10)
:ok
iex> Beaker.Counter.get("set_counter")
10
Returns :ok.