Counters Module
General purpose atomically incrementing counters.
Methods
clear(search='') count(search='') del(key) get(key) has(key) list(search='', skip=0, limit=100) next(key)
counters.clear(search='')
Clears counters starting with search
(or all counters with ''
).
Arguments
search
(String) Any keys starting withsearch
are removed. To avoid inadvertently clearing keys, adopt a key naming strategy that guarantees key domains remain segregated. Leaving this argument blank will delete all counters.
Returns
removed
(Number) the number of counters removed.
counters.count(search='')
Returns a count of counters entries starting with search
(or all counters with ''
).
Arguments
search
(String) Any counters starting withsearch
are counted.
Returns
count
(Number) the number of matching keys.
counters.del(key)
Removes the counters with a key matching key
.
Arguments
key
(String) The key to remove.
Returns
removed
(Boolean) true if the counters was removed.
counters.get(key)
Returns the value of a counter matching key
without incrementing.
Arguments
key
(String) The key to match.
Returns
value
(Object) Returns the value of the entry, ornull
if not found.
counters.has(key)
Returns true if a counter matching key
exists.
Arguments
key
(String) The counter to match.
Returns
exists
(Boolean) Returnstrue
if the counter exists.
counters.list(search='', skip=0, limit=100)
Returns an array of matching entry metadata, sorted by key.
Arguments
search
(String) The key filter. All entries starting withsearch
are returned.skip
(Number) The number of entries to skip. Useful for paging.limit
(Number) The maximum number of entries to return, from 1 to 1000.
Returns
entries
(Object[]) A list of matching entry metadata.key
(String) The entry key.created
(Date) The time the entry was initially created.val
(Number) The current counter value.updated
(Date) The date of the last update to the counter.
counters.next(key)
Atomically increment and return the next counter value.
Arguments
key
(String) The key to set.
Returns
value
(Number) The next counter value.
Examples
Example
Last updated