hash작업 완료
This commit is contained in:
parent
3fcbe9ab34
commit
170171bb56
|
|
@ -18,7 +18,7 @@ namespace Server.System
|
|||
Dictionary<string, string> stringType;
|
||||
Dictionary<string, List<string>> listType;
|
||||
Dictionary<string, List<Rank>> zType;
|
||||
Dictionary<string, Dictionary<string, object>> hashType;
|
||||
Dictionary<string, Dictionary<string, string>> hashType;
|
||||
public Redis(string host = "127.0.0.1", int port = 6379)
|
||||
{
|
||||
if (host == "localhost")
|
||||
|
|
@ -27,7 +27,7 @@ namespace Server.System
|
|||
stringType = new Dictionary<string, string>();
|
||||
listType = new Dictionary<string, List<string>>();
|
||||
zType = new Dictionary<string, List<Rank>>();
|
||||
hashType = new Dictionary<string, Dictionary<string, object>>();
|
||||
hashType = new Dictionary<string, Dictionary<string, string>>();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -41,6 +41,19 @@ namespace Server.System
|
|||
public void test()
|
||||
{
|
||||
Console.WriteLine("----------");
|
||||
Dictionary<string, object> hash = GetHash("testhash");
|
||||
|
||||
foreach (var item in hash)
|
||||
{
|
||||
Console.WriteLine($"{item.Key} : {item.Value}");
|
||||
}
|
||||
|
||||
//hash.Add("nickname", "ganada");
|
||||
//hash.Add("uuid", "addzip");
|
||||
//hash.Add("id", 1);
|
||||
|
||||
//SetHash(hash, "testhash");
|
||||
//GetHash("testhash");
|
||||
|
||||
Console.WriteLine("----------");
|
||||
}
|
||||
|
|
@ -175,6 +188,51 @@ namespace Server.System
|
|||
return result;
|
||||
}
|
||||
|
||||
public void SetHash(string field, object value, params string[] keys)
|
||||
{
|
||||
if (local)
|
||||
{
|
||||
if (hashType.ContainsKey(KeySet(keys)))
|
||||
hashType.Add(KeySet(keys), new Dictionary<string, string> { { field, JsonConvert.SerializeObject(value) } });
|
||||
else
|
||||
{
|
||||
Dictionary<string, string> userHash = hashType[KeySet(keys)];
|
||||
if (userHash.ContainsKey(field))
|
||||
userHash.Add(field, JsonConvert.SerializeObject(value));
|
||||
else
|
||||
userHash[field] = JsonConvert.SerializeObject(value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
db.HashSet(KeySet(keys), field, JsonConvert.SerializeObject(value));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetHash(Dictionary<string, object> hash, params string[] keys)
|
||||
{
|
||||
foreach (var item in hash)
|
||||
SetHash(item.Key, item.Value, keys);
|
||||
}
|
||||
|
||||
public Dictionary<string, object> GetHash(params string[] keys)
|
||||
{
|
||||
Dictionary<string, object> hash = new Dictionary<string, object>();
|
||||
if (local)
|
||||
{
|
||||
Dictionary<string, string> hashs = new Dictionary<string, string>(hashType[KeySet(keys)]);
|
||||
foreach (var entry in hashs)
|
||||
hash.Add(entry.Key, JsonConvert.DeserializeObject(entry.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
HashEntry[] hashEntries = db.HashGetAll(KeySet(keys));
|
||||
foreach (var entry in hashEntries)
|
||||
hash.Add(entry.Name, entry.Value);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
private string KeySet(string[] keys)
|
||||
{
|
||||
return string.Join(":", keys);
|
||||
|
|
|
|||
Loading…
Reference in New Issue