From c1514e23960d0d17482563126d7ddd98ebac2890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=84=9C?= Date: Wed, 3 Apr 2024 10:28:35 +0900 Subject: [PATCH] =?UTF-8?q?Setz=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/System/Redis.cs | 63 ++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/Server/System/Redis.cs b/Server/System/Redis.cs index 2e42b49..f5765d7 100644 --- a/Server/System/Redis.cs +++ b/Server/System/Redis.cs @@ -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,16 +16,16 @@ namespace Server.System Dictionary stringType; Dictionary> listType; - Dictionary> zType; + Dictionary> zType; Dictionary> hashType; public Redis(string host = "127.0.0.1", int port = 6379) { - if(host == "localhost") + if (host == "localhost") { local = true; stringType = new Dictionary(); listType = new Dictionary>(); - zType = new Dictionary>(); + zType = new Dictionary>(); hashType = new Dictionary>(); } else @@ -37,24 +39,22 @@ namespace Server.System public void test() { - SetString("test", "key1"); - Console.WriteLine("123123"); - Console.WriteLine(GetString("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,27 +68,22 @@ namespace Server.System return JsonConvert.DeserializeObject(db.StringGet(key: KeySet(keys))); } - public void SetList(object value, params string[] keys) + public void SetList(T value, params string[] keys) { if (local) { if (listType.ContainsKey(KeySet(keys))) - { listType[KeySet(keys)].Add(JsonConvert.SerializeObject(value)); - } else - { - List 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 value, params string[] keys) + public void SetList(List value, params string[] keys) { - foreach(var item in value) + foreach (var item in value) { SetList(item, keys); } @@ -124,18 +119,21 @@ 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) { - + 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(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;