redis-counter
This is a trivial redis auto-increment counter implementation.
Install
npm install redis-counter
Initialization
// Initialization via redis URLs of the form: redis://user:password@host:port/ var counters = ; // Specifying collection name instead of defaulting to counters collection. // The collection name is the hash name to store the counters under var counters = ;
API
; // increments by one, throws away the result ; // increments by 5 throws away the result ; // increment by one and get the new value ; ; // same options with decrement ; ; // update the value. // if you only want to generate unique ids (for URL shortening for example), // a much faster method is getNextUniqueId. It only hits the database every 100 // calls. Ofcourse, this has the side effect that the sequence is not strictly // monotonically increasing in order and there could be gaps when there are crashes // but uniqueness is guaranteed and the ordering will be almost monotonic. This is // suitable for a lot of cases where you just want a small unique ID. { ; });