redis簡單的讀寫
記錄key value。
首先要引用redes 算了,還是代碼來說話吧。麻煩。
鏈接方式 //引用 public static PooledRedisClientManager poolreds; //這個對應的redis的庫 static int port = 1; static RedisPool() { try { // 對於的redis庫的 密碼 ip 端口 RedisUrlopenid=“密碼@ip:端口” poolreds = new PooledRedisClientManager(port, new string[] { ConfigurationManager.AppSettings["RedisUrlopenid"] }); } catch (Exception ex) { } }
對於上面的:寫
/// <summary>
/// 緩存到Redis中
/// </summary>
/// <param name="key">key值</param>
/// <param name="danhaoList">詳細的信息</param>
public static void EnqueueList(string key, string obj)
{
using (var client = poolreds.GetClient())
{
//隊列使用
if (obj != null)
{
client.AddItemToList(key, obj);
}
}
}
對於上面的:讀
// //<summary>
// //讀取當前
// //</summary>
// //<param name="key"></param>
// //<returns></returns>
public static string DequeueModel(string key)
{
using (var client = poolreds.GetClient())
{
string danhao = client.GetItemFromList(key, 0);
return danhao;
}
}
// //<summary>
// //判斷當前是否有記錄
// //</summary>
// //<param name="key"></param>
// //<returns></returns>
public static long GetListCount(string key)
{
using (var client = poolreds.GetClient())
{
long count = client.GetListCount(key);
return count;
}
}
這個是插入到一個list里面。如圖
插入到統一的kjgz2016-04-08 list里面。
list的里面又可以插入很多記錄。一個key 對於很多value。可以記錄很多東西。很好用的一種
排版不是很好啊。嘿嘿。。。 后面還有哦