-
Notifications
You must be signed in to change notification settings - Fork 6
(Proposal) RedisLeaderboard
This work would add leaderboard functionality to mod_redis, the idea being that it would provide all the functionality to surface leaderboard data via HTTP GET calls. All responses would be encoded as JSON only, with the option of a function name to be supplied as a parameter to return JSONP.
For purposes of illustration this page assumes mod_redis has been installed into an Apache HTTPD server running on port 80 on the local machine & configured to map to a prefix of '/redis/'.
Description: Defines a rule to match a URL to a REDIS sorted set
Syntax: RedisLeaderboard TestString option ...
TestString
A regular expression defining the elements in the URL to match, in the same manner as the RedisAlias directive. The only difference in this case is that there must be only one backreference which must be the name of the Redis sorted set storing the leaderboard data.
For example,
^game/([^/]+)$
would mean that the URL http://localhost/redis/game/manic_miner would map on to a sorted set with the key of manic_miner
Option can be one of
pagesize=n The pagesize option specifies the size of a page of results. The default is 20
max_friends=n This option specifies the maximum size of the list of friends that can be supplied for friends leaderboards. The default is 50.
Example
RedisLeaderboard ^leaderboard/([^/]+)$ pagesize=10
In the following examples prefix is the part of the URL that maps onto a specific redis sorted set as defined in the directive as above
Description: Returns details of the specified leaderboard.
Syntax: prefix(?callback=function_name)
Returns the total number of members in the sorted set, and the total number of pages (which will be the total number of members divided by the page size)
For example :
http://server/mod_redis/leaderboard/manic_miner
Description: Returns a page of the leaderboard as JSON.
Syntax: prefix/page/page_number(?callback=function_name)
The size of the page is as defined in the httpd directive, and the first page_number is 0. The callback parameter is optional, but if defined then the response is JSONP with the function_name as the callback.
For example :
http://server/mod_redis/leaderboard/manic_miner/page/0
This would return the first 20 entries of the sorted set manic_miner
http://server/mod_redis/leaderboard/defender/page/1?callback=firstPage
would return the second set of 20 entries from the sorted set defender as JSONP invoking the callback firstPage
Description: Returns a page of the leaderboard centred around a particular member as JSON.
Syntax: prefix/aroundme/member(?callback=function_name)
For example :
http://server/mod_redis/leaderboard/manic_miner/around_me/user20
Would retrieve the entries around the member user_20 of sorted set manic_miner
Description: Returns a leaderboard consisting solely of the members supplied
Syntax: prefix/friends/member_list(?callback=function_name)
member_list consists of at least one member - if more than one they must be separated by commas.
For example :
http://server/mod_redis/leaderboard/manic_miner/friends/user20,user1,user99