标签:
1、使用Linq匹配关键字查询
using (var redisClient = RedisManager.GetClient()) { var user = redisClient.GetTypedClient<User>(); var userList = user.GetAll().Where(x => x.Job.Position.Contains(txtScreenPosition.Text)).ToList(); if (userList.Count > 0) { var htmlStr = string.Empty; foreach (var u in userList) { htmlStr += "<li>ID=" + u.Id + " 姓名:" + u.Name + " 所在部门:" + u.Job.Position + "</li>"; } lblPeople.Text = htmlStr; } lblShow.Text = "筛选后共有:" + userList.Count.ToString() + "人!"; }
2、通过key来查询数据
var user = redisClient.GetTypedClient<User>(); var userKeyList = user.GetAllKeys();
我们逐一说明下:
在redis-client中输入:get urn:user:1 得到json类型数据。
我们就可以很轻松的通过key来查询value值了,代码如下
using (var redisClient = RedisManager.GetClient()) { var keyValue = string.Empty; try { var user = redisClient.GetTypedClient<User>(); var value = user.GetValue(txtKey.Text); keyValue += "ID=" + value.Id + " 姓名:" + value.Name + " 所在部门:" + value.Job.Position; } catch (Exception ex) { keyValue += ex.ToString(); } lblPeople.Text = keyValue.ToJson(); lblShow.Text = string.Empty; }
标签:
原文地址:http://www.cnblogs.com/wuxl360/p/5434418.html