Setz세팅
This commit is contained in:
parent
cdb167f19b
commit
c1514e2396
|
|
@ -1,6 +1,8 @@
|
|||
using Newtonsoft.Json;
|
||||
using NetTopologySuite.Index.HPRtree;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using StackExchange.Redis;
|
||||
using static Server.System.Redis;
|
||||
using static System.Formats.Asn1.AsnWriter;
|
||||
|
||||
namespace Server.System
|
||||
|
|
@ -14,7 +16,7 @@ namespace Server.System
|
|||
|
||||
Dictionary<string, string> stringType;
|
||||
Dictionary<string, List<string>> listType;
|
||||
Dictionary<string, List<rank>> zType;
|
||||
Dictionary<string, List<Rank>> zType;
|
||||
Dictionary<string, Dictionary<string, object>> hashType;
|
||||
public Redis(string host = "127.0.0.1", int port = 6379)
|
||||
{
|
||||
|
|
@ -23,7 +25,7 @@ namespace Server.System
|
|||
local = true;
|
||||
stringType = new Dictionary<string, string>();
|
||||
listType = new Dictionary<string, List<string>>();
|
||||
zType = new Dictionary<string, List<rank>>();
|
||||
zType = new Dictionary<string, List<Rank>>();
|
||||
hashType = new Dictionary<string, Dictionary<string, object>>();
|
||||
}
|
||||
else
|
||||
|
|
@ -37,25 +39,23 @@ namespace Server.System
|
|||
|
||||
public void test()
|
||||
{
|
||||
SetString("test", "key1");
|
||||
Console.WriteLine("123123");
|
||||
Console.WriteLine(GetString<string>("key1"));
|
||||
Console.WriteLine("123123");
|
||||
Console.WriteLine("----------");
|
||||
Setz("test1",1.5d, "ListTest");
|
||||
Setz("test3",3.5d, "ListTest");
|
||||
Setz("test2",2.5d, "ListTest");
|
||||
|
||||
Console.WriteLine("----------");
|
||||
}
|
||||
|
||||
public void SetString(object value, params string[] keys)
|
||||
{
|
||||
if (local)
|
||||
{
|
||||
if (listType.ContainsKey(KeySet(keys)))
|
||||
{
|
||||
if (stringType.ContainsKey(KeySet(keys)))
|
||||
stringType[KeySet(keys)] = JsonConvert.SerializeObject(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
stringType.Add(KeySet(keys), JsonConvert.SerializeObject(value));
|
||||
}
|
||||
}
|
||||
else
|
||||
db.StringSet(KeySet(keys), JsonConvert.SerializeObject(value));
|
||||
}
|
||||
|
|
@ -68,25 +68,20 @@ namespace Server.System
|
|||
return JsonConvert.DeserializeObject<T>(db.StringGet(key: KeySet(keys)));
|
||||
}
|
||||
|
||||
public void SetList(object value, params string[] keys)
|
||||
public void SetList<T>(T value, params string[] keys)
|
||||
{
|
||||
if (local)
|
||||
{
|
||||
if (listType.ContainsKey(KeySet(keys)))
|
||||
{
|
||||
listType[KeySet(keys)].Add(JsonConvert.SerializeObject(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
List<string> newdata = [JsonConvert.SerializeObject(value)];
|
||||
listType.Add(KeySet(keys), newdata);
|
||||
}
|
||||
listType.Add(KeySet(keys), [JsonConvert.SerializeObject(value)]);
|
||||
}
|
||||
else
|
||||
db.ListRightPush(KeySet(keys), JsonConvert.SerializeObject(value));
|
||||
}
|
||||
|
||||
public void SetList(List<object> value, params string[] keys)
|
||||
public void SetList<T>(List<T> value, params string[] keys)
|
||||
{
|
||||
foreach (var item in value)
|
||||
{
|
||||
|
|
@ -126,16 +121,19 @@ namespace Server.System
|
|||
|
||||
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 (zType.ContainsKey(KeySet(keys)))
|
||||
zType[KeySet(keys)].Add(rank);
|
||||
else
|
||||
zType.Add(KeySet(keys), [rank]);
|
||||
zType[KeySet(keys)].OrderBy(r => r.score).ToList();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
db.SortedSetAdd(KeySet(keys), rank.value, rank.score);
|
||||
|
|
@ -147,19 +145,12 @@ namespace Server.System
|
|||
return string.Join(":", keys);
|
||||
}
|
||||
|
||||
//public T Test<T>(string key, int index)
|
||||
//{
|
||||
// // Implementation logic here
|
||||
// // You can access 'value' class via typeof(T)
|
||||
// return typeof(T) null;
|
||||
//}
|
||||
|
||||
public class rank
|
||||
public class Rank
|
||||
{
|
||||
public string value;
|
||||
public double score;
|
||||
|
||||
public rank(string value, double score)
|
||||
public Rank(string value, double score)
|
||||
{
|
||||
this.value = value;
|
||||
this.score = score;
|
||||
|
|
|
|||
Loading…
Reference in New Issue