Пример #1
0
        public static void AddGameResultToRedis(GameResult gameResult)
        {
            IDatabase db = GetRedisDatabase();

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

            gameResults.Add(gameResult.game_id, gameResult);

            db.SortedSetIncrement("leaderboard", gameResult.game_id, gameResult.total_score);
        }
Пример #2
0
        public static void AddGameResultListToRedis(List <GameResult> gameResultList)
        {
            IDatabase db = GetRedisDatabase();

            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);
            }
        }
Пример #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);
        }