From 7c42c6462a00d8e5de4e9bb12a460802d6845750 Mon Sep 17 00:00:00 2001 From: geffzhang Date: Thu, 1 Nov 2018 11:09:52 +0800 Subject: [PATCH 1/2] feat : use csredis async api --- BotSharp.Core/AgentStorage/AgentStorageInMemory.cs | 3 +-- BotSharp.Core/AgentStorage/AgentStorageInRedis.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/BotSharp.Core/AgentStorage/AgentStorageInMemory.cs b/BotSharp.Core/AgentStorage/AgentStorageInMemory.cs index a3671b45f..068032e5f 100644 --- a/BotSharp.Core/AgentStorage/AgentStorageInMemory.cs +++ b/BotSharp.Core/AgentStorage/AgentStorageInMemory.cs @@ -2,8 +2,7 @@ using BotSharp.Platform.Models; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Linq; using System.Threading.Tasks; namespace BotSharp.Core.AgentStorage diff --git a/BotSharp.Core/AgentStorage/AgentStorageInRedis.cs b/BotSharp.Core/AgentStorage/AgentStorageInRedis.cs index 7fb03532c..d2364ecbd 100644 --- a/BotSharp.Core/AgentStorage/AgentStorageInRedis.cs +++ b/BotSharp.Core/AgentStorage/AgentStorageInRedis.cs @@ -34,9 +34,9 @@ public AgentStorageInRedis() public async Task FetchById(string agentId) { var key = agentId; - if (csredis.Exists(key)) + if (await csredis.ExistsAsync(key)) { - return JsonConvert.DeserializeObject(csredis.Get(key)); + return JsonConvert.DeserializeObject(await csredis.GetAsync(key)); } else { @@ -51,7 +51,7 @@ public async Task FetchByName(string agentName) var keys = csredis.Keys($"{prefix}*"); foreach (string key in keys) { - var data = csredis.Get(key.Substring(prefix.Length)); + var data = await csredis.GetAsync(key.Substring(prefix.Length)); var agent = JsonConvert.DeserializeObject(data); if(agent.Name == agentName) @@ -76,7 +76,7 @@ public async Task Persist(TAgent agent) Formatting = Formatting.Indented, }); - csredis.Set(agent.Id, json); + await csredis.SetAsync(agent.Id, json); return true; } @@ -85,7 +85,7 @@ public async Task PurgeAllAgents() { var keys = csredis.Keys($"{prefix}*"); - csredis.Del(keys.Select(x => x.Substring(prefix.Length)).ToArray()); + await csredis.DelAsync(keys.Select(x => x.Substring(prefix.Length)).ToArray()); return keys.Count(); } @@ -97,7 +97,7 @@ public async Task> Query() var keys = csredis.Keys($"{prefix}*"); foreach (string key in keys) { - var data = csredis.Get(key.Substring(prefix.Length)); + var data = await csredis.GetAsync(key.Substring(prefix.Length)); var agent = JsonConvert.DeserializeObject(data); agents.Add(agent); } From 180bdf07b4c590f35337455ef979fffbcd899829 Mon Sep 17 00:00:00 2001 From: geffzhang Date: Fri, 2 Nov 2018 15:40:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat=EF=BC=9A=20delete=20unused=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BotSharp.Core/AgentStorage/AgentStorageInRedis.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/BotSharp.Core/AgentStorage/AgentStorageInRedis.cs b/BotSharp.Core/AgentStorage/AgentStorageInRedis.cs index d2364ecbd..911a763a9 100644 --- a/BotSharp.Core/AgentStorage/AgentStorageInRedis.cs +++ b/BotSharp.Core/AgentStorage/AgentStorageInRedis.cs @@ -46,8 +46,6 @@ public async Task FetchById(string agentId) public async Task FetchByName(string agentName) { - var agents = new List(); - var keys = csredis.Keys($"{prefix}*"); foreach (string key in keys) {