Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global memberdata #21

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/leaderboard.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions spec/leaderboard_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ describe 'Leaderboard', ->
reply.should.equal(1)
done())

it 'should allow you to change the memberDataNamespace to global namespace', (done) ->
updated_options =
'memberDataNamespace': 'global:namespace'
'useGlobalMemberData': true

@leaderboard = new Leaderboard('highscores', updated_options)
for index in [0...Leaderboard.DEFAULT_PAGE_SIZE + 1]
@leaderboard.rankMember("member_#{index}", index, "member_data_#{index}", (reply) -> )

@leaderboard.redisConnection.exists('highscores:member_data', (err, reply) ->
reply.should.equal(0))
@leaderboard.redisConnection.exists('highscores:global:namespace', (err, reply) ->
reply.should.equal(0))
@leaderboard.redisConnection.exists('global:namespace', (err, reply) ->
reply.should.equal(1)
done())

it 'should allow you to disconnect the Redis connection', (done) ->
@leaderboard.disconnect()
done()
Expand Down
3 changes: 2 additions & 1 deletion src/leaderboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Leaderboard
@scoreKeyOption = options['scoreKey'] || 'score'
@memberDataKeyOption = options['memberDataKey'] || 'member_data'
@memberDataNamespace = options['memberDataNamespace'] || 'member_data'
@useGlobalMemberData = if (options['useGlobalMemberData']) then true else false

@redisConnection = redisOptions['redis_connection']

Expand Down Expand Up @@ -1076,6 +1077,6 @@ class Leaderboard
# @return a key in the form of +leaderboardName:member_data+
###
memberDataKey: (leaderboardName) ->
"#{leaderboardName}:#{@memberDataNamespace}"
return if @useGlobalMemberData then "#{@memberDataNamespace}" else "#{leaderboardName}:#{@memberDataNamespace}"

module.exports = Leaderboard