scorerank
Simple score ranking with redis.
Installation
$ npm install scorerank
Usage
const scorerank = const url = 'redis://127.0.0.1:6379'const options = prefix: 'scores' const score = // Add scoresscorescorescore // Get top 10 rankingconst tops = await scoretop0 10console // => ['user3', 'user2', 'user1'] // Get user specific rankingconst rank = await scoreconsole // => 1 // Get user specific scoreconst sc = await scoreconsole // => 21 // Remove user specific scoreconst sc = await score
API
scorerank([options])
Get an instance of scorerank. options
is an object that besides prefix
it can have any option property supported by ioredis
.
const options = prefix: 'scores' port: 6379 host: '127.0.0.1' password: '' const score =
scorerank.add(id, score, [ns])
Add scores by id.
scorerank
scorerank.score(id, [ns])
Get score by user id.
scorerank
scorerank.rank(id, [ns])
Get ranking of an specific id.
scorerank
scorerank.top([range, [ns]])
Get top 100 ranking.
scoreranktop
Or get specific range ranking.
// get top 10 rankingscoreranktop0 10 // get ranking between the range of 10 to 20scoreranktop10 20
scorerank.remove(id, [ns])
Remove score by id.
scorerank
Run tests
$ yarn test
License
(The MIT License)
Copyright (c) 2019 Jonathan Brumley <cayasso@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.