标签:
using (var redisClient = RedisManager.GetClient()) { var user = redisClient.GetTypedClient<User>(); var value = user.GetValue(txtChangeKey.Text);//首先先获取当前key的值 var changedUser = new User { Id = value.Id, Name = txtChangeName.Text, Job = new Job { Position = txtChangePosition.Text } };//设置相应的新value值,并使其它数据与原来相统一 redisClient.Set(txtChangeKey.Text, changedUser);//修改value value = user.GetValue(txtChangeKey.Text);//根据key获取最新的数据 var htmlStr = string.Empty; htmlStr += "修改后的ID=" + value.Id + " 姓名:" + value.Name + " 所在部门:" + value.Job.Position; lblPeople.Text = htmlStr; lblShow.Text = "筛选后共有:1人!"; }
var dictionary = new Dictionary<string, User>(); using (var redisClient = RedisManager.GetClient()) { var user = redisClient.GetTypedClient<User>(); var user1 = new User { Id = user.GetNextSequence(),//获取新的ID Name = "小明", Job = new Job { Position = "Python" } }; var user2 = new User { Id = user.GetNextSequence(), Name = "小红", Job = new Job { Position = "Python" } }; var userKeyList = user.GetAllKeys().Where(x => x.StartsWith("urn")).OrderBy(y => y).ToList();//只获取保存value的key dictionary.Add(userKeyList[1], user1);//第二个人 dictionary.Add(userKeyList[2], user2);//第三个人 redisClient.SetAll(dictionary);//同时修改多个value var users = user.GetAll(); if (users.Count > 0) { var htmlStr = string.Empty; foreach (var u in users) { htmlStr += "<li>ID=" + u.Id + " 姓名:" + u.Name + " 所在部门:" + u.Job.Position + "</li>"; } lblPeople.Text = htmlStr; } lblShow.Text = "筛选后共有:" + users.Count.ToString() + "人!"; }
using (var redisClient = RedisManager.GetClient()) { redisClient.RenameKey(txtKey.Text, txtNewKey.Text); var user = redisClient.GetTypedClient<User>(); var userKeyList = user.GetAllKeys(); if (userKeyList.Count > 0) { lblPeople.Text = string.Empty; var htmlStr = string.Empty; foreach (var u in userKeyList) { htmlStr += "<li>key=" + u + "</li>"; } lblPeople.Text = htmlStr; } lblShow.Text = "筛选后共有:" + userKeyList.Count.ToString() + " Keys!"; }
public void Rename(string oldKeyname, string newKeyname) { if (oldKeyname == null) throw new ArgumentNullException("oldKeyname"); if (newKeyname == null) throw new ArgumentNullException("newKeyname"); SendExpectSuccess(Commands.Rename, oldKeyname.ToUtf8Bytes(), newKeyname.ToUtf8Bytes()); }
http://blog.csdn.net/qiujialongjjj/article/details/17298767
标签:
原文地址:http://www.cnblogs.com/tianciliangen/p/4949422.html