110,565
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 将ListModel添加到缓存层
/// </summary>
/// <param name="key">键</param>
/// <param name="lt">list</param>
/// <returns></returns>
public bool SetListModel<T>(string key, List<T> lt) where T : class
{
try
{
string value = JsonConvert.SerializeObject(lt);
if (rc2.Client.Set(key, value) == "OK")
{
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
public static Dictionary<string, Socket> device = new Dictionary<string, Socket>();
其中key是socket的ip+port.
反正我现在是这样保存...public static RedisClient client = new RedisClient();
static void Main(string[] args)
{
List<UserInfo> u = new List<UserInfo>() {
new UserInfo(){Name="1",Age=1},
new UserInfo(){Name="2",Age=11},
new UserInfo(){Name="3",Age=12},
};
//存储
client.Set<List<UserInfo>>("test", u);
//获取
var q = client.Get<List<UserInfo>>("test");
foreach (var item in q)
{
Console.WriteLine(item.Name);
}
Console.ReadLine();
}
public class UserInfo
{
public string Name { get; set; }
public int Age { get; set; }
}