Redis::LeaderBoard - leader board using Redis
use Redis; use Redis::LeaderBoard; my $redis = Redis->new; my $lb = Redis::LeaderBoard->new( redis => $redis, key => 'leader_board:1', order => 'asc', # asc/desc, desc as default ); $lb->set_score('one' => 100'); $lb->set_score('two' => 50'); my ($rank, $score) = $lb->get_rank_with_score('one'); # memmber object my $member = $lb->find_member('two'); $member->score(90); my $rank2 = $member->rank;
Redis::LeaderBoard is for providing leader board by using Redis's sorted set.
z(rev)?rank of Redis 2.8 or older doesn't consider same scores. This module resolve it.
Create a new leader board object. Options should be set in
Redis object. Redis.pm or Redis::hiredis.
desc as default.
Find member by member id. see Redis::LeaderBoard::Member for more details.
Set scores of members. You can set multiple element if using Redis 2.4 or later.
Get score of member.
increment score of member and returns reflected score. 1 is default
decrement score of member and returns reflected score. 1 is default
remove members from leader board. Multiple element can be accepted Redis 2.4 or later.
Returns rank and score. If you want to get rank and score at the same time, you should not call
get_rank separately, use this method instead for performance.
Get rank of member.
Get sorted order in sorted set. (same as
Get number of members. If score range (
$to) is specified, it returns a number of members in range.
Return rankings by arrayref contains hashrefs. keys of hashref is
Options can be set in
%options. keys of options are as follows.
Copyright (C) Masayuki Matsuki.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Masayuki Matsuki <email@example.com>