modifying data
The C # language modifies the Redis sample.
1. Modify single value by key
using(varRedisclient =redismanager.getclient ()) { varuser = Redisclient.gettypedclient<user>(); varValue = user. GetValue (Txtchangekey.text);//first get the value of the current key varChangeduser =NewUser {Id=value. Id, Name=Txtchangename.text, Job=NewJob {Position =Txtchangeposition.text}};//set the corresponding new value value, and make the other data consistent with the originalRedisclient.set (Txtchangekey.text, Changeduser);//Modify ValueValue = user. GetValue (Txtchangekey.text);//get the latest data based on key varHtmlstr =string. Empty; Htmlstr+="Modified id="+ value. Id +" Name:"+ value. Name +" Department:"+value. Job.position; Lblpeople.text=Htmlstr; Lblshow.text="total After screening: 1 people! "; }
2. Modify multiple values with keys
varDictionary =Newdictionary<string, user>(); using(varRedisclient =redismanager.getclient ()) { varuser = Redisclient.gettypedclient<user>(); varUser1 =NewUser {Id= user. Getnextsequence (),//get the new IDName ="Xiao Ming", Job=NewJob {Position ="Python" } }; varUser2 =NewUser {Id=user. Getnextsequence (), Name="Little Red", Job=NewJob {Position ="Python" } }; varuserkeylist = user. Getallkeys (). Where (x = X.startswith ("urn")). (y = y). ToList ();//get only key that holds valueDictionary. ADD (userkeylist[1], user1);//a second personDictionary. ADD (userkeylist[2], user2);//a third personRedisclient.setall (dictionary);//Modify multiple value at the same time varUsers =user. GetAll (); if(Users. Count >0) { varHtmlstr =string. Empty; foreach(varUinchusers) {Htmlstr+="<li>id="+ U.id +" Name:"+ U.name +" Department:"+ U.job.position +"</li>"; } Lblpeople.text=Htmlstr; } Lblshow.text="total after filtering:"+ Users. Count.tostring () +"people! "; }
3. Rename Key
using(varRedisclient =redismanager.getclient ()) {Redisclient.renamekey (Txtkey.text, Txtnewkey.text); varuser = Redisclient.gettypedclient<user>(); varUserkeylist =user. Getallkeys (); if(Userkeylist.count >0) {Lblpeople.text=string. Empty; varHtmlstr =string. Empty; foreach(varUinchuserkeylist) {Htmlstr+="<li>key="+ U +"</li>"; } Lblpeople.text=Htmlstr; } Lblshow.text="total after filtering:"+ userKeyList.Count.ToString () +"keys! "; }
Redis Combat (vii)