Exemplo n.º 1
0
        public static void AddGameResultToRedis(GameResult gameResult)
        {
            IDatabase db = redis.GetDatabase();

            var gameResults = new RedisDictionary <int, GameResult>("gameResults");

            gameResults.Add(gameResult.game_id, gameResult);

            db.SortedSetIncrement("leaderboard", gameResult.game_id, gameResult.total_score);
        }
Exemplo n.º 2
0
        public static void AddGameResultListToRedis(List <GameResult> gameResultList)
        {
            IDatabase db = redis.GetDatabase();

            var gameResults = new RedisDictionary <int, GameResult>("gameResults");

            foreach (GameResult item in gameResultList)
            {
                gameResults.Add(item.game_id, item);
                db.SortedSetIncrement("leaderboard", item.game_id, item.total_score);
            }
        }
Exemplo n.º 3
0
        public static List <GameResult> GetTopRankings(int start, int stop)
        {
            IDatabase db = GetRedisDatabase();

            SortedSetEntry[] list = db.SortedSetRangeByRankWithScores("leaderboard", start, stop, Order.Descending);

            var gameResults = new RedisDictionary <int, GameResult>("gameResults");
            List <GameResult> gameResultList = new List <GameResult>();

            for (int i = 0; i < list.Length; i++)
            {
                GameResult item = gameResults[Convert.ToInt32(list[i].Element)];
                item.total_rank = i + 1;
                gameResultList.Add(item);
            }
            return(gameResultList);
        }