Created
July 10, 2021 19:52
-
-
Save Chriz76/ceccec7740ec5dd65a9df89a07db5d4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserWithPostCount | |
{ | |
public int ID { get; set; } | |
public string Name { get; set; } | |
public int PostCount { get; set; } | |
} | |
public IEnumerable<UserWithPostCount> ReadTopUsers(int offset, int countCategories) | |
{ | |
var cache = _muxer.GetDatabase(); | |
var topUsers = cache.SortedSetRangeByRankWithScores("UsersByPostCount", offset, offset + countCategories - 1, Order.Descending); | |
var ret = new List<Dto.UserWithPostCount>(); | |
var keys = new List<RedisKey>(); | |
foreach (var e in topUsers) | |
{ | |
string redisId = e.Element.ToString(); | |
keys.Add(new RedisKey(redisId + ":Name")); | |
} | |
var names = cache.StringGet(keys.ToArray()); | |
for (int i = 0; i < names.Length; i++) | |
{ | |
int.TryParse(topUsers[i].Element.ToString().Substring(5), out int id); | |
ret.Add(new Dto.UserWithPostCount { ID = id, PostCount = (int)topUsers[i].Score, Name = names[i] }); | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment