- $member_obj:Redis::LeaderBoard::Member = $lb->find_member($member:Str)
- $lb->set_score($member:Str, $score:Number, [$member2, $score2,...])
- $score:Number = $lb->get_score($member:Str)
- $score:Number = $lb->incr_score($member:Str, [$increment_score:Number])
- $score:Number = $lb->decr_score($member:Str, [$decrement_score:Number])
- $lb->remove($member:Str, [$member2:Str,...])
- ($rank:Int, $score:Number) = $lb->get_rank_with_score($member:Str)
- $rank:Int = $lb->get_rank($member:Str)
- $order:Int = $lb->get_sorted_order($member:Str)
- $count = $lb->member_count([$from, $to])
- $rankings:ArrayRef<HashRef> = $lb->rankings(%opt)
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.
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 <firstname.lastname@example.org>