Redis Combat (vii)

Source: Internet
Author: User

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 +"&nbsp;&nbsp; Name:"+ value. Name +"&nbsp;&nbsp; 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 +"&nbsp;&nbsp; Name:"+ U.name +"&nbsp;&nbsp; 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.