Rank 작업 완료

This commit is contained in:
김민서 2024-04-03 12:16:39 +09:00
parent c1514e2396
commit 3fcbe9ab34
1 changed files with 42 additions and 6 deletions

View File

@ -2,6 +2,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using StackExchange.Redis;
using System.Collections.Generic;
using static Server.System.Redis;
using static System.Formats.Asn1.AsnWriter;
@ -40,9 +41,6 @@ namespace Server.System
public void test()
{
Console.WriteLine("----------");
Setz("test1",1.5d, "ListTest");
Setz("test3",3.5d, "ListTest");
Setz("test2",2.5d, "ListTest");
Console.WriteLine("----------");
}
@ -119,12 +117,12 @@ namespace Server.System
return result;
}
public void Setz(string value, double score, params string[] keys)
public void SetZ(string value, double score, params string[] keys)
{
Setz(new Rank(value, score), keys);
SetZ(new Rank(value, score), keys);
}
public void Setz(Rank rank, params string[] keys)
public void SetZ(Rank rank, params string[] keys)
{
if (local)
{
@ -140,6 +138,43 @@ namespace Server.System
}
}
public double GetZScore(string value, params string[] keys)
{
if (local)
return zType[KeySet(keys)].Find(n => n.value == value).score;
else
return (double)db.SortedSetScore(KeySet(keys), value);
}
public long GetZRank(string value, params string[] keys)
{
if (local)
return zType[KeySet(keys)].FindIndex(n => n.value == value) + 1;
else
return (long)db.SortedSetRank(KeySet(keys), value);
}
public List<Rank> GetZ(long rank, params string[] keys)
{
List<Rank> result = new List<Rank>();
if (local)
{
List<Rank> ranking = new List<Rank>(zType[KeySet(keys)]);
if (ranking.Count > rank)
for (long n = 0; n < rank; n++)
result.Add(ranking[(int)n]);
else
result = new List<Rank>(ranking);
}
else
{
var topRankEntries = db.SortedSetRangeByRank(KeySet(keys), 0, rank - 1);
foreach (var entry in topRankEntries)
result.Add(new Rank(entry, GetZScore(entry, keys)));
}
return result;
}
private string KeySet(string[] keys)
{
return string.Join(":", keys);
@ -158,3 +193,4 @@ namespace Server.System
}
}
}