Rank 작업 완료
This commit is contained in:
parent
c1514e2396
commit
3fcbe9ab34
|
|
@ -2,6 +2,7 @@
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
|
using System.Collections.Generic;
|
||||||
using static Server.System.Redis;
|
using static Server.System.Redis;
|
||||||
using static System.Formats.Asn1.AsnWriter;
|
using static System.Formats.Asn1.AsnWriter;
|
||||||
|
|
||||||
|
|
@ -40,9 +41,6 @@ namespace Server.System
|
||||||
public void test()
|
public void test()
|
||||||
{
|
{
|
||||||
Console.WriteLine("----------");
|
Console.WriteLine("----------");
|
||||||
Setz("test1",1.5d, "ListTest");
|
|
||||||
Setz("test3",3.5d, "ListTest");
|
|
||||||
Setz("test2",2.5d, "ListTest");
|
|
||||||
|
|
||||||
Console.WriteLine("----------");
|
Console.WriteLine("----------");
|
||||||
}
|
}
|
||||||
|
|
@ -119,12 +117,12 @@ namespace Server.System
|
||||||
return result;
|
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)
|
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)
|
private string KeySet(string[] keys)
|
||||||
{
|
{
|
||||||
return string.Join(":", keys);
|
return string.Join(":", keys);
|
||||||
|
|
@ -158,3 +193,4 @@ namespace Server.System
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue