python - Connecting my django app to the redis installation -
i have django app. app normal application. running fine me.
i want implement leaderboard of now. read couple of places redis helps in doing it. , awesome. installed , configured redis on server.
a minimal representation of user profile me is:
class userprofile(models.model): user = models.onetoonefield(user) invited_friends = models.booleanfield(default=false) filled_wishlist = models.booleanfield(default=false) upvote = models.integerfield() downvote = models.integerfield() @property def reputation(self): return int(confidence_fixed(self.upvote, self.downvote)*100)
based on reputation property, value. happening @ postgresql db backend.
now want is, take these scores, put them in redis key value store, , generate leaderboard. there superawesome redis library implementing leaderboard: https://github.com/agoragames/leaderboard-python
so question is, given redis server running @ xxx.xxx.xx.xx:6342
how connect python/django app redis server, , update kv store, , once there numbers, how fetch in view , display?
i think you're on right track leaderboard-python library.
first need write onetime script move data model redis using leaderboard-python.
# create new leaderboard reputation_lb = leaderboard('reputation') profile in userprofile.objects.all(): reputation.rank_member('user_%i' % profile.user.pk, profile.reputation)
you need create property on userprofile model retrieves reputation leaderboard-python.
then want update score, either duplicate information in database , continue use reputation property update leaderboard, or increment/decrement score stored in redis.
the readme of leaderboard-python library quite , should contain of examples need build this.
Comments
Post a Comment