国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實現(xiàn)redis讀寫的方法

2020-01-24 00:40:43
字體:
供稿:網(wǎng)友

最近做一個C#項目,需要對radis進行讀寫。

首先引入System.Configuration,如下

實現(xiàn)代碼如下:

public class ManualSuggestRedisHelper {  private static IRedisClient GetManualSuggestClient()  {   var config = ConfigurationManager.ConnectionStrings["REDIS_MANUAL_VIDEO_LIST"].ConnectionString.Split(':');   if (config.Length == 3)   {    int dbNum = int.Parse(config[2]);    return new RedisClient(config[0], int.Parse(config[1]), db: dbNum);   }   else   {    return new RedisClient("192.168.86.15", 6379, db: 8);   }  }   public static void AddRangeToList(string key, JSONObject value)  {   try   {    using (var redis = GetManualSuggestClient())    {     redis.SetEntry(key, value.ToString());    }   }   catch (Exception ex)   {    TxtLogger.DumpException(ex);   }  }   public static void AddRangeToSuggestList(string key, List<string> value)  {   try   {    using (var redis = GetManualSuggestClient())    {     redis.AddRangeToList(key, value);    }   }   catch (Exception ex)   {    TxtLogger.DumpException(ex);   }  }   public static void Remove(string key)  {   try   {    using (var redis = GetManualSuggestClient())    {     redis.Remove(key);    }   }   catch (Exception ex)   {    TxtLogger.AppendStringToTextFile("刪除redis key存在異常――" + ex);   }  }   public static bool ExistsRedis(string key)  {   try   {    using (var redis = GetManualSuggestClient())    {     List<string> isExists = redis.GetAllItemsFromList(key);     if (isExists != null && isExists.Count() > 0)     {      return true;     }    }   }   catch (Exception ex)   {    TxtLogger.DumpException(ex);   }   return false;  }  }

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 邹平县| 永宁县| 睢宁县| 连州市| 明星| 政和县| 安龙县| 肇东市| 藁城市| 施秉县| 汝州市| 鲁山县| 赞皇县| 保山市| 遂平县| 大洼县| 乌恰县| 重庆市| 筠连县| 西乌珠穆沁旗| 孝感市| 宝清县| 巫溪县| 平谷区| 汨罗市| 高雄县| 泗洪县| 丰城市| 湘潭市| 衡山县| 鱼台县| 衡山县| 通榆县| 湟中县| 平武县| 滨海县| 渝中区| 大方县| 石阡县| 岗巴县| 台中县|